Skip to content

Commit 7f87458

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-70540' into 2.2-develop-pr10
2 parents 5e62491 + df2f289 commit 7f87458

File tree

10 files changed

+305
-9
lines changed

10 files changed

+305
-9
lines changed

app/code/Magento/Bundle/Block/Catalog/Product/View/Type/Bundle/Option.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function getDefaultValues()
142142
*/
143143
protected function _getSelectedOptions()
144144
{
145-
if (is_null($this->_selectedOptions)) {
145+
if ($this->_selectedOptions === null) {
146146
$this->_selectedOptions = [];
147147

148148
/** @var \Magento\Bundle\Model\Option $option */
@@ -152,17 +152,29 @@ protected function _getSelectedOptions()
152152
$selectionId = $this->getProduct()->getPreconfiguredValues()->getData(
153153
'bundle_option/' . $option->getId()
154154
);
155-
if ($selectionId && $option->getSelectionById($selectionId)) {
156-
$this->_selectedOptions = $selectionId;
157-
} elseif (!$option->getRequired()) {
158-
$this->_selectedOptions = 'None';
159-
}
155+
$this->assignSelection($option, $selectionId);
160156
}
161157
}
162158

163159
return $this->_selectedOptions;
164160
}
165161

162+
/**
163+
* Set selected options.
164+
*
165+
* @param \Magento\Bundle\Model\Option $option
166+
* @param mixed $selectionId
167+
* @return void
168+
*/
169+
protected function assignSelection(\Magento\Bundle\Model\Option $option, $selectionId)
170+
{
171+
if ($selectionId && $option->getSelectionById($selectionId)) {
172+
$this->_selectedOptions = $selectionId;
173+
} elseif (!$option->getRequired()) {
174+
$this->_selectedOptions = 'None';
175+
}
176+
}
177+
166178
/**
167179
* Define if selection is selected
168180
*

app/code/Magento/Bundle/Block/Catalog/Product/View/Type/Bundle/Option/Multi.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,20 @@ class Multi extends \Magento\Bundle\Block\Catalog\Product\View\Type\Bundle\Optio
1717
* @var string
1818
*/
1919
protected $_template = 'catalog/product/view/type/bundle/option/multi.phtml';
20+
21+
/**
22+
* @inheritdoc
23+
*/
24+
protected function assignSelection(\Magento\Bundle\Model\Option $option, $selectionId)
25+
{
26+
if (is_array($selectionId)) {
27+
foreach ($selectionId as $id) {
28+
if ($id && $option->getSelectionById($id)) {
29+
$this->_selectedOptions[] = $id;
30+
}
31+
}
32+
} else {
33+
parent::assignSelection($option, $selectionId);
34+
}
35+
}
2036
}

app/code/Magento/Bundle/view/frontend/templates/catalog/product/view/type/bundle/options.phtml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
<?php
1212
$product = $block->getProduct();
1313
$helper = $this->helper('Magento\Catalog\Helper\Output');
14+
$stripSelection = $product->getConfigureMode() ? true : false;
15+
$options = $block->decorateArray($block->getOptions($stripSelection));
1416
?>
15-
<?php $options = $block->decorateArray($block->getOptions()); ?>
1617
<?php if ($product->isSaleable()):?>
1718
<?php if (count($options)): ?>
1819
<script type="text/x-magento-init">

