dweeves / magmi-git

Magmi GitHub
364 stars 307 forks source link

Wrong image processing in multi-store setup #329

Open bad-for-zathras opened 9 years ago

bad-for-zathras commented 9 years ago

In a multi-store-setup when using different image configurations (position, exclude from gallery, image, small_image, thumbnail) in each store Magmi fails to handle this case correctly. After a search through the code and the SQL queries it looks like the JOIN over _catalog_product_entityvarchar doesn't care for the store_id which causes the return value of getImageId pointing to the wrong _valueid. After applying the patch the store ID is used to filter for the right rows. This error may be difficult to reproduce.

--- imageitattributeemprocessor_old.php 2015-09-15 13:17:29.239326056 +0200
+++ imageitattributeemprocessor_new.php 2015-09-15 13:16:25.195640360 +0200
@@ -252,7 +252,7 @@
      *            : image file name (relative to /products/media in magento dir)
      * @return bool : if image is already present in gallery for a given product id
      */
-    public function getImageId($pid, $attid, $imgname, $refid = null)
+    public function getImageId($pid, $attid, $imgname, $refid = null, $store_id = 0)
     {
         $t = $this->tablename('catalog_product_entity_media_gallery');

@@ -261,8 +261,8 @@
         {
             $vc = $this->tablename('catalog_product_entity_varchar');
             $sql .= " JOIN $vc ON $t.entity_id=$vc.entity_id AND $t.value=$vc.value AND $vc.attribute_id=?
-                   WHERE $t.entity_id=?";
-            $imgid = $this->selectone($sql, array($refid,$pid), 'value_id');
+                   WHERE $t.entity_id=? AND $vc.store_id=?";
+            $imgid = $this->selectone($sql, array($refid,$pid,$store_id), 'value_id');
         }
         else
         {
@@ -322,7 +322,7 @@
         $gal_attinfo = $this->getAttrInfo("media_gallery");
         $tg = $this->tablename('catalog_product_entity_media_gallery');
         $tgv = $this->tablename('catalog_product_entity_media_gallery_value');
-        $vid = $this->getImageId($pid, $gal_attinfo["attribute_id"], $imgname, $refid);
+        $vid = $this->getImageId($pid, $gal_attinfo["attribute_id"], $imgname, $refid, $storeid);
         if ($vid != null)
         {
dweeves commented 9 years ago

could you submit a pull request for the patch ?