2626use Magento \ConfigurableProduct \Test \Fixture \AddProductToCart as AddConfigurableProductToCartFixture ;
2727use Magento \ConfigurableProduct \Test \Fixture \Attribute as AttributeFixture ;
2828use Magento \ConfigurableProduct \Test \Fixture \Product as ConfigurableProductFixture ;
29+ use Magento \Eav \Api \Data \AttributeInterface ;
30+ use Magento \Eav \Api \Data \AttributeOptionInterface ;
2931use Magento \Framework \DataObject ;
3032use Magento \Framework \ObjectManagerInterface ;
3133use Magento \Quote \Test \Fixture \AddProductToCart ;
@@ -266,33 +268,71 @@ public function testStockStatusUnavailableConfigurableProduct(): void
266268 }
267269
268270 #[
269- DataFixture(ProductFixture::class, [ ' sku ' => self :: SKU ], as: 'product ' ),
271+ DataFixture(ProductFixture::class, as: 'product ' ),
270272 DataFixture(AttributeFixture::class, as: 'attribute ' ),
271273 DataFixture(
272274 ConfigurableProductFixture::class,
273- ['sku ' => self :: PARENT_SKU_CONFIGURABLE , ' _options ' => ['$attribute$ ' ], '_links ' => ['$product$ ' ]],
275+ ['_options ' => ['$attribute$ ' ], '_links ' => ['$product$ ' ]],
274276 'configurable_product '
275277 ),
276278 DataFixture(GuestCartFixture::class, as: 'cart ' ),
277279 DataFixture(QuoteMaskFixture::class, ['cart_id ' => '$cart.id$ ' ], 'quoteIdMask ' ),
280+ DataFixture(ProductStockFixture::class, ['prod_id ' => '$product.id$ ' , 'prod_qty ' => 100 ], 'prodStock ' ),
278281 DataFixture(
279282 AddConfigurableProductToCartFixture::class,
280283 [
281284 'cart_id ' => '$cart.id$ ' ,
282285 'product_id ' => '$configurable_product.id$ ' ,
283286 'child_product_id ' => '$product.id$ ' ,
284- 'qty ' => 100
287+ 'qty ' => 90
288+ ],
289+ ),
290+ ]
291+ public function testStockStatusAvailableConfigurableProduct (): void
292+ {
293+ $ maskedQuoteId = $ this ->fixtures ->get ('quoteIdMask ' )->getMaskedId ();
294+ $ query = $ this ->getQuery ($ maskedQuoteId );
295+ $ response = $ this ->graphQlMutation ($ query );
296+ $ responseDataObject = new DataObject ($ response );
297+
298+ self ::assertTrue (
299+ $ responseDataObject ->getData ('cart/items/0/is_available ' )
300+ );
301+ }
302+
303+ #[
304+ DataFixture(ProductFixture::class, ['sku ' => self ::SKU ], as: 'product ' ),
305+ DataFixture(AttributeFixture::class, as: 'attribute ' ),
306+ DataFixture(
307+ ConfigurableProductFixture::class,
308+ [
309+ 'sku ' => self ::PARENT_SKU_CONFIGURABLE ,
310+ '_options ' => ['$attribute$ ' ],
311+ '_links ' => ['$product$ ' ],
285312 ],
286- )
313+ 'configurable_product '
314+ ),
315+ DataFixture(GuestCartFixture::class, as: 'cart ' ),
316+ DataFixture(QuoteMaskFixture::class, ['cart_id ' => '$cart.id$ ' ], 'quoteIdMask ' ),
287317 ]
288318 public function testStockStatusAddConfigurableProduct (): void
289319 {
290320 $ maskedQuoteId = $ this ->fixtures ->get ('quoteIdMask ' )->getMaskedId ();
291- $ query = $ this ->mutationAddConfigurableProduct ($ maskedQuoteId , self ::SKU , self ::PARENT_SKU_CONFIGURABLE );
321+ /** @var AttributeInterface $attribute */
322+ $ attribute = $ this ->fixtures ->get ('attribute ' );
323+ /** @var AttributeOptionInterface $option */
324+ $ option = $ attribute ->getOptions ()[1 ];
325+ $ selectedOption = base64_encode ("configurable/ {$ attribute ->getAttributeId ()}/ {$ option ->getValue ()}" );
326+ $ query = $ this ->mutationAddConfigurableProduct (
327+ $ maskedQuoteId ,
328+ self ::PARENT_SKU_CONFIGURABLE ,
329+ $ selectedOption ,
330+ 100
331+ );
292332 $ response = $ this ->graphQlMutation ($ query );
293333 $ responseDataObject = new DataObject ($ response );
294334 self ::assertTrue (
295- $ responseDataObject ->getData ('addProductsToCart/cart/items/1 /is_available ' )
335+ $ responseDataObject ->getData ('addProductsToCart/cart/items/0 /is_available ' )
296336 );
297337 $ response = $ this ->graphQlMutation ($ query );
298338 $ responseDataObject = new DataObject ($ response );
@@ -376,7 +416,7 @@ private function mutationAddBundleProduct(
376416 private function mutationAddConfigurableProduct (
377417 string $ cartId ,
378418 string $ sku ,
379- string $ parentSku ,
419+ string $ selectedOption ,
380420 int $ qty = 1
381421 ): string {
382422 return <<<QUERY
@@ -387,7 +427,9 @@ private function mutationAddConfigurableProduct(
387427 {
388428 sku: " {$ sku }"
389429 quantity: $ qty
390- parent_sku: " {$ parentSku }"
430+ selected_options: [
431+ " $ selectedOption"
432+ ]
391433 }]
392434 ) {
393435 cart {
0 commit comments