Skip to content

Commit 742e6a7

Browse files
XxXgeoXxXnaydav
authored andcommitted
Cannot return null for non-nullable field SelectedCustomizableOptionValue.sort_order and Call to a member function getPriceType() on null
1 parent 81daba8 commit 742e6a7

File tree

2 files changed

+83
-1
lines changed

2 files changed

+83
-1
lines changed

app/code/Magento/QuoteGraphQl/Model/Cart/AddSimpleProductToCart.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
1616
use Magento\Framework\Stdlib\ArrayManager;
1717
use Magento\Quote\Model\Quote;
18-
use phpDocumentor\Reflection\Types\Mixed_;
1918

2019
/**
2120
* Add simple product to cart

dev/tests/api-functional/testsuite/Magento/GraphQl/CatalogInventory/AddProductToCartTest.php

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,89 @@ public function testAddProductIfQuantityIsNotAvailable()
4646
$this->graphQlMutation($query);
4747
}
4848

49+
/**
50+
* @magentoApiDataFixture Magento/Catalog/_files/product_simple_with_custom_options.php
51+
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
52+
* @expectedException \Exception
53+
* @expectedExceptionMessage The product's required option(s) weren't entered. Make sure the options are entered and try again.
54+
*/
55+
public function testAddProductWithoutRequiredCustomOPtions()
56+
{
57+
$sku = 'simple_with_custom_options';
58+
$qty = 1;
59+
60+
$maskedQuoteId = $this->getMaskedQuoteId();
61+
$query = $this->getAddSimpleProductQuery($maskedQuoteId, $sku, $qty);
62+
$this->graphQlQuery($query);
63+
}
64+
65+
/**
66+
* @magentoApiDataFixture Magento/Catalog/_files/product_simple_with_custom_options.php
67+
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
68+
*/
69+
public function testAddProductWithRequiredCustomOPtions()
70+
{
71+
$sku = 'simple_with_custom_options';
72+
$qty = 1;
73+
$productCustomOptions = Bootstrap::getObjectManager()
74+
->get(\Magento\Catalog\Api\ProductCustomOptionRepositoryInterface::class)
75+
->getList($sku);
76+
$customizableOptions = '';
77+
foreach ($productCustomOptions as $option) {
78+
$value = $option->getValues() ?
79+
'[' . key($option->getValues()) . ']' :
80+
'Test';
81+
$customizableOptions .= ' {
82+
id: ' . $option->getId() . '
83+
value: "' . $value . '"
84+
}';
85+
}
86+
87+
$maskedQuoteId = $this->getMaskedQuoteId();
88+
$query = <<<QUERY
89+
mutation {
90+
addSimpleProductsToCart(
91+
input: {
92+
cart_id: "{$maskedQuoteId}"
93+
cartItems: {
94+
data: {
95+
qty: {$qty}
96+
sku: "{$sku}"
97+
}
98+
customizable_options: [
99+
{$customizableOptions}
100+
]
101+
}
102+
}
103+
)
104+
{
105+
cart {
106+
items {
107+
product {
108+
sku
109+
}
110+
... on SimpleCartItem {
111+
customizable_options {
112+
id
113+
is_required
114+
sort_order
115+
}
116+
}
117+
}
118+
}
119+
}
120+
}
121+
QUERY;
122+
$response = $this->graphQlQuery($query);
123+
self::assertArrayHasKey('cart', $response['addSimpleProductsToCart']);
124+
125+
self::assertEquals($sku, $response['addSimpleProductsToCart']['cart']['items'][0]['product']['sku']);
126+
self::assertEquals(
127+
1,
128+
$response['addSimpleProductsToCart']['cart']['items'][0]['customizable_options'][0]['is_required']
129+
);
130+
}
131+
49132
/**
50133
* @magentoApiDataFixture Magento/Catalog/_files/products.php
51134
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php

0 commit comments

Comments
 (0)