Skip to content

Commit 9fc3d4a

Browse files
authored
Merge pull request #392 from magento-gl/GL_PR_Arrows_August_02_2023
Arrows Team - Bugfix delivery
2 parents c99019d + 6f9ff57 commit 9fc3d4a

File tree

3 files changed

+66
-1
lines changed

3 files changed

+66
-1
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\InventoryConfigurableProduct\Plugin\CatalogInventory\Api\StockRegistry;
9+
10+
use Magento\CatalogInventory\Api\Data\StockItemInterface;
11+
use Magento\CatalogInventory\Api\StockRegistryInterface;
12+
use Magento\CatalogInventory\Model\Stock;
13+
use Magento\Framework\Exception\LocalizedException;
14+
use Magento\InventoryConfiguration\Model\GetLegacyStockItem;
15+
16+
class SetLegacyStockItemForConfigurable
17+
{
18+
/**
19+
* @var GetLegacyStockItem
20+
*/
21+
private GetLegacyStockItem $getLegacyStockItem;
22+
23+
/**
24+
* @param GetLegacyStockItem $getLegacyStockItem
25+
*/
26+
public function __construct(GetLegacyStockItem $getLegacyStockItem)
27+
{
28+
$this->getLegacyStockItem = $getLegacyStockItem;
29+
}
30+
31+
/**
32+
* Set legacy stock for configurable if stock item status changed.
33+
*
34+
* @param StockRegistryInterface $subject
35+
* @param string $productSku
36+
* @param StockItemInterface $stockItem
37+
* @return array
38+
* @throws LocalizedException
39+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
40+
*/
41+
public function beforeUpdateStockItemBySku(
42+
StockRegistryInterface $subject,
43+
string $productSku,
44+
StockItemInterface $stockItem
45+
): array {
46+
if ($stockItem->getIsInStock() !== Stock::STOCK_OUT_OF_STOCK) {
47+
$this->getLegacyStockItem->execute($productSku);
48+
}
49+
return [$productSku, $stockItem];
50+
}
51+
}

InventoryConfigurableProduct/etc/di.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
</type>
3636
<type name="Magento\CatalogInventory\Api\StockRegistryInterface">
3737
<plugin name="inventory_catalog_add_qty_to_legacy_stock_configurable"
38-
type="Magento\InventoryConfigurableProduct\Plugin\CatalogInventory\Api\StockRegistry\SetQtyToLegacyStock"/>
38+
type="Magento\InventoryConfigurableProduct\Plugin\CatalogInventory\Api\StockRegistry\SetQtyToLegacyStock" sortOrder="100"/>
3939
</type>
4040
<type name="Magento\CatalogInventory\Model\ResourceModel\Stock\Item">
4141
<plugin name="after_update_stock_item_for_new_configurable_product"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
10+
<type name="Magento\CatalogInventory\Api\StockRegistryInterface">
11+
<plugin name="inventory_catalog_refresh_legacy_stock_item_configurable"
12+
type="Magento\InventoryConfigurableProduct\Plugin\CatalogInventory\Api\StockRegistry\SetLegacyStockItemForConfigurable" sortOrder="200"/>
13+
</type>
14+
</config>

0 commit comments

Comments
 (0)