Skip to content

Commit cf24001

Browse files
authored
Merge pull request #1517 from magento-tsg/2.1-develop-pr30
[TSG] Backporting for 2.1 (pr30) (2.1.10)
2 parents de49e22 + cd82114 commit cf24001

File tree

32 files changed

+1393
-388
lines changed

32 files changed

+1393
-388
lines changed

app/code/Magento/Bundle/Pricing/Price/BundleSelectionPrice.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public function getValue()
124124
$value = $product->getData('final_price') * ($selectionPriceValue / 100);
125125
} else {
126126
// calculate price for selection type fixed
127-
$value = $this->priceCurrency->convert($selectionPriceValue) * $this->quantity;
127+
$value = $this->priceCurrency->convert($selectionPriceValue);
128128
}
129129
}
130130
if (!$this->useRegularPrice) {

app/code/Magento/Bundle/Test/Unit/Pricing/Price/BundleSelectionPriceTest.php

+63-18
Original file line numberDiff line numberDiff line change
@@ -66,63 +66,58 @@ class BundleSelectionPriceTest extends \PHPUnit_Framework_TestCase
6666
*/
6767
protected $priceCurrencyMock;
6868

69-
/**
70-
* @var float
71-
*/
72-
protected $quantity;
73-
7469
/**
7570
* Test setUp
7671
*/
7772
protected function setUp()
7873
{
7974
$this->productMock = $this->getMock(
80-
'Magento\Catalog\Model\Product',
75+
\Magento\Catalog\Model\Product::class,
8176
['__wakeup', 'getPriceInfo', 'getSelectionPriceType', 'getSelectionPriceValue'],
8277
[],
8378
'',
8479
false
8580
);
8681

8782
$this->bundleMock = $this->getMock(
88-
'Magento\Catalog\Model\Product',
83+
\Magento\Catalog\Model\Product::class,
8984
['__wakeup', 'getPriceType', 'getPriceInfo', 'setFinalPrice', 'getData'],
9085
[],
9186
'',
9287
false
9388
);
94-
$this->calculatorMock = $this->getMockBuilder('Magento\Framework\Pricing\Adjustment\CalculatorInterface')
89+
$this->calculatorMock = $this->getMockBuilder(\Magento\Framework\Pricing\Adjustment\CalculatorInterface::class)
9590
->getMockForAbstractClass();
9691
$this->eventManagerMock = $this->getMock(
97-
'Magento\Framework\Event\Manager',
92+
\Magento\Framework\Event\Manager::class,
9893
['dispatch'],
9994
[],
10095
'',
10196
false
10297
);
10398
$this->priceInfoMock = $this->getMock(
104-
'Magento\Framework\Pricing\PriceInfo\Base',
99+
\Magento\Framework\Pricing\PriceInfo\Base::class,
105100
['getPrice'],
106101
[],
107102
'',
108103
false
109104
);
110105
$this->discountCalculatorMock = $this->getMock(
111-
'Magento\Bundle\Pricing\Price\DiscountCalculator',
106+
\Magento\Bundle\Pricing\Price\DiscountCalculator::class,
112107
[],
113108
[],
114109
'',
115110
false
116111
);
117112
$this->finalPriceMock = $this->getMock(
118-
'Magento\Catalog\Pricing\Price\FinalPrice',
113+
\Magento\Catalog\Pricing\Price\FinalPrice::class,
119114
[],
120115
[],
121116
'',
122117
false
123118
);
124119
$this->regularPriceMock = $this->getMock(
125-
'Magento\Catalog\Pricing\Price\RegularPrice',
120+
\Magento\Catalog\Pricing\Price\RegularPrice::class,
126121
[],
127122
[],
128123
'',
@@ -132,18 +127,16 @@ protected function setUp()
132127
->method('getPriceInfo')
133128
->will($this->returnValue($this->priceInfoMock));
134129

135-
$this->priceCurrencyMock = $this->getMock('\Magento\Framework\Pricing\PriceCurrencyInterface');
136-
137-
$this->quantity = 1;
130+
$this->priceCurrencyMock = $this->getMock(\Magento\Framework\Pricing\PriceCurrencyInterface::class);
138131

139132
$this->setupSelectionPrice();
140133
}
141134

142-
protected function setupSelectionPrice($useRegularPrice = false)
135+
protected function setupSelectionPrice($useRegularPrice = false, $qty = 1)
143136
{
144137
$this->selectionPrice = new \Magento\Bundle\Pricing\Price\BundleSelectionPrice(
145138
$this->productMock,
146-
$this->quantity,
139+
$qty,
147140
$this->calculatorMock,
148141
$this->priceCurrencyMock,
149142
$this->bundleMock,
@@ -313,6 +306,58 @@ public function testGetValueTypeFixedWithoutSelectionPriceType($useRegularPrice)
313306
$this->assertEquals($expectedPrice, $this->selectionPrice->getValue());
314307
}
315308

309+
/**
310+
* Test for method getValue with type Fixed and selectionPriceType is empty or zero.
311+
*
312+
* @param bool $useRegularPrice
313+
* @return void
314+
*
315+
* @dataProvider useRegularPriceDataProvider
316+
*/
317+
public function testFixedPriceWithMultipleQty($useRegularPrice)
318+
{
319+
$qty = 2;
320+
321+
$this->setupSelectionPrice($useRegularPrice, $qty);
322+
$regularPrice = 100.125;
323+
$discountedPrice = 70.453;
324+
$convertedValue = 100.247;
325+
$actualPrice = $useRegularPrice ? $convertedValue : $discountedPrice;
326+
$expectedPrice = $useRegularPrice ? round($convertedValue, 2) : round($discountedPrice, 2);
327+
328+
$this->bundleMock->expects($this->once())
329+
->method('getPriceType')
330+
->will($this->returnValue(\Magento\Bundle\Model\Product\Price::PRICE_TYPE_FIXED));
331+
$this->productMock->expects($this->once())
332+
->method('getSelectionPriceType')
333+
->will($this->returnValue(false));
334+
$this->productMock->expects($this->any())
335+
->method('getSelectionPriceValue')
336+
->will($this->returnValue($regularPrice));
337+
338+
$this->priceCurrencyMock->expects($this->once())
339+
->method('convert')
340+
->with($regularPrice)
341+
->will($this->returnValue($convertedValue));
342+
343+
if (!$useRegularPrice) {
344+
$this->discountCalculatorMock->expects($this->once())
345+
->method('calculateDiscount')
346+
->with(
347+
$this->equalTo($this->bundleMock),
348+
$this->equalTo($convertedValue)
349+
)
350+
->will($this->returnValue($discountedPrice));
351+
}
352+
353+
$this->priceCurrencyMock->expects($this->once())
354+
->method('round')
355+
->with($actualPrice)
356+
->will($this->returnValue($expectedPrice));
357+
358+
$this->assertEquals($expectedPrice, $this->selectionPrice->getValue());
359+
}
360+
316361
public function useRegularPriceDataProvider()
317362
{
318363
return [

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

-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ define([
5555
this._setOption('priceFormat', priceBox.priceBox('option').priceConfig.priceFormat);
5656
priceBox.priceBox('setDefault', this.options.optionConfig.prices);
5757
}
58-
this._applyQtyFix();
5958
this._applyOptionNodeFix(options);
6059

6160
options.on('change', this._onBundleOptionChanged.bind(this));

app/code/Magento/Catalog/Ui/DataProvider/Product/Attributes/Listing.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,16 @@ public function __construct(
4141
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
4242
$this->request = $request;
4343
$this->collection = $collectionFactory->create();
44-
$this->collection->setExcludeSetFilter((int)$this->request->getParam('template_id', 0));
4544
}
4645

4746
/**
4847
* {@inheritdoc}
4948
*/
5049
public function getData()
5150
{
51+
$this->collection->setExcludeSetFilter((int)$this->request->getParam('template_id', 0));
52+
$this->collection->getSelect()->setPart('order', []);
53+
5254
$items = [];
5355
foreach ($this->getCollection()->getItems() as $attribute) {
5456
$items[] = $attribute->toArray();

0 commit comments

Comments
 (0)