Skip to content

Commit

Permalink
ENGCOM-3978: [Backport] Fixed Issue #20121 Cancel order increases sto…
Browse files Browse the repository at this point in the history
…ck 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
  • Loading branch information
magento-engcom-team committed Jan 27, 2019
2 parents 722b213 + cc6b848 commit 79f6b2a
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,21 @@

namespace Magento\CatalogInventory\Observer;

use Magento\Framework\Event\ObserverInterface;
use Magento\CatalogInventory\Api\StockManagementInterface;
use Magento\CatalogInventory\Model\Configuration;
use Magento\Framework\Event\Observer as EventObserver;
use Magento\Framework\Event\ObserverInterface;

/**
* Catalog inventory module observer
*/
class CancelOrderItemObserver implements ObserverInterface
{
/**
* @var \Magento\CatalogInventory\Model\Configuration
*/
protected $configuration;

/**
* @var StockManagementInterface
*/
Expand All @@ -26,13 +32,16 @@ class CancelOrderItemObserver implements ObserverInterface
protected $priceIndexer;

/**
* @param Configuration $configuration
* @param StockManagementInterface $stockManagement
* @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 +58,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 79f6b2a

Please sign in to comment.