Browsing articles in "Magento"
Apr 18, 2013

Change default length of Increment ID for orders, invoices, shipments, creditmemos

By default in Magento CE 1.6, the default Increment ID of orders, invoices, shipments and creditmemos is 9 characters. If you want to make it short or long due to some other application dependency or whatever you will have to change the value of increment_pad_length in eav_entity_type table.

For changing it with some setup script installer, this code will do the trick:

$entityType = Mage::getModel('eav/entity_type')->loadByCode('order'); //invoice, shipment, creditmemo
$entityType->setIncrementPadLength(12)->save(); //changing length to 12

For changing it directly in database table, execute this queries:

UPDATE `eav_entity_type` SET `increment_pad_length`= 12 WHERE entity_type_code = 'order';
UPDATE `eav_entity_type` SET `increment_pad_length`= 12 WHERE entity_type_code = 'invoice';
UPDATE `eav_entity_type` SET `increment_pad_length`= 12 WHERE entity_type_code = 'shipment';
UPDATE `eav_entity_type` SET `increment_pad_length`= 12 WHERE entity_type_code = 'creditmemo';
Feb 26, 2013

Magento: Can’t see product images in category page

Set product image as small image and thumbnail programatically

If you see your images in product detail page but don’t see it in category page, it’s because your product have images (image attribute filled) but not small_image and thumbnail which are required to display on category page. If there are only few products you want to set small_image and thumbnail, then it’s easy to go to Manage Products > Individual Product > Images tab > Set small image and thumbnail radio button. But when it comes to hundreds/thousands of products, you better want it programatically way.

Make a file in your Magento root and place the below code in it. Then run that file and you have just copied your Product Image to small image and thumbnail as well!

require 'app/Mage.php';

$products = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*');
foreach ($products as $product) {
    if (!$product->hasImage()) continue;
    if (!$product->hasSmallImage()) $product->setSmallImage($product->getImage());
    if (!$product->hasThumbnail()) $product->setThumbnail($product->getImage());
echo 'Finished!';
Feb 25, 2013

Magento: Design Patterns


It implement the concept of factories and deals with the problem of creating objects without specifying the exact class of object that will be created.

$product = Mage::getModel('catalog/product');


It restricts the instantiation of a class to one object. It will refer to same object each time called.

$category = Mage::getSingleton('catalog/session');


It is a way to store information throughout your application.

Mage::register('key',$value); //stores
$currentCategory = Mage::registry('key'); //retrives


It determines the type of object to create. In Magento it can be Simple, Configurable, Grouped, Bundle, Downloadable or Virtual types.



It is mainly used to implement distributed event handling systems. Here the subject maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods.

Mage::dispatchEvent('event_name', array('key'=>$value));

Continue reading »

Feb 23, 2013

Magento: Product Free/Paid SAMPLE Purchase Order

If you want to allow your customers to order for sample of any product, before purchasing the actual product, it becomes very tough as in a product page you can’t have two products (sample + full) allowed. But it’s not a good idea to display sample products as Individually, it makes sense only in the actual product page just near the Add To Cart button.

Magento Sample product purchase

But the question is, how to have TWO SKUs in a single product detail page? Here is the code that will do exactly what you want now. Open your catalog/product/view.phtml template file and put this code just below the code “$this->getChildHtml(‘addtocart’);”

<button type="button" style="float:left;padding-left:5px;" onclick="window.location.href='/order_sample.php?sku=<?php echo $this->htmlEscape($_product->getSku()) ?>'" title="Request Sample for < ?php echo $this->htmlEscape($_product->getName()) ?>" class="button btn-cart" ><span><span>Order Sample - $1</span></span></button>

Continue reading »

Feb 20, 2013

Magento: Product Import error – shows HTML code while importing

While importing products (somewhere around 1200 rows) by Magento’s in-built “System > Import/Export > Dataflow – Profiles” I got an error where the Dashboard’s HTML was printed in the output.

magento product import error

The reason for this error is due to something wrong in CSV product data which Magento didn’t understand. Create a temporary CSV file with only few rows (2-4) and check if that works. If it works, that means there is some problem with rest of the data.

For more information check my SO question here:


Welcome to my Blog

Kalpesh MehtaHelping Magento developers in their day-to-day development problems since 2011. Most of the problems and solutions here are my own experiences while working on different projects. Enjoy the blog and don't forget to throw comments and likes/+1's/tweets on posts you like. Thanks for visiting!




Magento top 50 contributors

Magento top 50 contributors