Skip to content

Commit 063f66f

Browse files
committed
MAGETWO-57009: [Backport] [GitHub] Bundle Products - The price calculation fails for user defined quantity #4446 - for 2.0
1 parent 4ac2029 commit 063f66f

File tree

18 files changed

+469
-20
lines changed

18 files changed

+469
-20
lines changed

app/code/Magento/Bundle/view/base/web/js/price-bundle.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@ define([
295295
case 'hidden':
296296
optionHash = 'bundle-option-' + optionName + '##' + optionValue;
297297
optionQty = optionConfig[optionValue].qty || 0;
298+
canQtyCustomize = optionConfig[optionValue].customQty === '1';
299+
qtyField = element.data('qtyField');
300+
qtyField.data('option', element);
301+
toggleQtyField(qtyField, optionQty, optionId, optionValue, canQtyCustomize);
298302
tempChanges = utils.deepClone(optionConfig[optionValue].prices);
299303
tempChanges = applyTierPrice(tempChanges, optionQty, optionConfig);
300304
tempChanges = applyQty(tempChanges, optionQty);

dev/tests/functional/tests/app/Magento/Bundle/Test/Block/Adminhtml/Catalog/Product/Edit/Tab/Bundle/Option/Selection.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,9 @@
2828
<getProductName>
2929
<selector>td.col-name</selector>
3030
</getProductName>
31+
<user_defined>
32+
<selector>[class$='is-user-defined-qty']</selector>
33+
<input>checkbox</input>
34+
</user_defined>
3135
</fields>
3236
</mapping>

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77
namespace Magento\Bundle\Test\Block\Catalog\Product;
88

99
use Magento\Bundle\Test\Block\Catalog\Product\View\Type\Bundle;
10-
use Magento\Bundle\Test\Fixture\BundleProduct;
10+
use Magento\Bundle\Test\Block\Catalog\Product\View\Summary;
1111
use Magento\Mtf\Client\Locator;
1212
use Magento\Mtf\Fixture\FixtureInterface;
13-
use Magento\Mtf\Fixture\InjectableFixture;
1413

1514
/**
1615
* Class View
@@ -46,6 +45,13 @@ class View extends \Magento\Catalog\Test\Block\Product\View
4645
*/
4746
protected $newsletterFormSelector = '#newsletter-validate-detail[novalidate="novalidate"]';
4847

48+
/**
49+
* Summary Block selector.
50+
*
51+
* @var string
52+
*/
53+
private $summaryBlockSelector = '#bundleSummary';
54+
4955
/**
5056
* Get bundle options block.
5157
*
@@ -59,6 +65,19 @@ public function getBundleBlock()
5965
);
6066
}
6167

68+
/**
69+
* Get bundle Summary block.
70+
*
71+
* @return Summary
72+
*/
73+
public function getBundleSummaryBlock()
74+
{
75+
return $this->blockFactory->create(
76+
Summary::class,
77+
['element' => $this->_rootElement->find($this->summaryBlockSelector)]
78+
);
79+
}
80+
6281
/**
6382
* Click "Customize and add to cart button".
6483
*
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Bundle\Test\Block\Catalog\Product\View;
8+
9+
use Magento\Bundle\Test\Block\Catalog\Product\View\Summary\ConfiguredPrice;
10+
use Magento\Catalog\Test\Block\Product\View;
11+
use Magento\Mtf\Client\ElementInterface;
12+
13+
/**
14+
* Bundle Summary block.
15+
*/
16+
class Summary extends View
17+
{
18+
/**
19+
* Configured Price block selector.
20+
*
21+
* @var string
22+
*/
23+
private $configuredPriceBlockSelector = '.price-configured_price';
24+
25+
/**
26+
* Get configured price block.
27+
*
28+
* @return ConfiguredPrice
29+
*/
30+
public function getConfiguredPriceBlock()
31+
{
32+
/** @var ElementInterface $element */
33+
$element = $this->_rootElement->find($this->configuredPriceBlockSelector);
34+
35+
return $this->blockFactory->create(
36+
ConfiguredPrice::class,
37+
['element' => $element]
38+
);
39+
}
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Bundle\Test\Block\Catalog\Product\View\Summary;
8+
9+
use Magento\Catalog\Test\Block\AbstractPriceBlock;
10+
11+
/**
12+
* This class is used to access the price related information from the storefront.
13+
*/
14+
class ConfiguredPrice extends AbstractPriceBlock
15+
{
16+
/**
17+
* Mapping for different type of price.
18+
*
19+
* @var array
20+
*/
21+
protected $mapTypePrices = [
22+
'configured_price' => [
23+
'selector' => '.price',
24+
]
25+
];
26+
27+
/**
28+
* This method returns the price represented by the block.
29+
*
30+
* @param string $currency
31+
* @return string|null
32+
*/
33+
public function getPrice($currency = '$')
34+
{
35+
return $this->getTypePrice('configured_price', $currency);
36+
}
37+
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ public function getOptions(FixtureInterface $product)
107107

108108
/** @var SimpleElement $optionElement */
109109
$optionElement = $listFormOptions[$title];
110-
$getTypeData = 'get' . $this->optionNameConvert($option['type']) . 'Data';
110+
$getTypeData = 'get' . $this->optionNameConvert($option['frontend_type']) . 'Data';
111111

112112
$optionData = $this->$getTypeData($optionElement);
113113
$optionData['title'] = $title;
114-
$optionData['type'] = $option['type'];
114+
$optionData['type'] = $option['frontend_type'];
115115
$optionData['is_require'] = $optionElement->find($this->required, Locator::SELECTOR_XPATH)->isVisible()
116116
? 'Yes'
117117
: 'No';
@@ -266,7 +266,7 @@ public function fillBundleOptions($bundleOptions)
266266
/** @var Option $optionBlock */
267267
$optionBlock = $this->blockFactory->create(
268268
'Magento\Bundle\Test\Block\Catalog\Product\View\Type\Option\\'
269-
. $this->optionNameConvert($option['type']),
269+
. $this->optionNameConvert($option['frontend_type']),
270270
['element' => $this->_rootElement->find($selector, Locator::SELECTOR_XPATH)]
271271
);
272272
$optionBlock->fillOption($option['value']);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Bundle\Test\Block\Catalog\Product\View\Type\Option\Element;
8+
9+
use Magento\Mtf\Client\Element\SimpleElement;
10+
11+
/**
12+
* Typified element class for qty element.
13+
*/
14+
class Qty extends SimpleElement
15+
{
16+
/**
17+
* "Backspace" key code.
18+
*/
19+
const BACKSPACE = "\xEE\x80\x83";
20+
21+
/**
22+
* "RIGHT" key code.
23+
*/
24+
const RIGHT = "\xEE\x80\x94";
25+
26+
/**
27+
* Set the value.
28+
*
29+
* @param string|array $value
30+
* @return void
31+
*/
32+
public function setValue($value)
33+
{
34+
$this->keys([self::RIGHT, self::BACKSPACE, $value]);
35+
$this->context->click();
36+
}
37+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Bundle\Test\Block\Catalog\Product\View\Type\Option;
8+
9+
use Magento\Bundle\Test\Block\Catalog\Product\View\Type\Option;
10+
11+
/**
12+
* Bundle option hidden type.
13+
*/
14+
class Hidden extends Option
15+
{
16+
//
17+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" ?>
2+
<!--
3+
/**
4+
* Copyright © 2016 Magento. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<mapping strict="1">
9+
<fields>
10+
<qty>
11+
<selector>//input[contains(@class,"qty")]</selector>
12+
<strategy>xpath</strategy>
13+
<class>Magento\Bundle\Test\Block\Catalog\Product\View\Type\Option\Element\Qty</class>
14+
</qty>
15+
</fields>
16+
</mapping>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ protected function prepareBundleOptions(BundleProduct $product)
6161
foreach ($bundleOptions as $optionKey => $bundleOption) {
6262
$optionData = [
6363
'title' => $bundleOption['title'],
64-
'type' => $bundleOption['type'],
64+
'type' => $bundleOption['frontend_type'],
6565
'is_require' => $bundleOption['required'],
6666
];
6767

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. 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\Catalog\Test\TestStep\ConfigureProductOnProductPageStep;
12+
use Magento\Mtf\Constraint\AbstractConstraint;
13+
use Magento\Mtf\TestStep\TestStepFactory;
14+
15+
/**
16+
* Assert calculated price after configure bundle product on product page.
17+
*/
18+
class AssertBundlePriceCalculatedOnProductPage extends AbstractConstraint
19+
{
20+
/**
21+
* Assert calculated price after configure bundle product on product page.
22+
*
23+
* @param TestStepFactory $stepFactory
24+
* @param BundleProduct $product
25+
* @param CatalogProductView $catalogProductView
26+
*/
27+
public function processAssert(
28+
TestStepFactory $stepFactory,
29+
BundleProduct $product,
30+
CatalogProductView $catalogProductView
31+
) {
32+
$stepFactory->create(
33+
ConfigureProductOnProductPageStep::class,
34+
['product' => $product]
35+
)->run();
36+
37+
//Process assertions
38+
$this->assertPrice($product, $catalogProductView);
39+
}
40+
41+
/**
42+
* Assert prices on the product view Page.
43+
*
44+
* @param BundleProduct $product
45+
* @param CatalogProductView $productView
46+
* @return void
47+
*/
48+
protected function assertPrice(
49+
BundleProduct $product,
50+
CatalogProductView $productView
51+
) {
52+
$checkoutData = $product->getCheckoutData();
53+
54+
$blockPrice = $productView->getBundleViewBlock()
55+
->getBundleSummaryBlock()
56+
->getConfiguredPriceBlock()
57+
->getPrice();
58+
59+
\PHPUnit_Framework_Assert::assertEquals(
60+
$checkoutData['cartItem']['configuredPrice'],
61+
$blockPrice,
62+
'Bundle price calculated is not correct.'
63+
);
64+
}
65+
66+
/**
67+
* Returns a string representation of the object.
68+
*
69+
* @return string
70+
*/
71+
public function toString()
72+
{
73+
return 'Bundle price calculates right on product view page.';
74+
}
75+
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
*/
1414
class AssertBundleProductForm extends AssertProductForm
1515
{
16+
/**
17+
* Skipped fields for verify data.
18+
*
19+
* @var array
20+
*/
21+
protected $skippedFields = ['frontend_type'];
22+
1623
/**
1724
* Formatting options for array values.
1825
*

dev/tests/functional/tests/app/Magento/Bundle/Test/Handler/BundleProduct/Curl.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ public function __construct(DataInterface $configuration, EventManagerInterface
6363
'selection_price_type' => [
6464
'Fixed' => 0,
6565
'Percent' => 1,
66+
],
67+
'user_defined' => [
68+
'Yes' => 1,
69+
'No' => 0
6670
]
6771
];
6872
}

0 commit comments

Comments
 (0)