Call us now on 0115 9738074

Archive for the ‘Q&A’ Category

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; ?>