26
26
use Magento \ConfigurableProduct \Test \Fixture \AddProductToCart as AddConfigurableProductToCartFixture ;
27
27
use Magento \ConfigurableProduct \Test \Fixture \Attribute as AttributeFixture ;
28
28
use Magento \ConfigurableProduct \Test \Fixture \Product as ConfigurableProductFixture ;
29
+ use Magento \Eav \Api \Data \AttributeInterface ;
30
+ use Magento \Eav \Api \Data \AttributeOptionInterface ;
29
31
use Magento \Framework \DataObject ;
30
32
use Magento \Framework \ObjectManagerInterface ;
31
33
use Magento \Quote \Test \Fixture \AddProductToCart ;
@@ -266,33 +268,71 @@ public function testStockStatusUnavailableConfigurableProduct(): void
266
268
}
267
269
268
270
#[
269
- DataFixture(ProductFixture::class, [ ' sku ' => self :: SKU ], as: 'product ' ),
271
+ DataFixture(ProductFixture::class, as: 'product ' ),
270
272
DataFixture(AttributeFixture::class, as: 'attribute ' ),
271
273
DataFixture(
272
274
ConfigurableProductFixture::class,
273
- ['sku ' => self :: PARENT_SKU_CONFIGURABLE , ' _options ' => ['$attribute$ ' ], '_links ' => ['$product$ ' ]],
275
+ ['_options ' => ['$attribute$ ' ], '_links ' => ['$product$ ' ]],
274
276
'configurable_product '
275
277
),
276
278
DataFixture(GuestCartFixture::class, as: 'cart ' ),
277
279
DataFixture(QuoteMaskFixture::class, ['cart_id ' => '$cart.id$ ' ], 'quoteIdMask ' ),
280
+ DataFixture(ProductStockFixture::class, ['prod_id ' => '$product.id$ ' , 'prod_qty ' => 100 ], 'prodStock ' ),
278
281
DataFixture(
279
282
AddConfigurableProductToCartFixture::class,
280
283
[
281
284
'cart_id ' => '$cart.id$ ' ,
282
285
'product_id ' => '$configurable_product.id$ ' ,
283
286
'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$ ' ],
285
312
],
286
- )
313
+ 'configurable_product '
314
+ ),
315
+ DataFixture(GuestCartFixture::class, as: 'cart ' ),
316
+ DataFixture(QuoteMaskFixture::class, ['cart_id ' => '$cart.id$ ' ], 'quoteIdMask ' ),
287
317
]
288
318
public function testStockStatusAddConfigurableProduct (): void
289
319
{
290
320
$ 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
+ );
292
332
$ response = $ this ->graphQlMutation ($ query );
293
333
$ responseDataObject = new DataObject ($ response );
294
334
self ::assertTrue (
295
- $ responseDataObject ->getData ('addProductsToCart/cart/items/1 /is_available ' )
335
+ $ responseDataObject ->getData ('addProductsToCart/cart/items/0 /is_available ' )
296
336
);
297
337
$ response = $ this ->graphQlMutation ($ query );
298
338
$ responseDataObject = new DataObject ($ response );
@@ -376,7 +416,7 @@ private function mutationAddBundleProduct(
376
416
private function mutationAddConfigurableProduct (
377
417
string $ cartId ,
378
418
string $ sku ,
379
- string $ parentSku ,
419
+ string $ selectedOption ,
380
420
int $ qty = 1
381
421
): string {
382
422
return <<<QUERY
@@ -387,7 +427,9 @@ private function mutationAddConfigurableProduct(
387
427
{
388
428
sku: " {$ sku }"
389
429
quantity: $ qty
390
- parent_sku: " {$ parentSku }"
430
+ selected_options: [
431
+ " $ selectedOption"
432
+ ]
391
433
}]
392
434
) {
393
435
cart {
0 commit comments