dev/tests/functional/tests/app/Magento/Bundle/Test/Block/Catalog/Product/View/Type/Bundle.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,12 @@ protected function getSelectOptionsData(SimpleElement $element, $firstOption = 1
270270
$count = $firstOption;
271271
$selectOption = $element->find(sprintf($this->option, $count), Locator::SELECTOR_XPATH);
272272
while ($selectOption->isVisible()) {
273-
$listOptions[] = $this->parseOptionText($selectOption->getText());
273+
$option = $this->parseOptionText($selectOption->getText());
274+
$selected = $selectOption->getAttribute('selected');
275+
if ($selected) {
276+
$option['selected'] = $selected;
277+
}
278+
$listOptions[] = $option;
274279
++$count;
275280
$selectOption = $element->find(sprintf($this->option, $count), Locator::SELECTOR_XPATH);
276281
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Bundle\Test\Constraint;
8+
9+
use Magento\Bundle\Test\Fixture\BundleProduct;
10+
use Magento\Catalog\Test\Page\Product\CatalogProductView;
11+
use Magento\Checkout\Test\Fixture\Cart;
12+
use Magento\Checkout\Test\Page\CheckoutCart;
13+
use Magento\Mtf\Constraint\AbstractAssertForm;
14+
15+
/**
16+
* Assertion that bundle product is correctly displayed on cart configuration page.
17+
*/
18+
class AssertBundleProductOnConfigureCartPage extends AbstractAssertForm
19+
{
20+
/**
21+
* Check bundle product options correctly displayed on cart configuration page.
22+
*
23+
* @param CheckoutCart $checkoutCart
24+
* @param Cart $cart
25+
* @param CatalogProductView $catalogProductView
26+
* @return void
27+
*/
28+
public function processAssert(CheckoutCart $checkoutCart, Cart $cart, CatalogProductView $catalogProductView)
29+
{
30+
$checkoutCart->open();
31+
$sourceProducts = $cart->getDataFieldConfig('items')['source'];
32+
$products = $sourceProducts->getProducts();
33+
foreach ($cart->getItems() as $key => $item) {
34+
$product = $products[$key];
35+
$cartItem = $checkoutCart->getCartBlock()->getCartItem($product);
36+
$cartItem->edit();
37+
$formOptions = $catalogProductView->getBundleViewBlock()->getBundleBlock()->getOptions($product);
38+
$this->checkOptions($product, $formOptions, $item->getData()['options']);
39+
}
40+
}
41+
42+
/**
43+
* Returns a string representation of the object.
44+
*
45+
* @return string
46+
*/
47+
public function toString()
48+
{
49+
return 'Bundle options data on cart configuration page is correct.';
50+
}
51+
52+
/**
53+
* Compare bundle product options from fixture with product form.
54+
*
55+
* @param BundleProduct $product
56+
* @param array $formOptions
57+
* @param array $cartItemOptions
58+
* @return void
59+
*/
60+
private function checkOptions(BundleProduct $product, array $formOptions, array $cartItemOptions)
61+
{
62+
$productOptions = $this->prepareBundleOptions($product, $cartItemOptions);
63+
$productOptions = $this->sortDataByPath($productOptions, '::title');
64+
foreach ($productOptions as $key => $productOption) {
65+
$productOptions[$key] = $this->sortDataByPath($productOption, 'options::title');
66+
}
67+
$formOptions = $this->sortDataByPath($formOptions, '::title');
68+
foreach ($formOptions as $key => $formOption) {
69+
$formOptions[$key] = $this->sortDataByPath($formOption, 'options::title');
70+
}
71+
72+
$error = $this->verifyData($productOptions, $formOptions);
73+
\PHPUnit_Framework_Assert::assertEmpty($error, $error);
74+
}
75+
76+
/**
77+
* Prepare bundle options.
78+
*
79+
* @param BundleProduct $product
80+
* @param array $cartItemOptions
81+
* @return array
82+
*/
83+
private function prepareBundleOptions(BundleProduct $product, array $cartItemOptions)
84+
{
85+
$bundleSelections = $product->getBundleSelections();
86+
$bundleOptions = $bundleSelections['bundle_options'] ?? [];
87+
$result = [];
88+
foreach ($bundleOptions as $optionKey => $bundleOption) {
89+
$optionData = [
90+
'title' => $bundleOption['title'],
91+
'type' => $bundleOption['frontend_type'],
92+
'is_require' => $bundleOption['required'],
93+
];
94+
foreach ($bundleOption['assigned_products'] as $productKey => $assignedProduct) {
95+
$price = $assignedProduct['data']['selection_price_value']
96+
?? $bundleSelections['products'][$optionKey][$productKey]->getPrice();
97+
$title = $assignedProduct['search_data']['name'];
98+
$optionData['options'][$productKey] = [
99+
'title' => $title,
100+
'price' => number_format($price, 2),
101+
];
102+
foreach ($cartItemOptions as $option) {
103+
if (strpos($option['value'], $title)) {
104+
$optionData['options'][$productKey]['selected'] = true;
105+
}
106+
}
107+
}
108+
$result[$optionKey] = $optionData;
109+
}
110+
111+
return $result;
112+
}
113+
}

dev/tests/functional/tests/app/Magento/Bundle/Test/Repository/BundleProduct.xml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,5 +478,43 @@
478478
<item name="dataset" xsi:type="string">default_with_one_simple_product_and_custom_option</item>
479479
</field>
480480
</dataset>
481+
482+
<dataset name="bundle_with_multiselect_option_one_selection">
483+
<field name="name" xsi:type="string">Bundle with multiselect option %isolation%</field>
484+
<field name="url_key" xsi:type="string">bundle-with-multiselect-option-%isolation%</field>
485+
<field name="sku" xsi:type="string">sku_bundle_with_multiselect_option_%isolation%</field>
486+
<field name="sku_type" xsi:type="string">Yes</field>
487+
<field name="price_type" xsi:type="string">Yes</field>
488+
<field name="website_ids" xsi:type="array">
489+
<item name="0" xsi:type="array">
490+
<item name="dataset" xsi:type="string">default</item>
491+
</item>
492+
</field>
493+
<field name="bundle_selections" xsi:type="array">
494+
<item name="dataset" xsi:type="string">multiselect_option</item>
495+
</field>
496+
<field name="checkout_data" xsi:type="array">
497+
<item name="dataset" xsi:type="string">bundle_multiselect_one_option</item>
498+
</field>
499+
</dataset>
500+
501+
<dataset name="bundle_with_multiselect_option_two_selections">
502+
<field name="name" xsi:type="string">Bundle with multiselect option %isolation%</field>
503+
<field name="url_key" xsi:type="string">bundle-with-multiselect-option-%isolation%</field>
504+
<field name="sku" xsi:type="string">sku_bundle_with_multiselect_option_%isolation%</field>
505+
<field name="sku_type" xsi:type="string">Yes</field>
506+
<field name="price_type" xsi:type="string">Yes</field>
507+
<field name="website_ids" xsi:type="array">
508+
<item name="0" xsi:type="array">
509+
<item name="dataset" xsi:type="string">default</item>
510+
</item>
511+
</field>
512+
<field name="bundle_selections" xsi:type="array">
513+
<item name="dataset" xsi:type="string">multiselect_option</item>
514+
</field>
515+
<field name="checkout_data" xsi:type="array">
516+
<item name="dataset" xsi:type="string">bundle_multiselect_two_options</item>
517+
</field>
518+
</dataset>
481519
</repository>
482520
</config>

dev/tests/functional/tests/app/Magento/Bundle/Test/Repository/BundleProduct/BundleSelections.xml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,5 +1066,44 @@
10661066
</item>
10671067
</field>
10681068
</dataset>
1069+
1070+
<dataset name="multiselect_option">
1071+
<field name="bundle_options" xsi:type="array">
1072+
<item name="0" xsi:type="array">
1073+
<item name="title" xsi:type="string">Multiple Select Option</item>
1074+
<item name="type" xsi:type="string">Multiple Select</item>
1075+
<item name="frontend_type" xsi:type="string">Multiple Select</item>
1076+
<item name="required" xsi:type="string">Yes</item>
1077+
<item name="assigned_products" xsi:type="array">
1078+
<item name="0" xsi:type="array">
1079+
<item name="search_data" xsi:type="array">
1080+
<item name="name" xsi:type="string">%product_name%</item>
1081+
</item>
1082+
<item name="data" xsi:type="array">
1083+
<item name="selection_price_value" xsi:type="string">560.00</item>
1084+
<item name="selection_price_type" xsi:type="string">Fixed</item>
1085+
<item name="selection_qty" xsi:type="string">1</item>
1086+
</item>
1087+
</item>
1088+
<item name="1" xsi:type="array">
1089+
<item name="search_data" xsi:type="array">
1090+
<item name="name" xsi:type="string">%product_name%</item>
1091+
</item>
1092+
<item name="data" xsi:type="array">
1093+
<item name="selection_price_value" xsi:type="string">100.00</item>
1094+
<item name="selection_price_type" xsi:type="string">Fixed</item>
1095+
<item name="selection_qty" xsi:type="string">1</item>
1096+
</item>
1097+
</item>
1098+
</item>
1099+
</item>
1100+
</field>
1101+
<field name="products" xsi:type="array">
1102+
<item name="0" xsi:type="array">
1103+
<item name="0" xsi:type="string">catalogProductSimple::default</item>
1104+
<item name="1" xsi:type="string">catalogProductSimple::product_100_dollar</item>
1105+
</item>
1106+
</field>
1107+
</dataset>
10691108
</repository>
10701109
</config>

dev/tests/functional/tests/app/Magento/Bundle/Test/Repository/BundleProduct/CheckoutData.xml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,5 +462,53 @@
462462
</item>
463463
</field>
464464
</dataset>
465+
466+
<dataset name="bundle_multiselect_one_option">
467+
<field name="options" xsi:type="array">
468+
<item name="bundle_options" xsi:type="array">
469+
<item name="0" xsi:type="array">
470+
<item name="title" xsi:type="string">Multiple Select Option</item>
471+
<item name="type" xsi:type="string">Multiple Select</item>
472+
<item name="frontend_type" xsi:type="string">Multiple</item>
473+
<item name="value" xsi:type="array">
474+
<item name="name" xsi:type="string">product_100_dollar</item>
475+
</item>
476+
</item>
477+
</item>
478+
</field>
479+
<field name="cartItem" xsi:type="array">
480+
<item name="price" xsi:type="string">100</item>
481+
<item name="qty" xsi:type="string">1</item>
482+
<item name="subtotal" xsi:type="string">100</item>
483+
</field>
484+
</dataset>
485+
486+
<dataset name="bundle_multiselect_two_options">
487+
<field name="options" xsi:type="array">
488+
<item name="bundle_options" xsi:type="array">
489+
<item name="0" xsi:type="array">
490+
<item name="title" xsi:type="string">Multiple Select Option</item>
491+
<item name="type" xsi:type="string">Multiple Select</item>
492+
<item name="frontend_type" xsi:type="string">Multiple</item>
493+
<item name="value" xsi:type="array">
494+
<item name="name" xsi:type="string">Simple Product</item>
495+
</item>
496+
</item>
497+
<item name="1" xsi:type="array">
498+
<item name="title" xsi:type="string">Multiple Select Option</item>
499+
<item name="type" xsi:type="string">Multiple Select</item>
500+
<item name="frontend_type" xsi:type="string">Multiple</item>
501+
<item name="value" xsi:type="array">
502+
<item name="name" xsi:type="string">product_100_dollar</item>
503+
</item>
504+
</item>
505+
</item>
506+
</field>
507+
<field name="cartItem" xsi:type="array">
508+
<item name="price" xsi:type="string">660</item>
509+
<item name="qty" xsi:type="string">1</item>
510+
<item name="subtotal" xsi:type="string">660</item>
511+
</field>
512+
</dataset>
465513
</repository>
466514
</config>

dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Cart/CartItem.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class CartItem extends AbstractCartItem
1919
*
2020
* @var string
2121
*/
22-
protected $edit = '.action.edit';
22+
protected $edit = '.action-edit';
2323

2424
/**
2525
* Selector for "Remove item" button

dev/tests/functional/tests/app/Magento/Checkout/Test/TestCase/AddProductsToShoppingCartEntityTest.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,5 +264,29 @@
264264
<data name="isValidationFailed" xsi:type="boolean">true</data>
265265
<constraint name="Magento\Checkout\Test\Constraint\AssertCartItemsOptions" />
266266
</variation>
267+
<variation name="AddProductsToShoppingCartEntityTestVariation13" summary="Check Bundle on Cart Configuration Page." ticketId="MAGETWO-71634">
268+
<data name="productsData/0" xsi:type="string">bundleProduct::bundle_with_multiselect_option_one_selection</data>
269+
<data name="cart/data/grand_total" xsi:type="string">105</data>
270+
<data name="cart/data/subtotal" xsi:type="string">100</data>
271+
<data name="expectedItemsQty" xsi:type="number">1</data>
272+
<constraint name="Magento\Bundle\Test\Constraint\AssertBundleProductOnConfigureCartPage" />
273+
<constraint name="Magento\Checkout\Test\Constraint\AssertPriceInShoppingCart" />
274+
<constraint name="Magento\Checkout\Test\Constraint\AssertProductQtyInShoppingCart" />
275+
<constraint name="Magento\Checkout\Test\Constraint\AssertSubtotalInShoppingCart" />
276+
<constraint name="Magento\Checkout\Test\Constraint\AssertCartItemsOptions" />
277+
<constraint name="Magento\Checkout\Test\Constraint\AssertGrandTotalInShoppingCart" />
278+
</variation>
279+
<variation name="AddProductsToShoppingCartEntityTestVariation14" summary="Check Bundle on Cart Configuration Page." ticketId="MAGETWO-71634">
280+
<data name="productsData/0" xsi:type="string">bundleProduct::bundle_with_multiselect_option_two_selections</data>
281+
<data name="cart/data/grand_total" xsi:type="string">665</data>
282+
<data name="cart/data/subtotal" xsi:type="string">660</data>
283+
<data name="expectedItemsQty" xsi:type="number">1</data>
284+
<constraint name="Magento\Bundle\Test\Constraint\AssertBundleProductOnConfigureCartPage" />
285+
<constraint name="Magento\Checkout\Test\Constraint\AssertPriceInShoppingCart" />
286+
<constraint name="Magento\Checkout\Test\Constraint\AssertProductQtyInShoppingCart" />
287+
<constraint name="Magento\Checkout\Test\Constraint\AssertSubtotalInShoppingCart" />
288+
<constraint name="Magento\Checkout\Test\Constraint\AssertCartItemsOptions" />
289+
<constraint name="Magento\Checkout\Test\Constraint\AssertGrandTotalInShoppingCart" />
290+
</variation>
267291
</testCase>
268292
</config>

0 commit comments

Comments
 (0)