Skip to content

Commit 972fc19

Browse files
committed
ACP2E-1175: [GraphQL] addProductsToWishlist with custom options returns error "Call to a member function getPriceType() on null"
1 parent 27c22e7 commit 972fc19

File tree

9 files changed

+59
-29
lines changed

9 files changed

+59
-29
lines changed

dev/tests/api-functional/testsuite/Magento/Catalog/Api/CartItemRepositoryTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
*/
1717
class CartItemRepositoryTest extends WebapiAbstract
1818
{
19-
const SERVICE_NAME = 'quoteCartItemRepositoryV1';
20-
const SERVICE_VERSION = 'V1';
21-
const SIMPLE_PRODUCT_SKU = 'simple';
19+
public const SERVICE_NAME = 'quoteCartItemRepositoryV1';
20+
public const SERVICE_VERSION = 'V1';
21+
public const SIMPLE_PRODUCT_SKU = 'simple';
2222

2323
/**
2424
* @var \Magento\TestFramework\ObjectManager
@@ -175,10 +175,10 @@ protected function getOptionRequestValue(ProductCustomOptionInterface $option)
175175
$returnValue = '2015-09-09 07:16:00';
176176
break;
177177
case 'drop_down':
178-
$returnValue = '3-1-select';
178+
$returnValue = current($option->getValues())->getOptionTypeId();
179179
break;
180180
case 'radio':
181-
$returnValue = '4-1-radio';
181+
$returnValue = current($option->getValues())->getOptionTypeId();
182182
break;
183183
}
184184
return $returnValue;

dev/tests/api-functional/testsuite/Magento/GraphQl/Wishlist/AddConfigurableProductToWishlistTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,37 @@ public function testAddConfigurableProductWithCustomOptions(): void
153153
$this->assertEquals($optionValue, $customizableOptions[0]['values'][0]['value']);
154154
}
155155

156+
/**
157+
* @magentoConfigFixture default_store wishlist/general/active 1
158+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
159+
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable_with_custom_option_dropdown.php
160+
*
161+
* @throws Exception
162+
*/
163+
public function testShouldValidateCustomDropdownOptionValue(): void
164+
{
165+
$product = $this->getConfigurableProductInfo();
166+
$qty = 2;
167+
$childSku = $product['variants'][0]['product']['sku'];
168+
$parentSku = $product['sku'];
169+
$selectedOptions = array_column($product['variants'][0]['attributes'], 'uid');
170+
$optionId = $product['options'][0]['uid'];
171+
$customOptions = [$optionId => 'invalid-option-id'];
172+
$additionalInput = $this->getSelectedOptionsQuery($selectedOptions)
173+
. PHP_EOL
174+
. $this->getCustomOptionsQuery($customOptions);
175+
176+
$query = $this->getQuery($parentSku, $childSku, $qty, $additionalInput);
177+
$response = $this->graphQlMutation($query, [], '', $this->getHeadersMap());
178+
179+
$this->assertArrayHasKey('addProductsToWishlist', $response);
180+
$this->assertNotEmpty($response['addProductsToWishlist']['user_errors']);
181+
$this->assertEquals(
182+
'Some of the selected item options are not currently available.',
183+
$response['addProductsToWishlist']['user_errors'][0]['message']
184+
);
185+
}
186+
156187
/**
157188
* Authentication header map
158189
*

dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartAddingItemsTest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class GuestCartAddingItemsTest extends WebapiAbstract
2828
* @var \Magento\TestFramework\ObjectManager
2929
*/
3030
protected $objectManager;
31-
31+
3232
/**
3333
* @var ProductResource|mixed
3434
*/
@@ -58,7 +58,9 @@ public function testAddtoCartWithCustomOptionsForCreatingQuoteFromEmptyCart()
5858
foreach ($customOptionCollection as $option) {
5959
$customOptions [] = [
6060
'option_id' => $option->getId(),
61-
'option_value' => $option->getType() !== 'field' ? 1 : 'test'
61+
'option_value' => $option->getType() !== 'field'
62+
? current($option->getValues())->getOptionTypeId()
63+
: 'test'
6264
];
6365
}
6466

@@ -96,7 +98,9 @@ public function testAddtoCartWithCustomOptionsForCreatingQuoteFromEmptyCart()
9698
foreach ($customOptionCollection as $option) {
9799
$customOptions [] = [
98100
'option_id' => $option->getId(),
99-
'option_value' => $option->getType() != 'field' ? 2 : 'test2'
101+
'option_value' => $option->getType() != 'field'
102+
? current(array_reverse($option->getValues()))->getOptionTypeId()
103+
: 'test2'
100104
];
101105
}
102106
$requestData = [

dev/tests/integration/testsuite/Magento/Sales/_files/customer_order_item_with_product_and_custom_options.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,13 @@
3838
'day_part' => 'am',
3939
'date_internal' => '',
4040
],
41-
'drop_down' => '3-1-select',
42-
'radio' => '4-1-radio',
4341
];
4442

