I have an external script which basically gets a product and excludes all of the images. The script is really simple

error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);
ob_implicit_flush (1);
$mediaApi = Mage::getModel("catalog/product_attribute_media_api");
$_product = Mage::getModel('catalog/product')->load(15509);
$_images = $_product->getMediaGalleryImages();
foreach($_images as $_image)
    $mediaApi->update($_product->getId(),  $_image->getFile(),array('exclude' => 1));

Looking at the raw database I can see that the table catalog_product_entity_media_gallery_value has been successfully updated eg the column disabled is now set to 1 for the 10 images for the product. I can also see that the images have a tick in the excluded box in the product images detail page in the admin system.


When I go to the frontend its still showing me all the images for that product. When I debug on the frontend I can see that the the disabled flag is still set to 0 for the images. Example below

object(Varien_Object)#1036 (7) {
["_data":protected]=>array(11) {
string(5) "15083"
string(43) "/F/F/FF6D86FE39366DF362D711765C56FDAA_1.jpg"
string(0) ""
string(1) "1"
string(1) "0"

I have tried clearing all caches and re indexing however still I get the same issue.

The strange thing which leads me to believe it isnt cache if I run the following raw SQL

UPDATE `catalog_product_entity_media_gallery_value` SET `disabled` = '1' WHERE `disabled` = '0';

The images on the frontend dont display so its as though I am disabling the wrong images in my script but I dont see how

Can anyone help?

*****UPDATE***** If I view the actual MySQL table catalog_product_entity_media_gallery_value and look up value_id 15083 I can see there are 2 records.

value_id    store_id    label   position    disabled
15083           0        \N       0           1
15083           1        \N       1           0

So my script only updates the record with with store id of 0

So this leads me to 2 questions

  1. How do I update the image so it does it across all stores
  2. Why is there 2 rows as the Magento instance only has 1 store

Even if you only have one store, you have a default setting, website settings and store view settings. Therefore you can still use all three levels of overwrite the settings.

if you don't use this, the easiest part is to just delete all entries where store_id != 0

If you don't want to do this, just make sure you update all entries for an image.


It appears that you are setting the default store in your script with the line Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);. This will then mean that the product row you are updating will be for the admin section.

You should be able to specify the store you want to update via the api call.

The update function takes a parameter store which can be a store id. You can also simply pass it the product id rather than the product object and then the first thing it will do is init the product for your desired store.

public function update($productId, $file, $data, $store = null, $identifierType = null)

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.