Skip to content

Commit 79f6b2a

Browse files
ENGCOM-3978: [Backport] Fixed Issue #20121 Cancel order increases stock although 'Set Items' Status to be In Stock When Order is Cancelled' is set to No #20547
- Merge Pull Request #20547 from irajneeshgupta/magento2:2.2-develop-PR-port-20252 - Merged commits: 1. 331b5c1 2. cc6b848
2 parents 722b213 + cc6b848 commit 79f6b2a

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

app/code/Magento/CatalogInventory/Observer/CancelOrderItemObserver.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,21 @@
66

77
namespace Magento\CatalogInventory\Observer;
88

9-
use Magento\Framework\Event\ObserverInterface;
109
use Magento\CatalogInventory\Api\StockManagementInterface;
10+
use Magento\CatalogInventory\Model\Configuration;
1111
use Magento\Framework\Event\Observer as EventObserver;
12+
use Magento\Framework\Event\ObserverInterface;
1213

1314
/**
1415
* Catalog inventory module observer
1516
*/
1617
class CancelOrderItemObserver implements ObserverInterface
1718
{
19+
/**
20+
* @var \Magento\CatalogInventory\Model\Configuration
21+
*/
22+
protected $configuration;
23+
1824
/**
1925
* @var StockManagementInterface
2026
*/
@@ -26,13 +32,16 @@ class CancelOrderItemObserver implements ObserverInterface
2632
protected $priceIndexer;
2733

2834
/**
35+
* @param Configuration $configuration
2936
* @param StockManagementInterface $stockManagement
3037
* @param \Magento\Catalog\Model\Indexer\Product\Price\Processor $priceIndexer
3138
*/
3239
public function __construct(
40+
Configuration $configuration,
3341
StockManagementInterface $stockManagement,
3442
\Magento\Catalog\Model\Indexer\Product\Price\Processor $priceIndexer
3543
) {
44+
$this->configuration = $configuration;
3645
$this->stockManagement = $stockManagement;
3746
$this->priceIndexer = $priceIndexer;
3847
}
@@ -49,7 +58,8 @@ public function execute(EventObserver $observer)
4958
$item = $observer->getEvent()->getItem();
5059
$children = $item->getChildrenItems();
5160
$qty = $item->getQtyOrdered() - max($item->getQtyShipped(), $item->getQtyInvoiced()) - $item->getQtyCanceled();
52-
if ($item->getId() && $item->getProductId() && empty($children) && $qty) {
61+
if ($item->getId() && $item->getProductId() && empty($children) && $qty && $this->configuration
62+
->getCanBackInStock()) {
5363
$this->stockManagement->backItemQty($item->getProductId(), $qty, $item->getStore()->getWebsiteId());
5464
}
5565
$this->priceIndexer->reindexRow($item->getProductId());

0 commit comments

Comments
 (0)