Skip to content

Commit

Permalink
Merge pull request #1517 from magento-tsg/2.1-develop-pr30
Browse files Browse the repository at this point in the history
[TSG] Backporting for 2.1 (pr30) (2.1.10)
  • Loading branch information
vzabaznov authored Sep 27, 2017
2 parents de49e22 + cd82114 commit cf24001
Show file tree
Hide file tree
Showing 32 changed files with 1,393 additions and 388 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function getValue()
$value = $product->getData('final_price') * ($selectionPriceValue / 100);
} else {
// calculate price for selection type fixed
$value = $this->priceCurrency->convert($selectionPriceValue) * $this->quantity;
$value = $this->priceCurrency->convert($selectionPriceValue);
}
}
if (!$this->useRegularPrice) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,63 +66,58 @@ class BundleSelectionPriceTest extends \PHPUnit_Framework_TestCase
*/
protected $priceCurrencyMock;

/**
* @var float
*/
protected $quantity;

/**
* Test setUp
*/
protected function setUp()
{
$this->productMock = $this->getMock(
'Magento\Catalog\Model\Product',
\Magento\Catalog\Model\Product::class,
['__wakeup', 'getPriceInfo', 'getSelectionPriceType', 'getSelectionPriceValue'],
[],
'',
false
);

$this->bundleMock = $this->getMock(
'Magento\Catalog\Model\Product',
\Magento\Catalog\Model\Product::class,
['__wakeup', 'getPriceType', 'getPriceInfo', 'setFinalPrice', 'getData'],
[],
'',
false
);
$this->calculatorMock = $this->getMockBuilder('Magento\Framework\Pricing\Adjustment\CalculatorInterface')
$this->calculatorMock = $this->getMockBuilder(\Magento\Framework\Pricing\Adjustment\CalculatorInterface::class)
->getMockForAbstractClass();
$this->eventManagerMock = $this->getMock(
'Magento\Framework\Event\Manager',
\Magento\Framework\Event\Manager::class,
['dispatch'],
[],
'',
false
);
$this->priceInfoMock = $this->getMock(
'Magento\Framework\Pricing\PriceInfo\Base',
\Magento\Framework\Pricing\PriceInfo\Base::class,
['getPrice'],
[],
'',
false
);
$this->discountCalculatorMock = $this->getMock(
'Magento\Bundle\Pricing\Price\DiscountCalculator',
\Magento\Bundle\Pricing\Price\DiscountCalculator::class,
[],
[],
'',
false
);
$this->finalPriceMock = $this->getMock(
'Magento\Catalog\Pricing\Price\FinalPrice',
\Magento\Catalog\Pricing\Price\FinalPrice::class,
[],
[],
'',
false
);
$this->regularPriceMock = $this->getMock(
'Magento\Catalog\Pricing\Price\RegularPrice',
\Magento\Catalog\Pricing\Price\RegularPrice::class,
[],
[],
'',
Expand All @@ -132,18 +127,16 @@ protected function setUp()
->method('getPriceInfo')
->will($this->returnValue($this->priceInfoMock));

$this->priceCurrencyMock = $this->getMock('\Magento\Framework\Pricing\PriceCurrencyInterface');

$this->quantity = 1;
$this->priceCurrencyMock = $this->getMock(\Magento\Framework\Pricing\PriceCurrencyInterface::class);

$this->setupSelectionPrice();
}

protected function setupSelectionPrice($useRegularPrice = false)
protected function setupSelectionPrice($useRegularPrice = false, $qty = 1)
{
$this->selectionPrice = new \Magento\Bundle\Pricing\Price\BundleSelectionPrice(
$this->productMock,
$this->quantity,
$qty,
$this->calculatorMock,
$this->priceCurrencyMock,
$this->bundleMock,
Expand Down Expand Up @@ -313,6 +306,58 @@ public function testGetValueTypeFixedWithoutSelectionPriceType($useRegularPrice)
$this->assertEquals($expectedPrice, $this->selectionPrice->getValue());
}

/**
* Test for method getValue with type Fixed and selectionPriceType is empty or zero.
*
* @param bool $useRegularPrice
* @return void
*
* @dataProvider useRegularPriceDataProvider
*/
public function testFixedPriceWithMultipleQty($useRegularPrice)
{
$qty = 2;

$this->setupSelectionPrice($useRegularPrice, $qty);
$regularPrice = 100.125;
$discountedPrice = 70.453;
$convertedValue = 100.247;
$actualPrice = $useRegularPrice ? $convertedValue : $discountedPrice;
$expectedPrice = $useRegularPrice ? round($convertedValue, 2) : round($discountedPrice, 2);

$this->bundleMock->expects($this->once())
->method('getPriceType')
->will($this->returnValue(\Magento\Bundle\Model\Product\Price::PRICE_TYPE_FIXED));
$this->productMock->expects($this->once())
->method('getSelectionPriceType')
->will($this->returnValue(false));
$this->productMock->expects($this->any())
->method('getSelectionPriceValue')
->will($this->returnValue($regularPrice));

$this->priceCurrencyMock->expects($this->once())
->method('convert')
->with($regularPrice)
->will($this->returnValue($convertedValue));

if (!$useRegularPrice) {
$this->discountCalculatorMock->expects($this->once())
->method('calculateDiscount')
->with(
$this->equalTo($this->bundleMock),
$this->equalTo($convertedValue)
)
->will($this->returnValue($discountedPrice));
}

$this->priceCurrencyMock->expects($this->once())
->method('round')
->with($actualPrice)
->will($this->returnValue($expectedPrice));

$this->assertEquals($expectedPrice, $this->selectionPrice->getValue());
}

public function useRegularPriceDataProvider()
{
return [
Expand Down
1 change: 0 additions & 1 deletion app/code/Magento/Bundle/view/base/web/js/price-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ define([
this._setOption('priceFormat', priceBox.priceBox('option').priceConfig.priceFormat);
priceBox.priceBox('setDefault', this.options.optionConfig.prices);
}
this._applyQtyFix();
this._applyOptionNodeFix(options);

options.on('change', this._onBundleOptionChanged.bind(this));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,16 @@ public function __construct(
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
$this->request = $request;
$this->collection = $collectionFactory->create();
$this->collection->setExcludeSetFilter((int)$this->request->getParam('template_id', 0));
}

/**
* {@inheritdoc}
*/
public function getData()
{
$this->collection->setExcludeSetFilter((int)$this->request->getParam('template_id', 0));
$this->collection->getSelect()->setPart('order', []);

$items = [];
foreach ($this->getCollection()->getItems() as $attribute) {
$items[] = $attribute->toArray();
Expand Down
Loading

0 comments on commit cf24001

Please sign in to comment.