Skip to content

Commit b100079

Browse files
authored
Improved msi fallback (#313)
* Improved MSI fallback * added missing desc
1 parent 09d0dc6 commit b100079

File tree

5 files changed

+14
-28
lines changed

5 files changed

+14
-28
lines changed

app/code/Meta/BusinessExtension/Model/System/Config.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ class Config
7272
public const XML_PATH_FACEBOOK_BUSINESS_EXTENSION_ACCESS_TOKEN = 'facebook/business_extension/access_token';
7373
public const XML_PATH_FACEBOOK_BUSINESS_EXTENSION_PAGE_ACCESS_TOKEN =
7474
'facebook/business_extension/page_access_token';
75-
private const XML_PATH_FACEBOOK_USE_MULTI_SOURCE_INVENTORY =
76-
'facebook/catalog_management/use_multi_source_inventory';
7775
private const XML_PATH_FACEBOOK_BUSINESS_EXTENSION_OUT_OF_STOCK_THRESHOLD =
7876
'facebook/catalog_management/out_of_stock_threshold';
7977

@@ -321,18 +319,6 @@ public function getStoreId()
321319
return $this->storeManager->getStore()->getId();
322320
}
323321

324-
/**
325-
* Use multi source inventory
326-
*
327-
* @param int $scopeId
328-
* @param int $scope
329-
* @return bool
330-
*/
331-
public function useMultiSourceInventory($scopeId = null, $scope = null): bool
332-
{
333-
return (bool)$this->getConfig(self::XML_PATH_FACEBOOK_USE_MULTI_SOURCE_INVENTORY, $scopeId, $scope);
334-
}
335-
336322
/**
337323
* Get out of stock threshold
338324
*

app/code/Meta/Catalog/Model/Product/Feed/Builder.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -499,9 +499,7 @@ public function getUnitPrice($product)
499499
private function getInventory(Product $product): InventoryInterface
500500
{
501501
if ($this->inventory === null) {
502-
$this->inventory = $this->builderTools->getInventoryObject(
503-
$this->systemConfig->useMultiSourceInventory($this->storeId)
504-
);
502+
$this->inventory = $this->builderTools->getInventoryObject();
505503
}
506504
$this->inventory->initInventoryForProduct($product);
507505
return $this->inventory;

app/code/Meta/Catalog/Model/Product/Feed/Builder/Tools.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Exception;
2424
use Magento\Catalog\Model\Product;
2525
use Magento\Framework\Currency;
26+
use Magento\Framework\Module\Manager as ModuleManager;
2627
use Magento\Framework\ObjectManagerInterface;
2728
use Magento\Framework\Pricing\PriceCurrencyInterface;
2829
use Magento\Framework\Escaper;
@@ -56,6 +57,11 @@ class Tools
5657
*/
5758
private $catalogHelper;
5859

60+
/**
61+
* @var ModuleManager
62+
*/
63+
private ModuleManager $moduleManager;
64+
5965
/**
6066
* Tools constructor
6167
*
@@ -64,19 +70,22 @@ class Tools
6470
* @param Escaper $escaper
6571
* @param SystemConfig $systemConfig
6672
* @param CatalogHelper $catalogHelper
73+
* @param ModuleManager $moduleManager
6774
*/
6875
public function __construct(
6976
PriceCurrencyInterface $priceCurrency,
7077
ObjectManagerInterface $objectManager,
7178
Escaper $escaper,
7279
SystemConfig $systemConfig,
73-
CatalogHelper $catalogHelper
80+
CatalogHelper $catalogHelper,
81+
ModuleManager $moduleManager
7482
) {
7583
$this->priceCurrency = $priceCurrency;
7684
$this->objectManager = $objectManager;
7785
$this->escaper = $escaper;
7886
$this->systemConfig = $systemConfig;
7987
$this->catalogHelper = $catalogHelper;
88+
$this->moduleManager = $moduleManager;
8089
}
8190

8291
/**
@@ -240,13 +249,13 @@ public function getProductSalePriceEffectiveDate(Product $product)
240249
/**
241250
* Get inventory object
242251
*
243-
* @param bool $useMultiSource
244252
* @return InventoryInterface
245253
*/
246-
public function getInventoryObject(bool $useMultiSource = true): InventoryInterface
254+
public function getInventoryObject(): InventoryInterface
247255
{
256+
// Fallback to Magento_CatalogInventory in case Magento MSI modules are disabled
248257
//phpcs:disable Magento2.PHP.LiteralNamespaces
249-
return $useMultiSource
258+
return $this->moduleManager->isEnabled('Magento_InventorySalesApi')
250259
? $this->objectManager->get('Meta\Catalog\Model\Product\Feed\Builder\MultiSourceInventory')
251260
: $this->objectManager->get('Meta\Catalog\Model\Product\Feed\Builder\Inventory');
252261
//phpcs:enable Magento2.PHP.LiteralNamespaces

app/code/Meta/Catalog/etc/adminhtml/system.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@
2121
</depends>
2222
<frontend_model>Meta\Catalog\Block\Adminhtml\System\Config\ProductFeed</frontend_model>
2323
</field>
24-
<field id="use_multi_source_inventory" translate="label comment" type="select" sortOrder="30" showInDefault="1" showInWebsite="0" showInStore="1">
25-
<label>Use Multi Source Inventory</label>
26-
<config_path>facebook/catalog_management/use_multi_source_inventory</config_path>
27-
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
28-
<comment>Set to 'Yes' if you'd like to use Magento's Multi Source Inventory (MSI) for products sold on Meta</comment>
29-
</field>
3024
<field id="price_incl_tax" translate="label comment" type="select" sortOrder="60" showInDefault="0" showInWebsite="0" showInStore="0">
3125
<label>Price Including Tax</label>
3226
<depends>

app/code/Meta/Catalog/etc/config.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
<price_incl_tax>0</price_incl_tax>
88
<collections_sync>0</collections_sync>
99
<out_of_stock_threshold>0</out_of_stock_threshold>
10-
<use_multi_source_inventory>1</use_multi_source_inventory>
1110
</catalog_management>
1211
</facebook>
1312
</default>

0 commit comments

Comments
 (0)