diff --git a/app/code/Magento/QuoteGraphQl/etc/schema.graphqls b/app/code/Magento/QuoteGraphQl/etc/schema.graphqls index bf77d2e6e07b5..e8653da785c97 100644 --- a/app/code/Magento/QuoteGraphQl/etc/schema.graphqls +++ b/app/code/Magento/QuoteGraphQl/etc/schema.graphqls @@ -360,7 +360,7 @@ interface CartItemInterface @typeResolver(class: "Magento\\QuoteGraphQl\\Model\\ id: String! @deprecated(reason: "Use `uid` instead.") uid: ID! @doc(description: "The unique ID for a `CartItemInterface` object.") quantity: Float! @doc(description: "The quantity of this item in the cart.") - is_available: Boolean! @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\CheckProductStockAvailability") @doc(description: "If qty is more than stock display status as unavailable else available.") + is_available: Boolean! @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\CheckProductStockAvailability") @doc(description: "True if requested quantity is less than available stock, false otherwise.") prices: CartItemPrices @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\CartItemPrices") @doc(description: "Contains details about the price of the item, including taxes and discounts.") product: ProductInterface! @doc(description: "Details about an item in the cart.") errors: [CartItemError!] @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\CartItemErrors") @doc(description: "An array of errors encountered while loading the cart item") diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/StockAvailabilityTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/StockAvailabilityTest.php index b8dbc2f5ab7c0..bdf6423e1f8f3 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/StockAvailabilityTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/StockAvailabilityTest.php @@ -86,24 +86,47 @@ public function testStockStatusUnavailableSimpleProduct(): void $response = $this->graphQlMutation($query); $responseDataObject = new DataObject($response); - self::assertEquals(false, $responseDataObject->getData('cart/items/0/is_available')); + self::assertFalse( + $responseDataObject->getData('cart/items/0/is_available') + ); } #[ - DataFixture(ProductFixture::class, ['sku' => self::SKU, 'price' => 100.00], as: 'product'), + DataFixture(ProductFixture::class, ['price' => 100.00], as: 'product'), DataFixture(GuestCartFixture::class, as: 'cart'), DataFixture(AddProductToCart::class, ['cart_id' => '$cart.id$', 'product_id' => '$product.id$', 'qty' => 100]), DataFixture(QuoteMaskFixture::class, ['cart_id' => '$cart.id$'], 'quoteIdMask') ] - public function testStockStatusUnavailableAddSimpleProduct(): void + public function testStockStatusAvailableSimpleProduct(): void { $maskedQuoteId = $this->fixtures->get('quoteIdMask')->getMaskedId(); - $query = $this->mutationAddSimpleProduct($maskedQuoteId, self::SKU, 1); + $query = $this->getQuery($maskedQuoteId); $response = $this->graphQlMutation($query); $responseDataObject = new DataObject($response); - self::assertEquals( - false, + self::assertTrue( + $responseDataObject->getData('cart/items/0/is_available') + ); + } + + #[ + DataFixture(ProductFixture::class, ['sku' => self::SKU, 'price' => 100.00], as: 'product'), + DataFixture(GuestCartFixture::class, as: 'cart'), + DataFixture(AddProductToCart::class, ['cart_id' => '$cart.id$', 'product_id' => '$product.id$', 'qty' => 99]), + DataFixture(QuoteMaskFixture::class, ['cart_id' => '$cart.id$'], 'quoteIdMask') + ] + public function testStockStatusAddSimpleProduct(): void + { + $maskedQuoteId = $this->fixtures->get('quoteIdMask')->getMaskedId(); + $query = $this->mutationAddSimpleProduct($maskedQuoteId, self::SKU, 1); + $response = $this->graphQlMutation($query); + $responseDataObject = new DataObject($response); + self::assertTrue( + $responseDataObject->getData('addProductsToCart/cart/items/0/is_available') + ); + $response = $this->graphQlMutation($query); + $responseDataObject = new DataObject($response); + self::assertFalse( $responseDataObject->getData('addProductsToCart/cart/items/0/is_available') ); } @@ -144,8 +167,7 @@ public function testStockStatusUnavailableBundleProduct(): void $response = $this->graphQlMutation($query); $responseDataObject = new DataObject($response); - self::assertEquals( - false, + self::assertFalse( $responseDataObject->getData('cart/items/0/is_available') ); } @@ -173,12 +195,12 @@ public function testStockStatusUnavailableBundleProduct(): void 'cart_id' => '$cart.id$', 'product_id' => '$bundleProduct.id$', 'selections' => [['$product.id$']], - 'qty' => 100 + 'qty' => 99 ], ), DataFixture(QuoteMaskFixture::class, ['cart_id' => '$cart.id$'], 'quoteIdMask') ] - public function testStockStatusUnavailableAddBundleProduct(): void + public function testStockStatusAddBundleProduct(): void { $product = $this->productRepository->get(self::PARENT_SKU_BUNDLE); @@ -198,9 +220,14 @@ public function testStockStatusUnavailableAddBundleProduct(): void $query = $this->mutationAddBundleProduct($maskedQuoteId, self::PARENT_SKU_BUNDLE, $bundleOptionIdV2); $response = $this->graphQlMutation($query); $responseDataObject = new DataObject($response); + self::assertTrue( + $responseDataObject->getData('addProductsToCart/cart/items/0/is_available') + ); - self::assertEquals( - false, + $response = $this->graphQlMutation($query); + $responseDataObject = new DataObject($response); + + self::assertFalse( $responseDataObject->getData('addProductsToCart/cart/items/0/is_available') ); } @@ -233,8 +260,7 @@ public function testStockStatusUnavailableConfigurableProduct(): void $response = $this->graphQlMutation($query); $responseDataObject = new DataObject($response); - self::assertEquals( - false, + self::assertFalse( $responseDataObject->getData('cart/items/0/is_available') ); } @@ -259,15 +285,18 @@ public function testStockStatusUnavailableConfigurableProduct(): void ], ) ] - public function testStockStatusUnavailableAddConfigurableProduct(): void + public function testStockStatusAddConfigurableProduct(): void { $maskedQuoteId = $this->fixtures->get('quoteIdMask')->getMaskedId(); $query = $this->mutationAddConfigurableProduct($maskedQuoteId, self::SKU, self::PARENT_SKU_CONFIGURABLE); $response = $this->graphQlMutation($query); $responseDataObject = new DataObject($response); - - self::assertEquals( - false, + self::assertTrue( + $responseDataObject->getData('addProductsToCart/cart/items/1/is_available') + ); + $response = $this->graphQlMutation($query); + $responseDataObject = new DataObject($response); + self::assertFalse( $responseDataObject->getData('addProductsToCart/cart/items/0/is_available') ); } @@ -369,6 +398,10 @@ private function mutationAddConfigurableProduct( } } } + user_errors { + code + message + } } } QUERY;