From 212561c099e3cdec553ea26da23381ed610e2220 Mon Sep 17 00:00:00 2001 From: Alex Zarichnyi Date: Tue, 13 Apr 2021 10:37:14 -0700 Subject: [PATCH] Reverted multi-source inventory implementation Summary: Reverted multi-source inventory implementation as it was causing fatal errors for some sellers: https://github.com/facebookincubator/facebook-for-magento2/issues/23. Bumped version to `1.4.0`. Reviewed By: xiangminxufsu Differential Revision: D27724661 fbshipit-source-id: d5ef4df1 --- Model/Product/Feed/Builder.php | 1 - Model/Product/Feed/Builder/Inventory.php | 40 ++++-------------------- Model/System/Config.php | 9 ------ Test/Mftf/Data/PluginInfoData.xml | 2 +- composer.json | 4 +-- etc/adminhtml/system.xml | 6 ---- etc/config.xml | 1 - etc/module.xml | 2 +- 8 files changed, 10 insertions(+), 55 deletions(-) diff --git a/Model/Product/Feed/Builder.php b/Model/Product/Feed/Builder.php index 4aff806..e770a16 100644 --- a/Model/Product/Feed/Builder.php +++ b/Model/Product/Feed/Builder.php @@ -12,7 +12,6 @@ use Magento\Catalog\Api\Data\CategoryInterface; use Magento\Catalog\Model\Product; use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory as CategoryCollectionFactory; -use Magento\CatalogInventory\Model\Stock\Item as StockItem; use Magento\Framework\Exception\LocalizedException; class Builder diff --git a/Model/Product/Feed/Builder/Inventory.php b/Model/Product/Feed/Builder/Inventory.php index ce07deb..a2f2f77 100644 --- a/Model/Product/Feed/Builder/Inventory.php +++ b/Model/Product/Feed/Builder/Inventory.php @@ -11,9 +11,6 @@ use Magento\CatalogInventory\Api\StockConfigurationInterface; use Magento\CatalogInventory\Api\StockItemCriteriaInterfaceFactory; use Magento\CatalogInventory\Api\StockItemRepositoryInterface; -use Magento\Framework\Exception\NoSuchEntityException; -use Magento\InventoryApi\Api\Data\SourceItemInterface; -use Magento\InventorySourceDeductionApi\Model\GetSourceItemBySourceCodeAndSku; class Inventory { @@ -36,11 +33,6 @@ class Inventory */ private $stockConfigurationInterface; - /** - * @var GetSourceItemBySourceCodeAndSku - */ - private $getSourceItemBySourceCodeAndSku; - /** * @var Product */ @@ -52,33 +44,29 @@ class Inventory protected $systemConfig; /** - * @var SourceItemInterface|null + * @var StockItemInterface */ - protected $sourceItem; + protected $productStock; /** * @param StockItemRepositoryInterface $stockItemRepository * @param StockItemCriteriaInterfaceFactory $stockItemCriteriaInterfaceFactory * @param StockConfigurationInterface $stockConfigurationInterface - * @param GetSourceItemBySourceCodeAndSku $getSourceItemBySourceCodeAndSku * @param SystemConfig $systemConfig */ public function __construct( StockItemRepositoryInterface $stockItemRepository, StockItemCriteriaInterfaceFactory $stockItemCriteriaInterfaceFactory, StockConfigurationInterface $stockConfigurationInterface, - GetSourceItemBySourceCodeAndSku $getSourceItemBySourceCodeAndSku, SystemConfig $systemConfig ) { $this->stockItemRepository = $stockItemRepository; $this->stockItemCriteriaInterfaceFactory = $stockItemCriteriaInterfaceFactory; $this->stockConfigurationInterface = $stockConfigurationInterface; - $this->getSourceItemBySourceCodeAndSku = $getSourceItemBySourceCodeAndSku; $this->systemConfig = $systemConfig; } /** - * @deprecated Replaced with multi-source inventory * @param Product $product * @return StockItemInterface|null */ @@ -90,22 +78,6 @@ public function getStockItem(Product $product) return array_shift($stocksItems); } - /** - * @param Product $product - * @return SourceItemInterface|null - */ - public function getSourceItem(Product $product) - { - try { - return $this->getSourceItemBySourceCodeAndSku->execute( - $this->systemConfig->getInventorySource(), - $product->getSku() - ); - } catch (NoSuchEntityException $e) { - return null; - } - } - /** * @param Product $product * @return $this @@ -113,7 +85,7 @@ public function getSourceItem(Product $product) public function initInventoryForProduct(Product $product) { $this->product = $product; - $this->sourceItem = $this->getSourceItem($product); + $this->productStock = $this->getStockItem($product); return $this; } @@ -122,8 +94,8 @@ public function initInventoryForProduct(Product $product) */ public function getAvailability() { - return $this->product && $this->sourceItem && $this->sourceItem->getStatus() - && ($this->sourceItem->getQuantity() - $this->systemConfig->getOutOfStockThreshold() > 0) + return $this->product && $this->productStock && $this->productStock->getIsInStock() + && ($this->productStock->getQty() - $this->systemConfig->getOutOfStockThreshold() > 0) ? self::STATUS_IN_STOCK : self::STATUS_OUT_OF_STOCK; } @@ -132,6 +104,6 @@ public function getAvailability() */ public function getInventory() { - return $this->product && $this->sourceItem ? (int)$this->sourceItem->getQuantity() : 0; + return $this->product && $this->productStock ? (int)$this->productStock->getQty() : 0; } } diff --git a/Model/System/Config.php b/Model/System/Config.php index a9ac9a6..d70f1ba 100644 --- a/Model/System/Config.php +++ b/Model/System/Config.php @@ -14,7 +14,6 @@ class Config { const XML_PATH_FACEBOOK_COLLECTIONS_SYNC_IS_ACTIVE = 'facebook/catalog_management/collections_sync'; - const XML_PATH_FACEBOOK_INVENTORY_SOURCE = 'facebook/inventory_management/inventory_source'; const XML_PATH_FACEBOOK_OUT_OF_STOCK_THRESHOLD = 'facebook/inventory_management/out_of_stock_threshold'; /** @@ -103,14 +102,6 @@ public function isActiveCollectionsSync() return $this->scopeConfig->isSetFlag(self::XML_PATH_FACEBOOK_COLLECTIONS_SYNC_IS_ACTIVE); } - /** - * @return mixed - */ - public function getInventorySource() - { - return $this->scopeConfig->getValue(self::XML_PATH_FACEBOOK_INVENTORY_SOURCE); - } - /** * @return mixed */ diff --git a/Test/Mftf/Data/PluginInfoData.xml b/Test/Mftf/Data/PluginInfoData.xml index 089e076..e6066fd 100644 --- a/Test/Mftf/Data/PluginInfoData.xml +++ b/Test/Mftf/Data/PluginInfoData.xml @@ -4,6 +4,6 @@ xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/DataGenerator/etc/dataProfileSchema.xsd"> magento2 - 1.2.7 + 1.4.0 diff --git a/composer.json b/composer.json index d35e789..567316e 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "Facebook Business Extension for Magento 2", "type": "magento2-module", "license": "GPL-1.0-or-later", - "version": "1.2.7", + "version": "1.4.0", "require": { "facebook/php-business-sdk": "9.0.3" }, @@ -19,4 +19,4 @@ "Facebook\\BusinessExtension\\": "" } } -} \ No newline at end of file +} diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 8dde133..7c72210 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -24,12 +24,6 @@ - - - facebook/inventory_management/inventory_source - Facebook\BusinessExtension\Model\Config\Source\Product\InventorySource - Use this inventory source for products on Facebook and Instagram - facebook/inventory_management/out_of_stock_threshold diff --git a/etc/config.xml b/etc/config.xml index 88535a9..7f4db6b 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -6,7 +6,6 @@ 1 - default 0 diff --git a/etc/module.xml b/etc/module.xml index be7d7a2..b4fbc1b 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,5 +1,5 @@ - +