4543
$requestInfo = ['options' => []];
4644
$productOptions = $product->getOptions();
4745
foreach ($productOptions as $option) {
48-
$requestInfo['options'][$option->getOptionId()] = $optionValuesByType[$option->getType()];
46+
$requestInfo['options'][$option->getOptionId()] = $optionValuesByType[$option->getType()]
47+
?? current($option->getValues())->getOptionTypeId();
4948
}
5049

5150
/** @var \Magento\Sales\Model\Order\Item $orderItem */

dev/tests/integration/testsuite/Magento/Sales/_files/order_with_1_qty_product.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,14 @@
4444
'minute' => '2',
4545
'day_part' => 'am',
4646
'date_internal' => '',
47-
],
48-
'drop_down' => '3-1-select',
49-
'radio' => '4-1-radio',
47+
]
5048
];
5149

5250
$requestInfo = ['options' => [], 'qty' => 1];
5351
$productOptions = $product->getOptions();
5452
foreach ($productOptions as $option) {
55-
$requestInfo['options'][$option->getOptionId()] = $optionValuesByType[$option->getType()];
53+
$requestInfo['options'][$option->getOptionId()] = $optionValuesByType[$option->getType()]
54+
?? current($option->getValues())->getOptionTypeId();
5655
}
5756

5857
/** @var \Magento\Sales\Model\Order\Item $orderItem */

dev/tests/integration/testsuite/Magento/Sales/_files/order_with_js_date_option_product.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,14 @@
3636
'minute' => '15',
3737
'day_part' => 'am',
3838
'date_internal' => '2020-09-30 02:15:00'
39-
],
40-
'drop_down' => '3-1-select',
41-
'radio' => '4-1-radio',
39+
]
4240
];
4341

4442
$requestInfo = ['options' => []];
4543
$productOptions = $product->getOptions();
4644
foreach ($productOptions as $option) {
47-
$requestInfo['options'][$option->getOptionId()] = $optionValuesByType[$option->getType()];
45+
$requestInfo['options'][$option->getOptionId()] = $optionValuesByType[$option->getType()]
46+
?? current($option->getValues())->getOptionTypeId();
4847
}
4948

5049
/** @var \Magento\Sales\Model\Order\Item $orderItem */

dev/tests/integration/testsuite/Magento/Sales/_files/order_with_two_simple_products.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,14 @@
4242
'minute' => '2',
4343
'day_part' => 'am',
4444
'date_internal' => '',
45-
],
46-
'drop_down' => '3-1-select',
47-
'radio' => '4-1-radio',
45+
]
4846
];
4947

5048
$requestInfo = ['options' => [], 'qty' => 1];
5149
$productOptions = $product->getOptions();
5250
foreach ($productOptions as $option) {
53-
$requestInfo['options'][$option->getOptionId()] = $optionValuesByType[$option->getType()];
51+
$requestInfo['options'][$option->getOptionId()] = $optionValuesByType[$option->getType()]
52+
?? current($option->getValues())->getOptionTypeId();
5453
}
5554

5655
/** @var \Magento\Sales\Model\Order\Item $orderItem */

dev/tests/integration/testsuite/Magento/Sales/_files/order_with_zero_qty_product.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,14 @@
4343
'minute' => '2',
4444
'day_part' => 'am',
4545
'date_internal' => '',
46-
],
47-
'drop_down' => '3-1-select',
48-
'radio' => '4-1-radio',
46+
]
4947
];
5048

5149
$requestInfo = ['options' => [], 'qty' => 1];
5250
$productOptions = $product->getOptions();
5351
foreach ($productOptions as $option) {
54-
$requestInfo['options'][$option->getOptionId()] = $optionValuesByType[$option->getType()];
52+
$requestInfo['options'][$option->getOptionId()] = $optionValuesByType[$option->getType()]
53+
?? current($option->getValues())->getOptionTypeId();
5554
}
5655

5756
/** @var \Magento\Sales\Model\Order\Item $orderItem */

dev/tests/integration/testsuite/Magento/Wishlist/_files/wishlist_shared.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
$options[$option->getId()] = ['month' => 1, 'day' => 1, 'year' => 2001, 'hour' => 1, 'minute' => 1];
3232
break;
3333
case 'drop_down':
34-
$options[$option->getId()] = '1';
34+
$options[$option->getId()] = current($option->getValues())->getOptionTypeId();
3535
break;
3636
case 'radio':
37-
$options[$option->getId()] = '1';
37+
$options[$option->getId()] = current($option->getValues())->getOptionTypeId();
3838
break;
3939
}
4040
}

0 commit comments

Comments
 (0)