Skip to content

Commit

Permalink
Merge pull request #14 from VitaliiTsilnyk/negative-stock-fix
Browse files Browse the repository at this point in the history
Fix for negative Magento stock amount.
  • Loading branch information
gsomoza authored Dec 9, 2019
2 parents e895320 + f92327e commit a7fe1aa
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Model/Observer/SubtractQuoteInventoryObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,12 @@ public function execute(EventObserver $observer)
$items[$productId] += $childItem->getTotalQty();

$stockItem = $this->stockRegistry->getStockItem($productId);
$stockQty = max($stockItem->getQty(), 0);
if ($this->stockbaseStockManagement->isStockbaseProduct($productId) &&
$items[$productId] > $stockItem->getQty()
$items[$productId] > $stockQty
) {
$diff = $items[$productId] - $stockItem->getQty();
$items[$productId] = $stockItem->getQty();
$diff = $items[$productId] - $stockQty;
$items[$productId] = $stockQty;

$stockbaseAmount = $this->stockbaseStockManagement->getStockbaseStockAmount($productId);
if ($stockbaseAmount - $diff < 0) {
Expand Down

0 comments on commit a7fe1aa

Please sign in to comment.