I know there is a way to delete image cache:

protected function cleanImageCache()
    try {
        echo "Cleaning image cache... ";
        echo Mage::getModel('catalog/product_image')->clearCache();
        echo "[OK]" . PHP_EOL . PHP_EOL;
    } catch (Exception $e) {
        die("[ERROR:" . $e->getMessage() . "]" . PHP_EOL);

How to I regenerate the images after that?

I know that by browsing the site they get generated but before that happens (e.g. if some of them have not been browsed yet) Google Image bot gets 404 from the server which I want to avoid.

1 Answer 1


you will need to load the instance per product

$_product = Mage::getModel('catalog/product')->load($product()->getId()); // pass product id here 

echo Mage::helper('catalog/image')->init($_product, 'small_image')->resize(50,50);


(string)Mage::helper('catalog/image')->init($product, 'thumbnail')->resize(200);

Get store config value

The values you can get in Mage::getStoreConfig('abc/xyz/hfc') are saved in core_config_data table of magento database.

Before this function can return anything, there has to be an entry in path column of core_config_data table. There is a column for store_id as well in core_config_data. If no store id is passed as an argument, default store id 0, which belongs to admin

instead of each you can store it some variable for google feed.

just checkout for this first 1 or 2 product then apply for whole .xml

Fetch Product collection

 public function getCollection() {

        $store = Mage::app()->getDefaultStoreView();
        $rootCategoryId = $store->getRootCategoryId();
        // Gets the current store's id
        $this->_storeId = $store->getStoreId();

        $collection = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*')
                                'status', array('eq' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED)

        // added to check in stock item


        return $collection;

call above function and loop

 $collection = $this->getCollection();
 foreach ($collection as $product) { 

       $products[$i]["Id"] = $product->getId();
       $products[$i]["Sku"] = $product->getSku(); // end so on.

hope this will work for you.

  • The code you provide is too specific, e.g. what if the size needs to be read from config instead of being hard-coded? Could you please provide a solution compatible with the function above, so we can make it full-featured for the purpose?
    – george
    Apr 22, 2015 at 16:04
  • @george you can use my updated anser
    – liyakat
    Apr 22, 2015 at 16:13
  • Sorry but this 'abc/xyz...' and the other explanatons are unclear to me (I am not a Magento developer). If you know how it should be done, please write the whole function. Can you do that please?
    – george
    Apr 22, 2015 at 16:56
  • here is detail example extension inchoo.net/magento/…
    – liyakat
    Apr 23, 2015 at 4:25
  • 1
    @george, my answer is updated with fetch product collection. i hope now you have enough understanding to get your answer. ;)
    – liyakat
    Apr 24, 2015 at 4:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.