diff --git a/app/code/community/Ess/M2ePro/Model/Ebay/Order/Item.php b/app/code/community/Ess/M2ePro/Model/Ebay/Order/Item.php index c612fc40..72c13de1 100644 --- a/app/code/community/Ess/M2ePro/Model/Ebay/Order/Item.php +++ b/app/code/community/Ess/M2ePro/Model/Ebay/Order/Item.php @@ -244,7 +244,7 @@ public function getVariationProductOptions() } foreach ($channelItem->getVariations() as $variation) { - if ($variation['channel_options'] !== $this->getVariationChannelOptions()) { + if ($this->isOptionsDifferent($variation['channel_options'], $this->getVariationChannelOptions())) { continue; } @@ -254,6 +254,29 @@ public function getVariationProductOptions() return $this->getVariationChannelOptions(); } + + /** + * @param array $first + * @param array $second + * + * @return bool + */ + protected function isOptionsDifferent(array $first, array $second) + { + $comparator = function ($a, $b) { + if ($a === $b) { + return 0; + } + + return $a > $b ? 1 : -1; + }; + + $firstDiff = array_udiff_uassoc($first, $second, $comparator, $comparator); + $secondDiff = array_udiff_uassoc($second, $first, $comparator, $comparator); + + return count($firstDiff) !== 0 || count($secondDiff) !== 0; + } + /** * @return array */ diff --git a/app/code/community/Ess/M2ePro/Model/Resource/Walmart/Listing/Product.php b/app/code/community/Ess/M2ePro/Model/Resource/Walmart/Listing/Product.php index 309b4d5c..37362fc7 100644 --- a/app/code/community/Ess/M2ePro/Model/Resource/Walmart/Listing/Product.php +++ b/app/code/community/Ess/M2ePro/Model/Resource/Walmart/Listing/Product.php @@ -88,5 +88,30 @@ public function mapChannelItemProduct(Ess_M2ePro_Model_Walmart_Listing_Product $ ); } + public function moveChildrenToListing($listingProduct) + { + /** @var Varien_Db_Adapter_Pdo_Mysql $connection */ + $connection = Mage::getSingleton('core/resource')->getConnection('core_write'); + $select = $connection->select(); + $select->join( + array('wlp' => $this->getMainTable()), + 'lp.id = wlp.listing_product_id', + null + ); + $select->join( + array('parent_lp' => Mage::getResourceModel('M2ePro/Listing_Product')->getMainTable()), + 'parent_lp.id = wlp.variation_parent_id', + array('listing_id' => 'parent_lp.listing_id') + ); + $select->where('wlp.variation_parent_id = ?', $listingProduct->getId()); + + $updateQuery = $connection->updateFromSelect( + $select, + array('lp' => Mage::getResourceModel('M2ePro/Listing_Product')->getMainTable()) + ); + + $connection->query($updateQuery); + } + //######################################## } diff --git a/app/code/community/Ess/M2ePro/Model/Walmart/Listing.php b/app/code/community/Ess/M2ePro/Model/Walmart/Listing.php index 5cf4c33d..b0c5f1a8 100644 --- a/app/code/community/Ess/M2ePro/Model/Walmart/Listing.php +++ b/app/code/community/Ess/M2ePro/Model/Walmart/Listing.php @@ -334,7 +334,7 @@ public function addProductFromOther( public function addProductFromListing( Ess_M2ePro_Model_Listing_Product $listingProduct, Ess_M2ePro_Model_Listing $sourceListing - ){ + ) { if (!$this->getParentObject()->addProductFromListing($listingProduct, $sourceListing, false)) { return false; } @@ -348,6 +348,15 @@ public function addProductFromListing( } } + $walmartListingProduct = $listingProduct->getChildObject(); + $variationManager = $walmartListingProduct->getVariationManager(); + + if ($variationManager->isRelationParentType()) { + /** @var Ess_M2ePro_Model_Resource_Walmart_Listing_Product $resourceModel */ + $resourceModel = Mage::getResourceModel('M2ePro/Walmart_Listing_Product'); + $resourceModel->moveChildrenToListing($listingProduct); + } + return true; } diff --git a/app/code/community/Ess/M2ePro/composer.json b/app/code/community/Ess/M2ePro/composer.json index a0b58f99..013fa743 100644 --- a/app/code/community/Ess/M2ePro/composer.json +++ b/app/code/community/Ess/M2ePro/composer.json @@ -2,7 +2,7 @@ "name": "m2epro/magento1-extension", "description": "M2E Pro is a Magento trusted (TM), award-winning extension, which allows merchants of all sizes to fully integrate Magento based system(s) into eBay/Amazon/Walmart platforms.", "type": "magento-module", - "version": "6.31.0", + "version": "6.31.1", "license": "proprietary", "keywords": ["ebay", "amazon", "walmart", "magento"], "homepage": "https://www.m2epro.com/", diff --git a/app/code/community/Ess/M2ePro/etc/config.xml b/app/code/community/Ess/M2ePro/etc/config.xml index edf82610..f1101741 100644 --- a/app/code/community/Ess/M2ePro/etc/config.xml +++ b/app/code/community/Ess/M2ePro/etc/config.xml @@ -2,7 +2,7 @@ - 6.31.0 + 6.31.1 diff --git a/app/code/community/Ess/M2ePro/sql/Update/y22_m11/FixWalmartChildListingId.php b/app/code/community/Ess/M2ePro/sql/Update/y22_m11/FixWalmartChildListingId.php new file mode 100644 index 00000000..90eb1b14 --- /dev/null +++ b/app/code/community/Ess/M2ePro/sql/Update/y22_m11/FixWalmartChildListingId.php @@ -0,0 +1,33 @@ +_installer; + $connection = $installer->getConnection(); + $select = $connection->select(); + + $select->join( + array('wlp' => $installer->getFullTableName('walmart_listing_product')), + 'lp.id = wlp.listing_product_id', + null + ); + $select->join( + array('parent_lp' => $installer->getFullTableName('listing_product')), + 'parent_lp.id = wlp.variation_parent_id', + array('listing_id' => 'parent_lp.listing_id') + ); + $select->where('lp.listing_id != parent_lp.listing_id'); + + $updateQuery = $connection->updateFromSelect( + $select, + array('lp' => $installer->getFullTableName('listing_product')) + ); + + $connection->query($updateQuery); + } +} diff --git a/app/code/community/Ess/M2ePro/sql/Upgrade/v6_31_0__v6_31_1/Config.php b/app/code/community/Ess/M2ePro/sql/Upgrade/v6_31_0__v6_31_1/Config.php new file mode 100644 index 00000000..2accf938 --- /dev/null +++ b/app/code/community/Ess/M2ePro/sql/Upgrade/v6_31_0__v6_31_1/Config.php @@ -0,0 +1,17 @@ +