Skip to content

Commit 163f0fc

Browse files
author
Sergey Semenov
committed
Merge remote-tracking branch 'origin/MAGETWO-52067' into BUGS
2 parents 5738510 + 1157ccd commit 163f0fc

File tree

20 files changed

+679
-42
lines changed

20 files changed

+679
-42
lines changed

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,20 @@ public function __construct(
4343
}
4444

4545
/**
46-
* Get Price Amount object
47-
*
48-
* @return AmountInterface
46+
* @inheritdoc
4947
*/
5048
public function getAmount()
5149
{
52-
if (null === $this->amount) {
50+
if (!isset($this->amount[$this->getValue()])) {
5351
$price = $this->getValue();
5452
if ($this->product->getPriceType() == Price::PRICE_TYPE_FIXED) {
5553
/** @var \Magento\Catalog\Pricing\Price\CustomOptionPrice $customOptionPrice */
5654
$customOptionPrice = $this->priceInfo->getPrice(CustomOptionPrice::PRICE_CODE);
5755
$price += $customOptionPrice->getCustomOptionRange(true);
5856
}
59-
$this->amount = $this->calculator->getMinRegularAmount($price, $this->product);
57+
$this->amount[$this->getValue()] = $this->calculator->getMinRegularAmount($price, $this->product);
6058
}
61-
return $this->amount;
59+
return $this->amount[$this->getValue()];
6260
}
6361

6462
/**

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,18 @@ public function getValue()
142142
*/
143143
public function getAmount()
144144
{
145-
if (null === $this->amount) {
145+
if (!isset($this->amount[$this->getValue()])) {
146146
$exclude = null;
147147
if ($this->getProduct()->getTypeId() == \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE) {
148148
$exclude = $this->excludeAdjustment;
149149
}
150-
$this->amount = $this->calculator->getAmount($this->getValue(), $this->getProduct(), $exclude);
150+
$this->amount[$this->getValue()] = $this->calculator->getAmount(
151+
$this->getValue(),
152+
$this->getProduct(),
153+
$exclude
154+
);
151155
}
152-
return $this->amount;
156+
return $this->amount[$this->getValue()];
153157
}
154158

155159
/**

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

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,8 @@ protected function setUp()
9191
'',
9292
false
9393
);
94-
$this->calculatorMock = $this->getMock(
95-
'Magento\Framework\Pricing\Adjustment\CalculatorInterface',
96-
[],
97-
[],
98-
'',
99-
false,
100-
true,
101-
false
102-
);
94+
$this->calculatorMock = $this->getMockBuilder('Magento\Framework\Pricing\Adjustment\CalculatorInterface')
95+
->getMockForAbstractClass();
10396
$this->eventManagerMock = $this->getMock(
10497
'Magento\Framework\Event\Manager',
10598
['dispatch'],
@@ -349,4 +342,42 @@ public function testGetProductDynamicBundle()
349342
$product = $this->selectionPrice->getProduct();
350343
$this->assertEquals($this->productMock, $product);
351344
}
345+
346+
public function testGetAmount()
347+
{
348+
$this->setupSelectionPrice();
349+
350+
$price = 10.;
351+
$amount = 20.;
352+
353+
$this->priceInfoMock->expects($this->once())
354+
->method('getPrice')
355+
->with(\Magento\Bundle\Pricing\Price\FinalPrice::PRICE_CODE)
356+
->willReturn($this->finalPriceMock);
357+
358+
$this->finalPriceMock->expects($this->once())
359+
->method('getValue')
360+
->willReturn($price);
361+
362+
$this->discountCalculatorMock->expects($this->once())
363+
->method('calculateDiscount')
364+
->with($this->bundleMock, $price)
365+
->willReturn($price);
366+
367+
$this->priceCurrencyMock->expects($this->once())
368+
->method('round')
369+
->with($price)
370+
->willReturn($price);
371+
372+
$this->bundleMock->expects($this->any())
373+
->method('getPriceType')
374+
->willReturn(\Magento\Bundle\Model\Product\Price::PRICE_TYPE_DYNAMIC);
375+
376+
$this->calculatorMock->expects($this->once())
377+
->method('getAmount')
378+
->with($price, $this->productMock, null)
379+
->willReturn($amount);
380+
381+
$this->assertEquals($amount, $this->selectionPrice->getAmount());
382+
}
352383
}

app/code/Magento/Catalog/Test/Unit/Pricing/Price/BasePriceTest.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class BasePriceTest extends \PHPUnit_Framework_TestCase
2929
protected $saleableItemMock;
3030

3131
/**
32-
* @var \Magento\Framework\Pricing\Adjustment\Calculator
32+
* @var \Magento\Framework\Pricing\Adjustment\Calculator|\PHPUnit_Framework_MockObject_MockObject
3333
*/
3434
protected $calculatorMock;
3535

@@ -111,4 +111,23 @@ public function getValueDataProvider()
111111
{
112112
return [[77, 77], [0, 0], [false, 99]];
113113
}
114+
115+
public function testGetAmount()
116+
{
117+
$amount = 20.;
118+
119+
$priceMock = $this->getMockBuilder('Magento\Framework\Pricing\Price\PriceInterface')
120+
->getMockForAbstractClass();
121+
122+
$this->priceInfoMock->expects($this->once())
123+
->method('getPrices')
124+
->willReturn([$priceMock]);
125+
126+
$this->calculatorMock->expects($this->once())
127+
->method('getAmount')
128+
->with(false, $this->saleableItemMock)
129+
->willReturn($amount);
130+
131+
$this->assertEquals($amount, $this->basePrice->getAmount());
132+
}
114133
}

app/code/Magento/GroupedProduct/Pricing/Price/ConfiguredPrice.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,6 @@ public function setItem(ItemInterface $item)
3434
return $this;
3535
}
3636

