Skip to content

Commit

Permalink
Code simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
sumesh-GL committed Dec 18, 2023
1 parent afd51ce commit dbfe81c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
8 changes: 3 additions & 5 deletions app/code/Magento/QuoteGraphQl/Model/CartItem/ProductStock.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ public function isProductAvailable($cartItem): bool
$previousQty = 0;

foreach ($cartItem->getQuote()->getItems() as $item) {
if ($item->getItemId() == $cartItem->getItemId()) {
if ($item->getItemId() === $cartItem->getItemId()) {
$requestedQty = $item->getQtyToAdd() ?? $item->getQty();
$previousQty = $item->getPreviousQty() ?? 0;
}
}

if ($cartItem->getProductType() == self::PRODUCT_TYPE_BUNDLE) {
if ($cartItem->getProductType() === self::PRODUCT_TYPE_BUNDLE) {
$qtyOptions = $cartItem->getQtyOptions();
$totalRequestedQty = $previousQty + $requestedQty;
foreach ($qtyOptions as $qtyOption) {
Expand All @@ -75,9 +75,7 @@ public function isProductAvailable($cartItem): bool
} else {
$requiredItemQty = $requestedQty + $previousQty;
$productId = (int) $cartItem->getProduct()->getId();
if (!$this->isStockAvailable($productId, $requiredItemQty)) {
return false;
}
return $this->isStockAvailable($productId, $requiredItemQty);
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
/** @var Item $cartItem */
$cartItem = $value['model'];

return $this->productStock->isProductAvailable($cartItem) ? true : false;
return $this->productStock->isProductAvailable($cartItem);
}
}

0 comments on commit dbfe81c

Please sign in to comment.