2

I want to know function logic location, when product image is remove from admin section. The checkbox is present in "images" tab. After check checkbox of images in "Remove" column and hit save or save and continue which functions calls in both cases for remove images which are assigned to product.

2

The code is in Mage_Catalog_Model_Product_Attribute_Backend_Media::beforeSave()

foreach ($value['images'] as &$image) {
    if(!empty($image['removed'])) {
        $clearImages[] = $image['file'];
    } else if (!isset($image['value_id'])) {
        $newFile                   = $this->_moveImageFromTmp($image['file']);
        $image['new_file'] = $newFile;
        $newImages[$image['file']] = $image;
        $this->_renamedImages[$image['file']] = $newFile;
        $image['file']             = $newFile;
    } else {
        $existImages[$image['file']] = $image;
    }
}

So if the remove checkbox is checked this will return true if(!empty($image['removed'])) { then the image is marked for deleteing.

Later on this is executed based on the images that are removed ($clearImages):

if (in_array($attrData, $clearImages)) {
    $object->setData($mediaAttrCode, 'no_selection');
}

[EDIT]

There is also this code in the same class in the afterSave method:

if(!empty($image['removed'])) {
    if(isset($image['value_id']) && !isset($picturesInOtherStores[$image['file']])) {
        $toDelete[] = $image['value_id'];
    }
    continue;
}

And later this is called $this->_getResource()->deleteGallery($toDelete);.
Maybe this one is what you are looking for.

3
  • If i use die; for printing $clearImages, my page is not stop and image is also deleted why?
    – Mathew
    Nov 27 '15 at 7:30
  • See my update. If that's not either, look for removed in the catalog module. That's how the input is called.
    – Marius
    Nov 27 '15 at 7:32
  • Yes i am looking for the same. :)
    – Mathew
    Nov 27 '15 at 8:42

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.