Skip to content

Commit 37247d0

Browse files
Indrani sonawaneIndrani sonawane
authored andcommitted
Merge remote-tracking branch 'karyna-tsymbal-atwix/fix-method-for-checking-bundle-required-options' into comm_78764_25677
2 parents e0d650c + bcee625 commit 37247d0

File tree

4 files changed

+249
-1
lines changed

4 files changed

+249
-1
lines changed

app/code/Magento/Bundle/Model/Product/Type.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,7 @@ protected function checkIsAllRequiredOptions($product, $isStrictProcessMode, $op
12861286
{
12871287
if (!$product->getSkipCheckRequiredOption() && $isStrictProcessMode) {
12881288
foreach ($optionsCollection->getItems() as $option) {
1289-
if ($option->getRequired() && !isset($options[$option->getId()])) {
1289+
if ($option->getRequired() && empty($options[$option->getId()])) {
12901290
throw new \Magento\Framework\Exception\LocalizedException(
12911291
__('Please select all required options.')
12921292
);

dev/tests/api-functional/testsuite/Magento/GraphQl/Bundle/AddBundleProductToCartTest.php

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,103 @@ public function testAddBundleToCartWithRadioAndSelectErr()
372372
}
373373
}
374374
}
375+
QUERY;
376+
377+
$this->graphQlMutation($query);
378+
}
379+
380+
/**
381+
* @magentoApiDataFixture Magento/Bundle/_files/product_with_multiple_options_multiselect_checkbox.php
382+
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
383+
*/
384+
public function testAddBundleToCartWithEmptyMultiselectOptionValue()
385+
{
386+
$this->expectException(\Exception::class);
387+
$this->expectExceptionMessage('Please select all required options.');
388+
389+
$this->quoteResource->load(
390+
$this->quote,
391+
'test_order_1',
392+
'reserved_order_id'
393+
);
394+
$sku = 'bundle-product-multiselect-checkbox-options';
395+
$product = $this->productRepository->get($sku);
396+
397+
/** @var $typeInstance \Magento\Bundle\Model\Product\Type */
398+
$typeInstance = $product->getTypeInstance();
399+
$typeInstance->setStoreFilter($product->getStoreId(), $product);
400+
/** @var $option \Magento\Bundle\Model\Option */
401+
$options = $typeInstance->getOptionsCollection($product);
402+
403+
$selectionIds = [];
404+
$optionIds = [];
405+
foreach ($options as $option) {
406+
$type = $option->getType();
407+
408+
/** @var \Magento\Catalog\Model\Product $selection */
409+
$selections = $typeInstance->getSelectionsCollection([$option->getId()], $product);
410+
$optionIds[$type] = $option->getId();
411+
412+
foreach ($selections->getItems() as $selection) {
413+
$selectionIds[$type][] = $selection->getSelectionId();
414+
}
415+
}
416+
417+
$maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$this->quote->getId());
418+
419+
$query = <<<QUERY
420+
mutation {
421+
addBundleProductsToCart(input:{
422+
cart_id: "{$maskedQuoteId}"
423+
cart_items: [
424+
{
425+
data: {
426+
sku: "{$sku}"
427+
quantity: 1
428+
}
429+
bundle_options: [
430+
{
431+
id: {$optionIds['multi']}
432+
quantity: 1
433+
value: [
434+
""
435+
]
436+
},
437+
{
438+
id: {$optionIds['checkbox']}
439+
quantity: 1
440+
value: [
441+
"{$selectionIds['checkbox'][0]}"
442+
]
443+
}
444+
]
445+
}
446+
]
447+
}) {
448+
cart {
449+
items {
450+
id
451+
quantity
452+
product {
453+
sku
454+
}
455+
... on BundleCartItem {
456+
bundle_options {
457+
id
458+
label
459+
type
460+
values {
461+
id
462+
label
463+
price
464+
quantity
465+
}
466+
}
467+
}
468+
}
469+
}
470+
}
471+
}
375472
QUERY;
376473

377474
$this->graphQlMutation($query);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Magento\Bundle\Model\Product\Price;
9+
use Magento\Catalog\Api\ProductRepositoryInterface;
10+
use Magento\Catalog\Model\Product\Attribute\Source\Status;
11+
use Magento\Catalog\Model\Product\Type;
12+
use Magento\Catalog\Model\Product\Type\AbstractType;
13+
use Magento\Catalog\Model\Product\Visibility;
14+
use Magento\Catalog\Model\ProductFactory;
15+
use Magento\Store\Api\WebsiteRepositoryInterface;
16+
use Magento\TestFramework\Bundle\Model\PrepareBundleLinks;
17+
use Magento\TestFramework\Helper\Bootstrap;
18+
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
19+
20+
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_duplicated.php');
21+
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/second_product_simple.php');
22+
23+
$objectManager = Bootstrap::getObjectManager();
24+
25+
/** @var WebsiteRepositoryInterface $websiteRepository */
26+
$websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
27+
$baseWebsiteId = $websiteRepository->get('base')->getId();
28+
29+
/** @var PrepareBundleLinks $prepareBundleLinks */
30+
$prepareBundleLinks = $objectManager->get(PrepareBundleLinks::class);
31+
32+
/** @var ProductFactory $productFactory */
33+
$productFactory = $objectManager->get(ProductFactory::class);
34+
35+
/** @var ProductRepositoryInterface $productRepository */
36+
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
37+
38+
$productRepository->cleanCache();
39+
$product = $productRepository->get('simple-1');
40+
$product2 = $productRepository->get('simple2');
41+
42+
$bundleProduct = $productFactory->create();
43+
$bundleProduct->setTypeId(Type::TYPE_BUNDLE)
44+
->setId(3)
45+
->setAttributeSetId($bundleProduct->getDefaultAttributeSetId())
46+
->setWebsiteIds([$baseWebsiteId])
47+
->setName('Bundle Product Multiselect&Checkbox Options')
48+
->setSku('bundle-product-multiselect-checkbox-options')
49+
->setVisibility(Visibility::VISIBILITY_BOTH)
50+
->setStatus(Status::STATUS_ENABLED)
51+
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
52+
->setPriceView(0)
53+
->setSkuType(1)
54+
->setWeightType(1)
55+
->setPriceType(Price::PRICE_TYPE_DYNAMIC)
56+
->setPrice(10.0)
57+
->setShipmentType(AbstractType::SHIPMENT_TOGETHER);
58+
59+
$bundleOptionsData = [
60+
[
61+
'title' => 'Checkbox Options',
62+
'default_title' => 'Checkbox Options',
63+
'type' => 'checkbox',
64+
'required' => 1,
65+
'delete' => '',
66+
],
67+
[
68+
'title' => 'Multiselect Options',
69+
'default_title' => 'Multiselect Options',
70+
'type' => 'multi',
71+
'required' => 1,
72+
'delete' => '',
73+
],
74+
];
75+
76+
$productSku1 = $product->getSku();
77+
$productSku2 = $product2->getSku();
78+
79+
$bundleSelectionsData = [
80+
[
81+
[
82+
'sku' => $productSku1,
83+
'selection_qty' => 1,
84+
'selection_can_change_qty' => 1,
85+
'delete' => '',
86+
'option_id' => 1
87+
],
88+
[
89+
'sku' => $productSku2,
90+
'selection_qty' => 1,
91+
'selection_can_change_qty' => 1,
92+
'delete' => '',
93+
'option_id' => 1
94+
]
95+
],
96+
[
97+
[
98+
'sku' => $productSku1,
99+
'selection_qty' => 1,
100+
'selection_can_change_qty' => 0,
101+
'delete' => '',
102+
'option_id' => 2
103+
],
104+
[
105+
'sku' => $productSku2,
106+
'selection_qty' => 1,
107+
'selection_can_change_qty' => 0,
108+
'delete' => '',
109+
'option_id' => 2
110+
]
111+
]
112+
];
113+
114+
$bundleProduct = $prepareBundleLinks->execute($bundleProduct, $bundleOptionsData, $bundleSelectionsData);
115+
116+
$productRepository->save($bundleProduct);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Magento\Catalog\Api\ProductRepositoryInterface;
9+
use Magento\Framework\Exception\NoSuchEntityException;
10+
use Magento\Framework\Registry;
11+
use Magento\TestFramework\Helper\Bootstrap;
12+
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
13+
14+
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_duplicated_rollback.php');
15+
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/second_product_simple_rollback.php');
16+
17+
$objectManager = Bootstrap::getObjectManager();
18+
/** @var Registry $registry */
19+
$registry = $objectManager->get(Registry::class);
20+
$registry->unregister('isSecureArea');
21+
$registry->register('isSecureArea', true);
22+
/** @var ProductRepositoryInterface $productRepository */
23+
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
24+
25+
$sku = 'bundle-product-multiselect-checkbox-options';
26+
27+
try {
28+
$product = $productRepository->get($sku, false, null, true);
29+
$productRepository->delete($product);
30+
} catch (NoSuchEntityException $e) {
31+
//Product already removed
32+
}
33+
34+
$registry->unregister('isSecureArea');
35+
$registry->register('isSecureArea', false);

0 commit comments

Comments
 (0)