Call us now on 0115 9738074

Posts Tagged ‘Magento’

Magento Q&A: How to ship orders via the API?

Wednesday, July 14th, 2010

Difficulty: Easy

Q:

I want to mark orders as shipped after we import the shipping feed from our warehouse. Is there an API for this? Or do I have to use the actual classes?

A:

Yes, of course! You can use the shipment API, to which you can connect using both SOAP and XML-RPC. The call that will be of most interest to you is shipment.create.

Here’s the sample code from magento’s site [php]:

$proxy = new SoapClient('http://magentohost/api/soap/?wsdl');
$sessionId = $proxy->login('apiUser', 'apiKey');
$notShipedOrderId  = '100000003';
 
// Create new shipment
$newShipmentId = $proxy->call($sessionId, 'sales_order_shipment.create', array($notShipedOrderId, array(), 'Shipment Created', true, true));

And here are the comments:

sales_order_shipment.create

Create new shipment for order

Return: string – shipment increment id

Arguments:

string orderIncrementId – order increment id

array itemsQty – items qty to ship as associative array (order_item_id ⇒ qty)

string comment – shipment comment (optional)

boolean email – send e-mail flag (optional)

boolean includeComment – include comment in e-mail flag (optional)

Magento Q&A: Why are some of my scheduled tasks not executed?

Friday, May 14th, 2010

Difficulty: Medium

Modification: Linux crontab

Q:

I have my scheduled tasks set up in magento and cron.php is executed periodically, however, some of the scheduled tasks are not performed. Is there anything I can do about that?

A:

We had the same problem with one of our sites. All the tasks were performed apart from sending the scheduled emails. After many discussions and when we have run out of all reasonable ideas we started looking at some more out of line ones. We noticed that the emails are sent when we access cron.php with a browser. It turns out that sometimes it is not enough to just execute your cron.php with a command line php interpretter in your linux crontab. We had to simulate a standard browser access to this php script by using wget. Here’s a sample line that you need to put in your crontab to make it work:

*/5 * * * * wget -q -O /dev/null http://.../cron.php

This line uses wget to request the cron.php file from the server and then discards the output. After putting this in place the emails were sent and they have been sending nicely ever since.

Magento Q&A: Where are my exported files? Where do I put import files?

Thursday, April 29th, 2010

Difficulty: Easy

Q:

I can’t figure out how to export my product database.  Is this possible?  I figured out how to export my products, but now I can’t seem to find the file.  Where do I go to find the file?

A:

When you use the magento export import features all the files are saved to and read from the server’s filesystem. The files you want to import into the system need to copied (for example via (s)ftp) to /var/import/ directory inside your magento root directory. The files that you export from magento will be placed inside /var/export/.

Magento Q&A: How to redirect from simple product to configurable product

Thursday, April 1st, 2010

Difficulty: Medium

Modification: Core Controller

Q:

I am trying to find a way to redirect the url for a simple product to go to the corresponding configurable product. For example if I have a link to a small blue t-shirt, it would go to the main t-shirt page where the attributes are available to select.

A:

You will need to modify the ProductController to make it look for a configurable product and display it when someone asks for a simple product.

The file you need to modify is /app/code/core/Mage/Catalog/controllers/ProductController and the method name is _initProduct().

Find the code which retrieves the product to be displayed:

$product = Mage::getModel(‘catalog/product’)

->setStoreId(Mage::app()->getStore()->getId())
->
load($productId);

And add this code after it:

if($product->type_id==“simple”)

{

$parentId=$product->loadParentProductIds()->getData('parent_product_ids');
if(isset(
$parentId[0]))
{
$product
=Mage::getModel('catalog/product')->load($parentId[0]);
}
}

That’s it, simple and elegant.

Magento Q&A: Why some customers can’t checkout

Friday, March 12th, 2010

Difficulty: Easy

Modification: Store Configuration

Q:

I keep getting complaints from potential customers that they are unable to use magento’s checkout. Instead of going to checkout they are logged out of the system and their cart is emptied. Why is this happening? What can I do about that?

A:

The issue in this case is that magento validates user sessions using their IP addresses. Validating customer’s IP address fails miserably when the customer’s ISP uses a proxy for http connections (and it seems many ISPs do that, at least in the UK). The problem occurs when switching from http to https. When on http, the customer connects through a proxy, so the session is created with the proxy’s IP address. When the customer is redirected to https (eg. goes to checkout) the connection is direct and the proxy is bypassed. Now the customer is connecting from his own IP address and not through a proxy, so his IP has changed. Magento detects this and invalidates the session.

The fix is fairly simple. You have to change the Session Validation settings in the Magento Admin. To do that go to System > Configurations > Web and choose ‘no’ on every option. After doing this,  go to System > Cache Management and refresh the configuration cache to apply the changes.

Magento Q&A: How to place a search box in the header

Friday, March 12th, 2010

Difficulty: Easy

Modification: Template File

Q:

I am a newbie at Magento and i need help. Can anyone guide me how to display the search form at the header?

A:

Put this code:

<?php echo $this->getChildHtml(‘topSearch’) ?>

Inside /app/design/frontend/default/your_skin/template/page/html/header.phtml. Then style it so that it appears exactly where you want it. It’s as simple as that!

