Skip to content
This repository has been archived by the owner on Apr 30, 2023. It is now read-only.

Commit

Permalink
Reverted multi-source inventory implementation
Browse files Browse the repository at this point in the history
Summary:
Reverted multi-source inventory implementation as it was causing fatal errors for some sellers: #23.

Bumped version to `1.4.0`.

Reviewed By: xiangminxufsu

Differential Revision: D27724661

fbshipit-source-id: d5ef4df1
  • Loading branch information
zlik authored and facebook-github-bot committed Apr 13, 2021
1 parent a617697 commit 212561c
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 55 deletions.
1 change: 0 additions & 1 deletion Model/Product/Feed/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 6 additions & 34 deletions Model/Product/Feed/Builder/Inventory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -36,11 +33,6 @@ class Inventory
*/
private $stockConfigurationInterface;

/**
* @var GetSourceItemBySourceCodeAndSku
*/
private $getSourceItemBySourceCodeAndSku;

/**
* @var Product
*/
Expand All @@ -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
*/
Expand All @@ -90,30 +78,14 @@ 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
*/
public function initInventoryForProduct(Product $product)
{
$this->product = $product;
$this->sourceItem = $this->getSourceItem($product);
$this->productStock = $this->getStockItem($product);
return $this;
}

Expand All @@ -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;
}

Expand All @@ -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;
}
}
9 changes: 0 additions & 9 deletions Model/System/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand Down Expand Up @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion Test/Mftf/Data/PluginInfoData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/DataGenerator/etc/dataProfileSchema.xsd">
<entity name="_pluginInfo" type="PluginInfo">
<data key="source">magento2</data>
<data key="pluginVersion">1.2.7</data>
<data key="pluginVersion">1.4.0</data>
</entity>
</entities>
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -19,4 +19,4 @@
"Facebook\\BusinessExtension\\": ""
}
}
}
}
6 changes: 0 additions & 6 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@
</group>
<group id="inventory_management" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Inventory Management</label>
<field id="inventory_source" translate="label comment" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Inventory Source</label>
<config_path>facebook/inventory_management/inventory_source</config_path>
<source_model>Facebook\BusinessExtension\Model\Config\Source\Product\InventorySource</source_model>
<comment>Use this inventory source for products on Facebook and Instagram</comment>
</field>
<field id="out_of_stock_threshold" translate="label comment" type="text" sortOrder="20" showInDefault="1" showInWebsite="0" showInStore="1">
<label>Out-of-Stock Threshold</label>
<config_path>facebook/inventory_management/out_of_stock_threshold</config_path>
Expand Down
1 change: 0 additions & 1 deletion etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<collections_sync>1</collections_sync>
</catalog_management>
<inventory_management>
<inventory_source>default</inventory_source>
<out_of_stock_threshold>0</out_of_stock_threshold>
</inventory_management>
</facebook>
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Facebook_BusinessExtension" setup_version="1.2.7">
<module name="Facebook_BusinessExtension" setup_version="1.4.0">
</module>
</config>

0 comments on commit 212561c

Please sign in to comment.