Skip to content

Commit

Permalink
Merge pull request #13 from amol2jcommerce/2.2-develop-PR-port-19997
Browse files Browse the repository at this point in the history
[Backport] 19482 increase product quantity with disabled manage stock when place order is failed
  • Loading branch information
Amol Chaudhari authored Jan 27, 2019
2 parents 9b9f31c + 582a1e7 commit 0e030ca
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
21 changes: 16 additions & 5 deletions app/code/Magento/CatalogInventory/Model/StockManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public function __construct(

/**
* Subtract product qtys from stock.
*
* Return array of items that require full save.
*
* @param string[] $items
Expand Down Expand Up @@ -139,17 +140,25 @@ public function registerProductsSale($items, $websiteId = null)
}

/**
* @param string[] $items
* @param int $websiteId
* @return bool
* @inheritdoc
*/
public function revertProductsSale($items, $websiteId = null)
{
//if (!$websiteId) {
$websiteId = $this->stockConfiguration->getDefaultScopeId();
//}
$this->qtyCounter->correctItemsQty($items, $websiteId, '+');
return true;
$revertItems = [];
foreach ($items as $productId => $qty) {
$stockItem = $this->stockRegistryProvider->getStockItem($productId, $websiteId);
$canSubtractQty = $stockItem->getItemId() && $this->canSubtractQty($stockItem);
if (!$canSubtractQty || !$this->stockConfiguration->isQty($stockItem->getTypeId())) {
continue;
}
$revertItems[$productId] = $qty;
}
$this->qtyCounter->correctItemsQty($revertItems, $websiteId, '+');

return $revertItems;
}

/**
Expand Down Expand Up @@ -193,6 +202,8 @@ protected function getProductType($productId)
}

/**
* Get stock resource.
*
* @return ResourceStock
*/
protected function getResource()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public function execute(EventObserver $observer)
{
$quote = $observer->getEvent()->getQuote();
$items = $this->productQty->getProductQty($quote->getAllItems());
$this->stockManagement->revertProductsSale($items, $quote->getStore()->getWebsiteId());
$productIds = array_keys($items);
$revertedItems = $this->stockManagement->revertProductsSale($items, $quote->getStore()->getWebsiteId());
$productIds = array_keys($revertedItems);
if (!empty($productIds)) {
$this->stockIndexerProcessor->reindexList($productIds);
$this->priceIndexer->reindexList($productIds);
Expand Down

0 comments on commit 0e030ca

Please sign in to comment.