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?
Best Answer
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 associatedstore_id
. If there is no entry with a specificstore_id
, Magento will use the value with thestore_id
0 (Default StoreView)With this Query you see all Images which are set in a StoreView
What the Query does is, it selects all default image attributes
image
,small_image
andthumbnail
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):
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 tableSo, we can convert this select Query into a delete Query
In the case you want to change it for a specific StoreView, just change the
WHERE
clause to