I have a script that adds images to my products. It is used to set the image, small_image and thumbnail. The code works nice for the default view, but when I switch to store view the media gallery is set to "no_image". Causing my product to have no image at all in the frontend.
I tried to reset the store view attributes without success.
$product->addImageToMediaGallery($fileName, array('image', 'small_image', 'thumbnail'), false, false);
$attributes = $product->setStoreId(1)->getTypeInstance(true)->getSetAttributes($product);
if (isset($attributes['media_gallery'])) {
$attributes['media_gallery']->getBackend()->clearMediaAttribute($product, array('image', 'small_image', 'thumbnail'));
}
$product->save();
How can I modify the specific store attributes, and reset them to use the parent one?
Thank you.
Your 'simple solution' can be even simpler;
foreach($product->getStoreIds() as $storeId) {
$product->setStoreId($storeId)
->setImage(false)
->setSmallImage(false)
->setThumbnail(false)
->save();
}
ok for those who still have problems i have found sql solution:
DELETE FROM `catalog_product_entity_varchar`
WHERE store_id IN (1,2,3,4)
and entity_type_id=4
and (attribute_id=77 or attribute_id=78 or attribute_id=79);
in my case i wanted to restore default picture view form all my store views (ids are 1,2,3,4)
edit: modified SQL as Electric Jesus suggested
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With