From dbfe81c259e6d4e5c4fb9058bfa1552aa410c699 Mon Sep 17 00:00:00 2001 From: Sumesh P Date: Mon, 18 Dec 2023 16:06:34 +0530 Subject: [PATCH] Code simplification --- .../Magento/QuoteGraphQl/Model/CartItem/ProductStock.php | 8 +++----- .../Model/Resolver/CheckProductStockAvailability.php | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/QuoteGraphQl/Model/CartItem/ProductStock.php b/app/code/Magento/QuoteGraphQl/Model/CartItem/ProductStock.php index 56696cf7d34a3..a39666131b4e9 100644 --- a/app/code/Magento/QuoteGraphQl/Model/CartItem/ProductStock.php +++ b/app/code/Magento/QuoteGraphQl/Model/CartItem/ProductStock.php @@ -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) { @@ -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; } diff --git a/app/code/Magento/QuoteGraphQl/Model/Resolver/CheckProductStockAvailability.php b/app/code/Magento/QuoteGraphQl/Model/Resolver/CheckProductStockAvailability.php index ed3ef8247390c..1db3f5e3358c2 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Resolver/CheckProductStockAvailability.php +++ b/app/code/Magento/QuoteGraphQl/Model/Resolver/CheckProductStockAvailability.php @@ -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); } }