Magento Q&A: How to properly change the admin url

Monday, March 1st, 2010

Difficulty: Easy

Modification: Config files, Database

Q:

Ok so I went to SYSTEM | ADVANCE and changed the path to log into the admin panel to another name.

Now, I can’t log in to the admin panel.

A:

First of all you would need to undo what you did – unset the custom admin url in the database. To do this, you would need to interact with the database. My preference is to use phpmyadmin, but you might also do it with the command line interface. Go to the table ‘core_config_data’ and delete the rows:

  • admin/url/use_custom
  • admin/url/custom

After that you need to properly set your custom admin url in the config file /app/etc/local.xml. In this file change this:

<frontName><![CDATA[admin]]></frontName>

to this:

<frontName><![CDATA[your_custom_admin_url]]></frontName>

Now save the file and clear the cache (if you are using it). If you still don’t have access to the admin you may clear the cache by deleting the contentss of the /var/cache directory.

On thing to remember is that while hiding your admin url makes your site more secure, it is not the ultimate solution for all your security issues. If your magento version is lower than 1.4, your admin url is easily discoverable by anyone unless you do some additional tweaking.

Magento Q&A: Hide the price for a free product

Friday, February 26th, 2010

Difficulty: Easy

Modification: Template File

Q:

I’m new to magento, and I would like to know if there is a way to hide the price of a product when it is 0?

I have a few free virtual product, and they have 0 as price. so the customer can order them for free. But I would like to hide the 0.

A:

That is fairly easy to do. You will need to modify the template file /app/design/forntend/default/your_skin/template/catalog/product/view.phtml.

In there you need to look for the piece of code responsible for displaying the price and surround it with additional code:

<?php if($_product->price==0): ?>

<?php echo 'FREE'; ?>
<?php
else: ?>
<!-- code that is currently displaying the price in your template -->
<?php endif; ?>

Prepare your magento site for upgrade

Thursday, February 18th, 2010

You might have heard that there is a new version of magento out there. Magento Community Edition 1.4 has just been declared stable by its creators – Varien. If you want to upgrade you must bear in mind that by doing so you will overwrite all the modifications in your core files. Normally this should not be a problem, as there shouldn’t be any core modifications. However, it is not uncommon that magento developers and designers do some quick changes in the core and then forget to move them to the local code pool or local template. The only way to make sure that your site will not loose the extra functionality or some custom styling is to track all the changes that have been applied to your core files and either move them to the local code/design files before upgrading or reapply them after the upgrade (though we would really recommend that you keep your core files free from any modifications). Now to the most important part: How to do this?

In order to find the core changes you would need to download a clean copy of magento. Be sure to download exactly the same version that you are currently running (you can check your current version in the admin panel’s footer). After download you need to extract the ‘app’ folder and place it somewhere in your filesystem. For the purpose of this example, lets assume that you put the original app file in the magento root folder and rename it to app.org.

Now you will need to make use of the linux console. The tool you will use is diff. It is a standard program for comparing files that should be present in all linux distributions. The only parameter that would need to be added is -r which switches the tool to recursive mode. The final command looks as follows for:

diff -r magento_root/app/code/core magento_root/app.org/code/core > ~/core_code_modifications.txt

diff -r magento_root/app/design/frontend/default/default/ magento_root/app.org/design/frontend/default/default/ > ~/core_design_modifications.txt

After executing those two commands you will have two files created in your home directory:

  • core_code_modifications.txt, which will list all the modifications in your core code files
  • core_design_modifications.txt, which will list all the modifications in your default template

With that knowledge your job of upgrading magento will be much simpler. Again, after you have successfully upgraded your magento store to version 1.4, do take some extra time and move the changes to the local code pool and/or your custom template. This will save you a lot of time and trouble in future upgrades and will also ensure that your store is easier to maintain by your developers and designers.

Save time customizing Magento with template hints

Friday, January 29th, 2010

So you need to do a few quick changes to the way magento displays some page. Great, but where is this page located in the file system? Have you been there? I know I have spent way too much time looking for the right files to edit.

Fortunately there is a built-in Magento feature that is designed exactly to help any programmer/designer in this situation. The feature is called template hints. You can activate it in your shop’s configuration. It is a bit tricky, however, because it is not visible by default. You need to go to System->Configuration->Advanced->Developer and open the Debug tab. By default you will only see an option to enable the Profiler. If you choose your store view from the ‘Current Configuration Scope‘ box situated in the top left part of the page you will get two extra options – ‘Template Path Hints‘ and ‘Add Block Names to Hints‘. Enabling the first option will display a path to the source file inside each block on the frontend. The second option will also add a Block Name, but it is not that useful and I would advise to keep it off for the sake of clarity.

There is one more thing worth noting here. If you would like to enable template hints on your live server you have to somehow limit them, so that they are shown only to you and your developers and not your customers. Well, you’re in luck again, because this option is also built-in. Just above the tab where you can set the template hints you will find a block called ‘Developer Client Restrictions‘. In there you can insert the IP addresses of all the machines that are allowed to view template hints. This way you can prevent your customers from seeing those hints and inevitably getting confused with your web shop.