Browsing articles in "Magento admin"
Apr 25, 2013

Magento Special price products page

Magento special price products page. We will be creating a new CMS page that will display all the Special or Sale products. We can make a product as a Special by filling it’s “Special From” and “Special To” price in “Prices” tab in Manage Products individual screen.

So let’s first create CMS Page, by going to CMS > Pages, which we will name it as “Specials”. In the Content tab of that Page, paste the below line of code:

{{block type="catalog/product_special" template="catalog/product/list.phtml" column_count="3" num_products="0"}}

and save the page.

– Here we are saying Magento to display Product List template by looking at our new block type file, Catalog/Product/Block/Special.php. So let’s create this file, Special.php in local/Mage/Catalog/Product/Block/ directory. You will have to create this directory path if it’s not already there.

class Mage_Catalog_Block_Product_Special extends Mage_Catalog_Block_Product_List
    protected function _getProductCollection()
        if (is_null($this->_productCollection)) {
            $categoryID = $this->getCategoryId();
              $category = new Mage_Catalog_Model_Category();
              $category->load($categoryID); // this is category id
              $collection = $category->getProductCollection();
            } else
              $collection = Mage::getResourceModel('catalog/product_collection');
            $todayDate = date('m/d/y');
            $tomorrow = mktime(0, 0, 0, date('m'), date('d')+1, date('y'));
            $tomorrowDate = date('m/d/y', $tomorrow);
            $collection->addAttributeToSort('created_at', 'desc');
            $collection->addAttributeToFilter('special_from_date', array('date' => true, 'to' => $todayDate))
                ->addAttributeToFilter('special_to_date', array('or'=> array(
                0 => array('date' => true, 'from' => $tomorrowDate),
                1 => array('is' => new Zend_Db_Expr('null')))
                ), 'left');
            $numProducts = $this->getNumProducts() ? $this->getNumProducts() : 0;
            $collection->setPage(1, $numProducts)->load();
            $this->_productCollection = $collection;
        return $this->_productCollection;
Apr 18, 2013

Magento client denied by server configuration notice

Magento client denied by server configuration: /var/www/magento/app/etc/local.xml .. This is not the error, but just a message type thing displayed in apache error log and firebug console. Nothing to worry here, it’s just a security check from web server and you should ignore it.

If you don’t like it then you can turn it off by writing few lines of code in app/design/adminhtml/default/default/layout/local.xml

        <remove name="notification_security" />
        <remove name="notification_survey" />

Clear cache as usual, and you should get rid of this message.

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 20, 2013

Magento: Reset download limit for downloadable product item/order

In Magento, downloadable products are the products which can be downloaded and does not require any shipping. When customer purchases this type of products, they get certain download limits to download their purchased items. This can be set in Products page in admin under “Downloadable Products” tab. In many cases store owner only want to give certain amount of downloads, so customers can’t download beyond that limit. But it may happen that due to bad internet or some interrupts downloads can’t be successful and customer want to reset that limit. For doing this, there is no option in backend to reset the download limits for the downloadable product items or for an entire order, and unfortunately admin use to re-order to achieve this.

Here is the query which will reset download limits for an entire order.

$q = Mage::getModel('sales/order_item')->getCollection()->addFieldToSelect('order_id');
$q->getSelect()->joinRight('downloadable_link_purchased_item as d', 'main_table.item_id = d.order_item_id',
$q->getSelect()->where('main_table.order_id = '. (int)$orderId);

//echo $q->getSelect()->__toString();exit;

$items = $q->getColumnValues('item_id');
foreach($items as $id) {

The raw SQL query for the above Magento Convention query is:
UPDATE sales_flat_order_item s RIGHT JOIN downloadable_link_purchased_item d ON s.item_id = d.order_item_id SET d.number_of_downloads_used = 0 WHERE s.order_id = $orderId;
Continue reading »

Feb 7, 2013

Magento: Add product custom attribute options dynamically

Once you have the product attributes in place, and you want to add lot of options to these attributes it becomes time consuming and hectic task. If you have only few attribute options to add, it’s easy to go to backend and add manually. But if you have many attribute options, more than 10 options for many attributes, it’s very tiresome and feels like data entry job. Magento is not built to do stuff manually, so here I will provide you the code snippet which will push all the attribute options to their respective attribute.

Create a file in the root of your Magento installation and copy this code there. I generally name it test.php

require_once 'app/Mage.php';

$installer = new Mage_Eav_Model_Entity_Setup('core_setup');

//Change this....
$attrCode = 'color'; //this should be there already

$aColors = array_map('utf8_encode',$aColors); //If you're using special characters
$iProductEntityTypeId = Mage::getModel('catalog/product')->getResource()->getTypeId();
$aOption = array();
$aOption['attribute_id'] = $installer->getAttributeId($iProductEntityTypeId, $attrCode);

   $aOption['value']['option'.$iCount][0] = $aColors[$iCount];


Now you just need to give the existing product attribute name AND future attribute options to this script. Run it and rest all script will do for you! 🙂

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