Skip to content

Commit

Permalink
Updated CancelOrderItemObserver.php
Browse files Browse the repository at this point in the history
Fixed Issue #20121 Cancel order increases stock although "Set Items' Status to be In Stock When Order is Cancelled" is set to No
  • Loading branch information
Shikha Mishra authored Jan 11, 2019
1 parent 6b69fa1 commit 473f907
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace Magento\CatalogInventory\Observer;

use Magento\CatalogInventory\Model\Configuration;
use Magento\Framework\Event\ObserverInterface;
use Magento\CatalogInventory\Api\StockManagementInterface;
use Magento\Framework\Event\Observer as EventObserver;
Expand All @@ -15,6 +16,11 @@
*/
class CancelOrderItemObserver implements ObserverInterface
{
/**
* @var \Magento\CatalogInventory\Model\Configuration
*/
protected $configuration;

/**
* @var StockManagementInterface
*/
Expand All @@ -30,9 +36,11 @@ class CancelOrderItemObserver implements ObserverInterface
* @param \Magento\Catalog\Model\Indexer\Product\Price\Processor $priceIndexer
*/
public function __construct(
Configuration $configuration,
StockManagementInterface $stockManagement,
\Magento\Catalog\Model\Indexer\Product\Price\Processor $priceIndexer
) {
$this->configuration = $configuration;
$this->stockManagement = $stockManagement;
$this->priceIndexer = $priceIndexer;
}
Expand All @@ -49,7 +57,8 @@ public function execute(EventObserver $observer)
$item = $observer->getEvent()->getItem();
$children = $item->getChildrenItems();
$qty = $item->getQtyOrdered() - max($item->getQtyShipped(), $item->getQtyInvoiced()) - $item->getQtyCanceled();
if ($item->getId() && $item->getProductId() && empty($children) && $qty) {
if ($item->getId() && $item->getProductId() && empty($children) && $qty && $this->configuration
->getCanBackInStock()) {
$this->stockManagement->backItemQty($item->getProductId(), $qty, $item->getStore()->getWebsiteId());
}
$this->priceIndexer->reindexRow($item->getProductId());
Expand Down

0 comments on commit 473f907

Please sign in to comment.