2

I am having a problem with magento. When I do an import of my products with magmi everything goes correctly well. But I am having a little problem magento removes images on some product. Why he did this? I show you a video of this problem: https://www.youtube.com/watch?v=mrYtAq3qcI8

If you look good, when I select only the color images images appear But when I select a size and a color the first two color image black images appear and when I select the last two color image does not appear.

Do you know why I have this problem?

  • are you sure that the images are deleted?please make sure that magento deletes that images. – Manikandan Arunachalam Jul 14 '15 at 18:30
  • @Manik I import my products with magmi I guess it is magmi which then deletes – webevolution Jul 14 '15 at 18:32
3

I can't commet yet because I don't have 50 reputation so I have to create an answer: This has nothing to do with Magmi but with the Magento image import in 1.9.0.1 (have not tested 1.9.2 yet). I have the same problem and I am not using Magmi.

This bug seems to happen only if you use the same image file/path for multiple products: Magento's configurable swatches have a function to delete duplicate images, the image files are not deleted physically but only the product-image-correlation from the database table. This happens upon saving a product (i.e. each time when a product is sold -> modification of stock). You can read more about this bug and a possible workaround (which has not worked for me) here: https://github.com/dweeves/magmi-git/issues/183

0

You can debug this by enabling query logging.

You'll notice in the trace that this observer is firing: Mage_ConfigurableSwatches_Model_Observer::productListCollectionLoadAfter()

If you follow the trace, you'll find where things are being deleted in Mage_Catalog_Model_Resource_Product_Attribute_Backend_Media

protected function _removeDuplicates(&$result)
{

    $fileToId = array();

    foreach (array_keys($result) as $index) {
        if (!isset($fileToId[$result[$index]['file']])) {
            $fileToId[$result[$index]['file']] = $result[$index]['value_id'];
        } elseif ($fileToId[$result[$index]['file']] != $result[$index]['value_id']) {
            $this->deleteGallery($result[$index]['value_id']);
            unset($result[$index]);
        }
    }

    $result = array_values($result);
    return $this;
}

public function deleteGallery($valueId)
{
    if (is_array($valueId) && count($valueId)>0) {
        $condition = $this->_getWriteAdapter()->quoteInto('value_id IN(?) ', $valueId);
    } elseif (!is_array($valueId)) {
        $condition = $this->_getWriteAdapter()->quoteInto('value_id = ? ', $valueId);
    } else {
        return $this;
    }

    $this->_getWriteAdapter()->delete($this->getMainTable(), $condition);
    return $this;
}

It seems that when you enable configurable swatches (it may happen all the time, but I'm only noticing it when using built in configurable swatches), Magento will try to self-clean any duplicate images it finds with your products. Pretty stupid feature if you ask me.

One solution would be to rewrite the function to something like

protected function _removeDuplicates(&$result)
{
    $fileToId = array();

    foreach (array_keys($result) as $index) {
        if (!isset($fileToId[$result[$index]['file']])) {
            $fileToId[$result[$index]['file']] = $result[$index]['value_id'];
        } elseif ($fileToId[$result[$index]['file']] != $result[$index]['value_id']) {
            # Don't actually delete from the DB, just don't show on frontend
            # $this->deleteGallery($result[$index]['value_id']);
            unset($result[$index]);
        }
    }

    $result = array_values($result);
    return $this;
}

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.