Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport] 19482 increase product quantity with disabled manage stock when place order is failed #20644

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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