37-
/**
38-
* Get Price Amount object
39-
*
40-
* @return AmountInterface
41-
*/
42-
public function getAmount()
43-
{
44-
// Reset amount
45-
$this->amount = null;
46-
return parent::getAmount();
47-
}
48-
4937
/**
5038
* Calculate configured price
5139
*

app/code/Magento/GroupedProduct/Test/Unit/Pricing/Price/ConfiguredPriceTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public function testGetAmount()
201201
{
202202
$resultPrice = rand(1, 9);
203203

204-
$this->price->expects($this->once())
204+
$this->price->expects($this->exactly(4))
205205
->method('getValue')
206206
->willReturn($resultPrice);
207207

app/code/Magento/Wishlist/CustomerData/Wishlist.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ protected function getItemData(\Magento\Wishlist\Model\Item $wishlistItem)
126126
'product_name' => $product->getName(),
127127
'product_price' => $this->block->getProductPriceHtml(
128128
$product,
129-
\Magento\Catalog\Pricing\Price\ConfiguredPriceInterface::CONFIGURED_PRICE_CODE,
129+
'wishlist_configured_price',
130130
\Magento\Framework\Pricing\Render::ZONE_ITEM_LIST,
131131
['item' => $wishlistItem]
132132
),

app/code/Magento/Wishlist/Model/Rss/Wishlist.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ public function getProductPriceHtml(\Magento\Catalog\Model\Product $product)
255255
}
256256
if ($priceRender) {
257257
$price = $priceRender->render(
258-
\Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE,
258+
'wishlist_configured_price',
259259
$product,
260260
['zone' => \Magento\Framework\Pricing\Render::ZONE_ITEM_LIST]
261261
);
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Wishlist\Pricing\ConfiguredPrice;
7+
8+
use Magento\Catalog\Model\Product\Configuration\Item\ItemInterface;
9+
use Magento\Catalog\Pricing\Price\ConfiguredPriceInterface;
10+
use Magento\Catalog\Pricing\Price\FinalPrice;
11+
12+
class ConfigurableProduct extends FinalPrice implements ConfiguredPriceInterface
13+
{
14+
/**
15+
* @var ItemInterface
16+
*/
17+
private $item;
18+
19+
/**
20+
* @inheritdoc
21+
*/
22+
public function getValue()
23+
{
24+
$result = 0.;
25+
/** @var \Magento\Wishlist\Model\Item\Option $customOption */
26+
$customOption = $this->getProduct()->getCustomOption('simple_product');
27+
if ($customOption) {
28+
/** @var \Magento\Framework\Pricing\PriceInfoInterface $priceInfo */
29+
$priceInfo = $customOption->getProduct()->getPriceInfo();
30+
$result = $priceInfo->getPrice(self::PRICE_CODE)->getValue();
31+
}
32+
return max(0, $result);
33+
}
34+
35+
/**
36+
* @inheritdoc
37+
*/
38+
public function setItem(ItemInterface $item)
39+
{
40+
$this->item = $item;
41+
return $this;
42+
}
43+
}
Lines changed: 75 additions & 0 deletions
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+
namespace Magento\Wishlist\Pricing\ConfiguredPrice;
7+
8+
use Magento\Catalog\Model\Product\Configuration\Item\ItemInterface;
9+
use Magento\Catalog\Pricing\Price\ConfiguredPriceInterface;
10+
use Magento\Catalog\Pricing\Price\FinalPrice;
11+
12+
class Downloadable extends FinalPrice implements ConfiguredPriceInterface
13+
{
14+
/**
15+
* Price type configured
16+
*/
17+
const PRICE_CODE = 'configured_price';
18+
19+
/**
20+
* @var ItemInterface
21+
*/
22+
private $item;
23+
24+
/**
25+
* @inheritdoc
26+
*/
27+
public function getValue()
28+
{
29+
return max(0, parent::getValue() + $this->getLinkPrice());
30+
}
31+
32+
/**
33+
* Retrieve calculated links price
34+
*
35+
* @return int
36+
*/
37+
private function getLinkPrice()
38+
{
39+
$result = 0;
40+
if ($this->getProduct()->getLinksPurchasedSeparately()) {
41+
/** @var \Magento\Wishlist\Model\Item\Option $customOption */
42+
$customOption = $this->getProduct()->getCustomOption('downloadable_link_ids');
43+
if ($customOption) {
44+
$links = $this->getLinks();
45+
$linkIds = explode(',', $customOption->getValue());
46+
foreach ($linkIds as $linkId) {
47+
if (isset($links[$linkId])) {
48+
$result += $links[$linkId]->getPrice();
49+
}
50+
}
51+
}
52+
}
53+
return $result;
54+
}
55+
56+
/**
57+
* @return \Magento\Downloadable\Model\Link[]
58+
*/
59+
private function getLinks()
60+
{
61+
/** @var \Magento\Downloadable\Model\Product\Type $productType */
62+
$productType = $this->getProduct()->getTypeInstance();
63+
$links = $productType->getLinks($this->getProduct());
64+
return $links;
65+
}
66+
67+
/**
68+
* @inheritdoc
69+
*/
70+
public function setItem(ItemInterface $item)
71+
{
72+
$this->item = $item;
73+
return $this;
74+
}
75+
}

0 commit comments

Comments
 (0)