Skip to content

Commit 4fb5b58

Browse files
authored
LYNX-430: Check for null quote
1 parent b55cd92 commit 4fb5b58

File tree

2 files changed

+119
-1
lines changed

2 files changed

+119
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ public function execute(Quote $cart, int $pageSize, int $offset, string $orderBy
4747
->addFieldToFilter('quote_id', $cart->getId())
4848
->setOrder($orderBy, $order)
4949
->setCurPage($offset)
50-
->setPageSize($pageSize);
50+
->setPageSize($pageSize)
51+
->setQuote($cart);
5152

5253
$items = [];
5354
$itemDeletedCount = 0;

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/GetCartPaginatedItemsTest.php

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,14 @@
77

88
namespace Magento\GraphQl\Quote\Guest;
99

10+
use Magento\Bundle\Test\Fixture\AddProductToCart as AddBundleProductToCart;
11+
use Magento\Bundle\Test\Fixture\Link as BundleSelectionFixture;
12+
use Magento\Bundle\Test\Fixture\Option as BundleOptionFixture;
13+
use Magento\Bundle\Test\Fixture\Product as BundleProductFixture;
1014
use Magento\Catalog\Model\Product;
1115
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
16+
use Magento\Catalog\Test\Fixture\ProductStock as ProductStockFixture;
17+
use Magento\CatalogInventory\Model\StockRegistry;
1218
use Magento\Indexer\Test\Fixture\Indexer;
1319
use Magento\Quote\Model\Cart\Data\CartItem;
1420
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
@@ -68,11 +74,15 @@ class GetCartPaginatedItemsTest extends GraphQlAbstract
6874
*/
6975
private $quoteIdToMaskedQuoteIdInterface;
7076

77+
/** @var StockRegistry */
78+
private $stockRegistry;
79+
7180
protected function setUp(): void
7281
{
7382
$objectManager = Bootstrap::getObjectManager();
7483
$this->fixtures = $objectManager->get(DataFixtureStorageManager::class)->getStorage();
7584
$this->quoteIdToMaskedQuoteIdInterface = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class);
85+
$this->stockRegistry = $objectManager->get(StockRegistry::class);
7686
}
7787

7888
public function testGetCartWithZeroPageSize()
@@ -93,6 +103,113 @@ public function testGetCartWithZeroCurrentPage()
93103
$this->graphQlQuery($query);
94104
}
95105

106+
#[
107+
DataFixture(ProductFixture::class, as: 'p1'),
108+
DataFixture(
109+
ProductStockFixture::class,
110+
[
111+
'prod_id' => '$p1.id$',
112+
'prod_qty' => 100
113+
],
114+
'p1Stock'
115+
),
116+
DataFixture(
117+
BundleSelectionFixture::class,
118+
[
119+
'sku' => '$p1.sku$', 'price' => 100, 'price_type' => 0
120+
],
121+
as:'link'
122+
),
123+
DataFixture(
124+
BundleOptionFixture::class,
125+
[ 'title' => 'Checkbox Options',
126+
'type' => 'checkbox',
127+
'required' => 1,
128+
'product_links' => ['$link$']
129+
],
130+
'option'
131+
),
132+
DataFixture(
133+
BundleProductFixture::class,
134+
['price' => 90, '_options' => ['$option$']],
135+
as:'bundle_product'
136+
),
137+
DataFixture(GuestCartFixture::class, as: 'cart'),
138+
DataFixture(
139+
AddBundleProductToCart::class,
140+
[
141+
'cart_id' => '$cart.id$',
142+
'product_id' => '$bundle_product.id$',
143+
'selections' => [['$p1.id$']],
144+
'qty' => 100
145+
],
146+
as: 'cart_item'
147+
),
148+
]
149+
public function testSetStockToZeroAfterAddingBundleProductToCart()
150+
{
151+
$cart = $this->fixtures->get('cart');
152+
/** @var Product $p1 */
153+
$p1 = $this->fixtures->get('p1');
154+
/** @var CartItem $cartItem */
155+
$cartItem = $this->fixtures->get('cart_item');
156+
$bundleProduct = $this->fixtures->get('bundle_product');
157+
158+
$stockItem = $this->stockRegistry->getStockItemBySku($p1->getSku());
159+
$stockItem->setQty(0);
160+
$this->stockRegistry->updateStockItemBySku($p1->getSku(), $stockItem);
161+
$maskedQuoteId = $this->quoteIdToMaskedQuoteIdInterface->execute((int) $cart->getId());
162+
$query = $this->getQuery($maskedQuoteId, 20, 1);
163+
$response = $this->graphQlQuery($query);
164+
165+
$expected = [
166+
'cart' => [
167+
'id' => $maskedQuoteId,
168+
'itemsV2' => [
169+
'total_count' => 1,
170+
'items' => [
171+
[
172+
'id' => $cartItem->getId(),
173+
'quantity' => 100,
174+
'product' => [
175+
'sku' => $bundleProduct->getSku(),
176+
'stock_status' => 'OUT_OF_STOCK',
177+
],
178+
'prices' => [
179+
'price' => [
180+
'value' => 10,
181+
'currency' => 'USD',
182+
]
183+
],
184+
'errors' => [
185+
[
186+
'code' => 'ITEM_QTY',
187+
'message' => 'This product is out of stock.'
188+
],
189+
[
190+
'code' => 'UNDEFINED',
191+
'message' => 'There are no source items with the in stock status
192+
This product is out of stock.
193+
The required options you selected are not available.'
194+
]
195+
]
196+
],
197+
],
198+
'page_info' => [
199+
'page_size' => 20,
200+
'current_page' => 1,
201+
'total_pages' => 1,
202+
]
203+
],
204+
]
205+
];
206+
$this->assertEquals(
207+
$expected,
208+
$response,
209+
sprintf("Expected:\n%s\ngot:\n%s", json_encode($expected), json_encode($response))
210+
);
211+
}
212+
96213
public function testGetCart()
97214
{
98215
/** @var Product $product1 */

0 commit comments

Comments
 (0)