Skip to content
This repository was archived by the owner on Dec 19, 2019. It is now read-only.

Commit 0071ef0

Browse files
author
Roman Glushko
committed
#141 Enables checkbox custom options
1 parent c63e9e8 commit 0071ef0

File tree

2 files changed

+41
-9
lines changed

2 files changed

+41
-9
lines changed

app/code/Magento/QuoteGraphQl/Model/Resolver/CartItem/CustomizableOptions.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ private function getOptionData($cartItem, int $optionId): array
131131

132132
if (ProductCustomOptionInterface::OPTION_TYPE_DROP_DOWN == $option->getType()
133133
|| ProductCustomOptionInterface::OPTION_TYPE_RADIO == $option->getType()
134+
|| ProductCustomOptionInterface::OPTION_TYPE_CHECKBOX == $option->getType()
134135
) {
135136
$optionValue = $option->getValueById($itemOption->getValue());
136137
$selectedOptionValueData['price'] = [

dev/tests/api-functional/testsuite/Magento/GraphQl/SimpleProduct/AddSimpleProductsToCartTest.php

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77

88
namespace Magento\GraphQl\Quote;
99

10-
use Magento\Quote\Api\CartRepositoryInterface;
10+
use Magento\Catalog\Api\Data\ProductCustomOptionInterface;
11+
use Magento\Catalog\Api\ProductRepositoryInterface;
12+
use Magento\Framework\Exception\NoSuchEntityException;
1113
use Magento\Quote\Model\Quote as QuoteModel;
12-
use Magento\Quote\Model\QuoteIdMask;
1314
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
1415
use Magento\TestFramework\ObjectManager;
1516
use Magento\TestFramework\TestCase\GraphQlAbstract;
@@ -19,11 +20,6 @@
1920
*/
2021
class AddSimpleProductsToCartTest extends GraphQlAbstract
2122
{
22-
/**
23-
* @var QuoteIdMask
24-
*/
25-
private $quoteIdMask;
26-
2723
/**
2824
* @var ObjectManager
2925
*/
@@ -39,14 +35,19 @@ class AddSimpleProductsToCartTest extends GraphQlAbstract
3935
*/
4036
private $quoteIdToMaskedQuote;
4137

38+
/**
39+
* @var ProductRepositoryInterface
40+
*/
41+
private $productRepository;
42+
4243
/**
4344
* @return void
4445
*/
4546
protected function setUp()
4647
{
4748
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
48-
$this->quoteIdMask = $this->objectManager->create(QuoteIdMask::class);
4949
$this->quoteModel = $this->objectManager->create(QuoteModel::class);
50+
$this->productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
5051
$this->quoteIdToMaskedQuote = $this->objectManager->create(QuoteIdToMaskedQuoteIdInterface::class);
5152
}
5253

@@ -57,8 +58,10 @@ protected function setUp()
5758
*/
5859
public function testAddSimpleProductsToCartForGuest()
5960
{
61+
$productSku = 'simple';
6062
$this->quoteModel->load('test_order_1', 'reserved_order_id');
6163
$quoteHash = $this->quoteIdToMaskedQuote->execute((int) $this->quoteModel->getId());
64+
$selectedOptionData = $this->getSelectedOptionData($productSku);
6265

6366
$query = <<<QUERY
6467
mutation {
@@ -68,7 +71,7 @@ public function testAddSimpleProductsToCartForGuest()
6871
cartItems: [
6972
{
7073
details: {
71-
sku: "simple",
74+
sku: "$productSku",
7275
qty: 1
7376
},
7477
customizable_options: [{id: 1, value: "Test"}, {id: 2, value: "Wow"}, {id: 3, value: "test.jpg"}, {id: 5, value: "1"}, {id: 6, value: "3"}]
@@ -120,4 +123,32 @@ public function testAddSimpleProductsToCartForGuest()
120123

121124

122125
}
126+
127+
/**
128+
* @param string $productSku
129+
* @throws NoSuchEntityException
130+
*/
131+
protected function getSelectedOptionData(string $productSku)
132+
{
133+
$selectedProductData = [];
134+
$product = $this->productRepository->get($productSku);
135+
$fieldTypes = [ProductCustomOptionInterface::OPTION_TYPE_AREA, ProductCustomOptionInterface::OPTION_TYPE_FIELD];
136+
$dropdownTypes = [
137+
ProductCustomOptionInterface::OPTION_TYPE_DROP_DOWN,
138+
ProductCustomOptionInterface::OPTION_TYPE_RADIO,
139+
ProductCustomOptionInterface::OPTION_TYPE_CHECKBOX,
140+
];
141+
142+
foreach ($product->getOptions() as $option) {
143+
if (in_array($option->getType(), $fieldTypes)) {
144+
$selectedProductData[$option->getOptionId()] = $option->getType(); // custom text
145+
}
146+
if (in_array($option->getType(), $dropdownTypes)) {
147+
$optionValues = $option->getValues();
148+
149+
}
150+
}
151+
152+
return $selectedProductData;
153+
}
123154
}

0 commit comments

Comments
 (0)