Skip to content

Commit 29aa488

Browse files
authored
LYNX-910: [AC-2.4.9] Error when requesting CartItem.not_available_message or is_available field when cart inventory check is disabled
1 parent 8e51ae6 commit 29aa488

File tree

2 files changed

+115
-3
lines changed

2 files changed

+115
-3
lines changed

app/code/Magento/QuoteGraphQl/Model/CartItem/ProductStock.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ public function __construct(
5757
*/
5858
public function isProductAvailable(Item $cartItem): bool
5959
{
60-
$requestedQty = $cartItem->getQtyToAdd() ?? $cartItem->getQty();
61-
$previousQty = $cartItem->getPreviousQty() ?? 0;
60+
$requestedQty = (float)($cartItem->getQtyToAdd() ?? $cartItem->getQty());
61+
$previousQty = (int)$cartItem->getPreviousQty() ?? 0;
6262

6363
if ($cartItem->getProductType() === self::PRODUCT_TYPE_BUNDLE) {
6464
return $this->isStockAvailableBundle($cartItem, $previousQty, $requestedQty);
@@ -98,7 +98,7 @@ public function isStockAvailableBundle(Item $cartItem, int $previousQty, $reques
9898
$qtyOptions = $cartItem->getQtyOptions();
9999
$totalRequestedQty = $previousQty + $requestedQty;
100100
foreach ($qtyOptions as $qtyOption) {
101-
$requiredItemQty = $qtyOption->getValue();
101+
$requiredItemQty = (float)$qtyOption->getValue();
102102
if ($totalRequestedQty) {
103103
$requiredItemQty = $requiredItemQty * $totalRequestedQty;
104104
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\GraphQl\Quote;
9+
10+
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
11+
use Magento\Quote\Test\Fixture\AddProductToCart as AddProductToCartFixture;
12+
use Magento\Quote\Test\Fixture\GuestCart;
13+
use Magento\Quote\Test\Fixture\QuoteIdMask;
14+
use Magento\TestFramework\Fixture\Config as ConfigFixture;
15+
use Magento\TestFramework\Fixture\DataFixture;
16+
use Magento\TestFramework\Fixture\DataFixtureStorage;
17+
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
18+
use Magento\TestFramework\TestCase\GraphQlAbstract;
19+
20+
class NotAvailableMessageTest extends GraphQlAbstract
21+
{
22+
/**
23+
* @var DataFixtureStorage
24+
*/
25+
private $fixtures;
26+
27+
protected function setUp(): void
28+
{
29+
$this->fixtures = DataFixtureStorageManager::getStorage();
30+
}
31+
32+
#[
33+
ConfigFixture('cataloginventory/options/enable_inventory_check', false, "store", "default"),
34+
ConfigFixture('cataloginventory/options/not_available_message', true, "store", "default"),
35+
DataFixture(ProductFixture::class, as: 'product'),
36+
DataFixture(GuestCart::class, as: 'cart'),
37+
DataFixture(QuoteIdMask::class, ['cart_id' => '$cart.id$'], 'quoteIdMask'),
38+
DataFixture(
39+
AddProductToCartFixture::class,
40+
[
41+
'cart_id' => '$cart.id$',
42+
'product_id' => '$product.id$',
43+
'qty' => 1
44+
]
45+
)
46+
]
47+
public function testNotAvailableMessageWithoutInventoryCheck(): void
48+
{
49+
$this->assertCartResponse();
50+
}
51+
52+
#[
53+
ConfigFixture('cataloginventory/options/enable_inventory_check', true, "store", "default"),
54+
ConfigFixture('cataloginventory/options/not_available_message', true, "store", "default"),
55+
DataFixture(ProductFixture::class, as: 'product'),
56+
DataFixture(GuestCart::class, as: 'cart'),
57+
DataFixture(QuoteIdMask::class, ['cart_id' => '$cart.id$'], 'quoteIdMask'),
58+
DataFixture(
59+
AddProductToCartFixture::class,
60+
[
61+
'cart_id' => '$cart.id$',
62+
'product_id' => '$product.id$',
63+
'qty' => 1
64+
]
65+
)
66+
]
67+
public function testNotAvailableMessageWithInventoryCheck(): void
68+
{
69+
$this->assertCartResponse();
70+
}
71+
72+
private function assertCartResponse(): void
73+
{
74+
$this->assertEquals(
75+
[
76+
'cart' => [
77+
'itemsV2' => [
78+
'items' => [
79+
[
80+
'not_available_message' => null,
81+
]
82+
]
83+
]
84+
]
85+
],
86+
$this->graphQlQuery(
87+
$this->getCartQuery($this->fixtures->get('quoteIdMask')->getMaskedId())
88+
)
89+
);
90+
}
91+
92+
/**
93+
* Get cart query with not available message
94+
*
95+
* @param string $maskedQuoteId
96+
* @return string
97+
*/
98+
private function getCartQuery(string $maskedQuoteId): string
99+
{
100+
return <<<QUERY
101+
{
102+
cart(cart_id: "{$maskedQuoteId}") {
103+
itemsV2 {
104+
items {
105+
not_available_message
106+
}
107+
}
108+
}
109+
}
110+
QUERY;
111+
}
112+
}

0 commit comments

Comments
 (0)