Skip to content

Commit 143cfb0

Browse files
committed
MAGETWO-70540: Edit bundle product from shopping cart work unexpected
1 parent ee3811d commit 143cfb0

File tree

4 files changed

+27
-93
lines changed

4 files changed

+27
-93
lines changed

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

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,10 @@ public function addToCart(BundleProduct $product, CatalogProductView $catalogPro
115115
* Get product options
116116
*
117117
* @param FixtureInterface $product
118-
* @param bool $showSelected
119118
* @return array
120119
* @throws \Exception
121120
*/
122-
public function getOptions(FixtureInterface $product, bool $showSelected = false)
121+
public function getOptions(FixtureInterface $product)
123122
{
124123
/** @var BundleProduct $product */
125124
$this->product = $product;
@@ -140,9 +139,7 @@ public function getOptions(FixtureInterface $product, bool $showSelected = false
140139
$optionElement = $listFormOptions[$title];
141140
$getTypeData = 'get' . $this->optionNameConvert($option['frontend_type']) . 'Data';
142141

143-
$optionData = $showSelected
144-
? $this->$getTypeData($optionElement, $showSelected)
145-
: $this->$getTypeData($optionElement);
142+
$optionData = $this->$getTypeData($optionElement);
146143
$optionData['title'] = $title;
147144
$optionData['type'] = $option['frontend_type'];
148145
$optionData['is_require'] = $optionElement->find($this->required, Locator::SELECTOR_XPATH)->isVisible()
@@ -206,13 +203,12 @@ protected function getDropdownData(SimpleElement $option)
206203
* Get data of "Multiple select" option
207204
*
208205
* @param SimpleElement $option
209-
* @param bool $showSelected
210206
* @return array
211207
*/
212-
protected function getMultipleselectData(SimpleElement $option, bool $showSelected = false)
208+
protected function getMultipleselectData(SimpleElement $option)
213209
{
214210
$multiselect = $option->find($this->selectOption, Locator::SELECTOR_XPATH, 'multiselect');
215-
$data = $this->getSelectOptionsData($multiselect, 1, $showSelected);
211+
$data = $this->getSelectOptionsData($multiselect, 1);
216212

217213
foreach ($data['options'] as $key => $option) {
218214
$option['title'] = trim(preg_replace('/^[\d]+ x/', '', $option['title']));
@@ -265,24 +261,21 @@ protected function getCheckboxData(SimpleElement $option)
265261
*
266262
* @param SimpleElement $element
267263
* @param int $firstOption
268-
* @param bool $showSelected
269264
* @return array
270265
*/
271-
protected function getSelectOptionsData(SimpleElement $element, $firstOption = 1, bool $showSelected = false)
266+
protected function getSelectOptionsData(SimpleElement $element, $firstOption = 1)
272267
{
273268
$listOptions = [];
274269

275270
$count = $firstOption;
276271
$selectOption = $element->find(sprintf($this->option, $count), Locator::SELECTOR_XPATH);
277272
while ($selectOption->isVisible()) {
278-
if ($showSelected) {
279-
$listOptions[] = $this->parseOptionText(
280-
$selectOption->getText(),
281-
$selectOption->getAttribute('selected')
282-
);
283-
} else {
284-
$listOptions[] = $this->parseOptionText($selectOption->getText());
273+
$option = $this->parseOptionText($selectOption->getText());
274+
$selected = $selectOption->getAttribute('selected');
275+
if ($selected) {
276+
$option['selected'] = $selected;
285277
}
278+
$listOptions[] = $option;
286279
++$count;
287280
$selectOption = $element->find(sprintf($this->option, $count), Locator::SELECTOR_XPATH);
288281
}
@@ -294,10 +287,9 @@ protected function getSelectOptionsData(SimpleElement $element, $firstOption = 1
294287
* Parse option text to title, price and optionally add selected attribute value.
295288
*
296289
* @param string $optionText
297-
* @param string|null $selected
298290
* @return array
299291
*/
300-
protected function parseOptionText($optionText, $selected = null)
292+
protected function parseOptionText($optionText)
301293
{
302294
preg_match('`^(.*?)\+ ?\$(\d.*?)$`sim', $optionText, $match);
303295
$optionPrice = isset($match[2]) ? str_replace(',', '', $match[2]) : 0;
@@ -306,9 +298,6 @@ protected function parseOptionText($optionText, $selected = null)
306298
'title' => $optionTitle,
307299
'price' => $optionPrice
308300
];
309-
if ($selected) {
310-
$option['selected'] = true;
311-
}
312301

313302
return $option;
314303
}

dev/tests/functional/tests/app/Magento/Bundle/Test/Constraint/AssertBundleProductOnConfigureCartPage.php

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
namespace Magento\Bundle\Test\Constraint;
88

99
use Magento\Bundle\Test\Fixture\BundleProduct;
10+
use Magento\Catalog\Test\Page\Product\CatalogProductView;
1011
use Magento\Checkout\Test\Fixture\Cart;
1112
use Magento\Checkout\Test\Page\CheckoutCart;
12-
use Magento\Checkout\Test\Page\CheckoutCartConfigure;
1313
use Magento\Mtf\Constraint\AbstractAssertForm;
1414

1515
/**
@@ -22,10 +22,10 @@ class AssertBundleProductOnConfigureCartPage extends AbstractAssertForm
2222
*
2323
* @param CheckoutCart $checkoutCart
2424
* @param Cart $cart
25-
* @param CheckoutCartConfigure $checkoutCartConfigure
25+
* @param CatalogProductView $catalogProductView
2626
* @return void
2727
*/
28-
public function processAssert(CheckoutCart $checkoutCart, Cart $cart, CheckoutCartConfigure $checkoutCartConfigure)
28+
public function processAssert(CheckoutCart $checkoutCart, Cart $cart, CatalogProductView $catalogProductView)
2929
{
3030
$checkoutCart->open();
3131
$sourceProducts = $cart->getDataFieldConfig('items')['source'];
@@ -34,8 +34,8 @@ public function processAssert(CheckoutCart $checkoutCart, Cart $cart, CheckoutCa
3434
$product = $products[$key];
3535
$cartItem = $checkoutCart->getCartBlock()->getCartItem($product);
3636
$cartItem->edit();
37-
$options = $checkoutCartConfigure->getBundleViewBlock()->getBundleBlock()->getOptions($product, true);
38-
$this->checkOptions($product, $options, $item->getData()['options']);
37+
$formOptions = $catalogProductView->getBundleViewBlock()->getBundleBlock()->getOptions($product);
38+
$this->checkOptions($product, $formOptions, $item->getData()['options']);
3939
}
4040
}
4141

@@ -83,29 +83,25 @@ private function checkOptions(BundleProduct $product, array $formOptions, array
8383
private function prepareBundleOptions(BundleProduct $product, array $cartItemOptions)
8484
{
8585
$bundleSelections = $product->getBundleSelections();
86-
$bundleOptions = isset($bundleSelections['bundle_options']) ? $bundleSelections['bundle_options'] : [];
86+
$bundleOptions = $bundleSelections['bundle_options'] ?? [];
8787
$result = [];
8888
foreach ($bundleOptions as $optionKey => $bundleOption) {
8989
$optionData = [
9090
'title' => $bundleOption['title'],
9191
'type' => $bundleOption['frontend_type'],
9292
'is_require' => $bundleOption['required'],
9393
];
94-
$key = 0;
9594
foreach ($bundleOption['assigned_products'] as $productKey => $assignedProduct) {
96-
if ($this->isInStock($product, $key++)) {
97-
$price = isset($assignedProduct['data']['selection_price_value'])
98-
? $assignedProduct['data']['selection_price_value']
99-
: $bundleSelections['products'][$optionKey][$productKey]->getPrice();
100-
$title = $assignedProduct['search_data']['name'];
101-
$optionData['options'][$productKey] = [
102-
'title' => $title,
103-
'price' => number_format($price, 2),
104-
];
105-
foreach ($cartItemOptions as $option) {
106-
if (strpos($option['value'], $title)) {
107-
$optionData['options'][$productKey]['selected'] = true;
108-
}
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;
109105
}
110106
}
111107
}
@@ -114,19 +110,4 @@ private function prepareBundleOptions(BundleProduct $product, array $cartItemOpt
114110

115111
return $result;
116112
}
117-
118-
/**
119-
* Check product is in stock.
120-
*
121-
* @param BundleProduct $product
122-
* @param int $key
123-
* @return bool
124-
*/
125-
private function isInStock(BundleProduct $product, int $key)
126-
{
127-
$assignedProducts = $product->getBundleSelections()['products'][0];
128-
$status = $assignedProducts[$key]->getData()['quantity_and_stock_status']['is_in_stock'];
129-
130-
return $status === 'In Stock';
131-
}
132113
}

dev/tests/functional/tests/app/Magento/Bundle/Test/Page/Checkout/CheckoutCartConfigure.xml

Lines changed: 0 additions & 15 deletions
This file was deleted.

dev/tests/functional/tests/app/Magento/Checkout/Test/Page/CheckoutCartConfigure.xml

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)