1

I have a new store view and i've updated all the products using the

magento admin: Manage Products > Select all > Update Attributes

and then selecting the new store. Now that all my products are affiliated with my new store view i'm having a problem with all my images. On the front end it shows all placeholders. In the admin panel when i click on a product and then images.. it may have images but it's not selected to use base image, small image or thumbnail.

Is there a way to update all images on my new store view to use the default store view main images?

require_once 'abstract.php';

class Attach_Default_Store_Images Extends Mage_Shell_Abstract {

    public function run()
    {
        $products = Mage::getModel('catalog/product')->getCollection();
        foreach ($products as $product) {
            $productFrom = $product->setStoreId(1)->getImage();
            $productTo = $product->setStoreId(13)
            ->setImage($productFrom)
            ->setSmallImage($productFrom)
            ->setThumbnail($productFrom);
            echo "Images Updated\n";
            $product->save();
   }

        Mage::getModel('catalog/product_image')->clearCache();
        echo "Image Cache Cleared\n";

    }


    public function usageHelp()
    {
        return <<<USAGE
Usage:  php -f cache.php -- [options]
        php -f cache.php -- clean

  clean             Clean Old Cache
  help              This help

USAGE;
    }
}

$shell = new Attach_Default_Store_Images();
$shell->run();

Run a shell script with above?

  • When You select store radio button selected or not ? – Prashant Barot Sep 8 '16 at 5:52
  • Hi @PrashantBarot, could you please elaborate on what you mean? – Supplement Sep 8 '16 at 17:12
3

One solution could be to delete the entries directly in the Database.
In the table catalog_product_entity_varchar you can find all images with the associated store_id. If there is no entry with a specific store_id, Magento will use the value with the store_id 0 (Default StoreView)

With this Query you see all Images which are set in a StoreView

SELECT
    attributes.entity_id, attributes.store_id, attributes.value,  eav.attribute_code
FROM
    catalog_product_entity_varchar attributes
    JOIN eav_attribute eav ON attributes.attribute_id = eav.attribute_id
WHERE 
    eav.attribute_code IN ("image", "small_image", "thumbnail") 
    AND attributes.store_id > 0

What the Query does is, it selects all default image attributes image, small_image and thumbnail with a store_id bigger then 0.
I used the eav_attribute table to select all entries with the attribute codes, because sometime the IDs are different.

The Result looks like this (in your case its a bigger list):

entity_id   store_id   value            attribute_code
86          6          /i/a/iamge1.png  image
86          6          /i/a/iamge2.png  small_image
86          6          /i/a/iamge2.png  thumbnail

Now we can test if this works like expected. If we choose a Product ID (entity_id) and change the images in the adminpanel to Use Default Value and execute the Query again, the entries are removed from the table

So, we can convert this select Query into a delete Query

DELETE FROM 
    attributes.entity_id, attributes.store_id, attributes.value,  eav.attribute_code
FROM
    catalog_product_entity_varchar attributes
    JOIN eav_attribute eav ON attributes.attribute_id = eav.attribute_id
WHERE 
    eav.attribute_code IN ("image", "small_image", "thumbnail") 
    AND attributes.store_id > 0

Before executing the delete query on your production system, you should test it on a test system.

In the case you want to change it for a specific StoreView, just change the WHERE clause to

AND attributes.store_id = 12 //Your StoreView ID
  • I'm not really using to use a sql query rather run a shell script. – Supplement Sep 8 '16 at 17:12
1

Go into your attributes panel, find the image/small image/thumbnail attributes. Note down the ids (mine in this case were 85,86 and 87) Change the query to reflect those id's. So my query looks like:

Delete FROM catalog_product_entity_varchar WHERE attribute_id IN (85,86,87) AND store_id > 0;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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