Skip to content

Commit 44a242e

Browse files
authored
Merge pull request #1262 from magento-south/MAGETWO-56062
[South] MAGETWO-56062: [Github #3890] Recently Viewed Products block does not appear when FPC is enabled
2 parents 4994418 + b1ca469 commit 44a242e

File tree

240 files changed

+15210
-238
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

240 files changed

+15210
-238
lines changed
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Bundle\Test\Unit\Ui\DataProvider\Product\Listing\Collector;
7+
8+
use Magento\Bundle\Ui\DataProvider\Product\Listing\Collector\BundlePrice;
9+
use Magento\Catalog\Api\Data\ProductRender\PriceInfoInterface;
10+
use Magento\Catalog\Api\Data\ProductRender\PriceInfoInterfaceFactory;
11+
use Magento\Catalog\Api\Data\ProductRenderInterface;
12+
use Magento\Catalog\Model\Product;
13+
use Magento\Catalog\Model\ProductRender\FormattedPriceInfoBuilder;
14+
use Magento\Catalog\Pricing\Price\FinalPrice;
15+
use Magento\Framework\Pricing\Amount\AmountInterface;
16+
use Magento\Framework\Pricing\PriceCurrencyInterface;
17+
18+
class BundlePriceTest extends \PHPUnit_Framework_TestCase
19+
{
20+
/**
21+
* @var BundlePrice
22+
*/
23+
private $model;
24+
25+
/**
26+
* @var PriceCurrencyInterface|\PHPUnit_Framework_MockObject_MockObject
27+
*/
28+
private $priceCurrencyMock;
29+
30+
/**
31+
* @var PriceInfoInterfaceFactory|\PHPUnit_Framework_MockObject_MockObject
32+
*/
33+
private $priceInfoFactory;
34+
35+
/**
36+
* @var FormattedPriceInfoBuilder|\PHPUnit_Framework_MockObject_MockObject
37+
*/
38+
private $formattedPriceInfoBuilder;
39+
40+
public function setUp()
41+
{
42+
$this->priceCurrencyMock = $this->getMockBuilder(PriceCurrencyInterface::class)
43+
->getMockForAbstractClass();
44+
$this->priceInfoFactory = $this->getMockBuilder(PriceInfoInterfaceFactory::class)
45+
->disableOriginalConstructor()
46+
->setMethods(['create'])
47+
->getMock();
48+
$this->formattedPriceInfoBuilder = $this->getMockBuilder(FormattedPriceInfoBuilder::class)
49+
->disableOriginalConstructor()
50+
->getMock();
51+
52+
$this->model = new BundlePrice(
53+
$this->priceCurrencyMock,
54+
$this->priceInfoFactory,
55+
$this->formattedPriceInfoBuilder
56+
);
57+
}
58+
59+
public function testCollect()
60+
{
61+
$minAmountValue = 5;
62+
$amountValue = 10;
63+
$storeId = 1;
64+
$currencyCode = 'usd';
65+
66+
$productMock = $this->getMockBuilder(Product::class)
67+
->disableOriginalConstructor()
68+
->getMock();
69+
$price = $this->getMockBuilder(FinalPrice::class)
70+
->disableOriginalConstructor()
71+
->getMock();
72+
$productRender = $this->getMockBuilder(ProductRenderInterface::class)
73+
->disableOriginalConstructor()
74+
->getMock();
75+
$amount = $this->getMockBuilder(AmountInterface::class)
76+
->disableOriginalConstructor()
77+
->getMock();
78+
$minAmount = $this->getMockBuilder(AmountInterface::class)
79+
->disableOriginalConstructor()
80+
->getMock();
81+
$priceInfo = $this->getMockBuilder(PriceInfoInterface::class)
82+
->setMethods(
83+
[
84+
'getPrice',
85+
'setMaxPrice',
86+
'setMaxRegularPrice',
87+
'setMinimalPrice',
88+
'setMinimalRegularPrice'
89+
]
90+
)
91+
->getMockForAbstractClass();
92+
93+
$productMock->expects($this->once())
94+
->method('getTypeId')
95+
->willReturn('bundle');
96+
$productRender->expects($this->exactly(2))
97+
->method('getPriceInfo')
98+
->willReturn($priceInfo);
99+
$priceInfo->expects($this->once())
100+
->method('setMaxPrice')
101+
->with($amountValue);
102+
$priceInfo->expects($this->once())
103+
->method('setMaxRegularPrice')
104+
->with($amountValue);
105+
$priceInfo->expects($this->once())
106+
->method('setMinimalPrice')
107+
->with($minAmountValue);
108+
$priceInfo->expects($this->once())
109+
->method('setMinimalRegularPrice')
110+
->with($minAmountValue);
111+
$productMock->expects($this->exactly(4))
112+
->method('getPriceInfo')
113+
->willReturn($priceInfo);
114+
$productMock->expects($this->any())
115+
->method('getPriceInfo')
116+
->willReturn($priceInfo);
117+
$priceInfo->expects($this->exactly(4))
118+
->method('getPrice')
119+
->willReturn($price);
120+
$price->expects($this->exactly(2))
121+
->method('getMaximalPrice')
122+
->willReturn($amount);
123+
$price->expects($this->exactly(2))
124+
->method('getMinimalPrice')
125+
->willReturn($minAmount);
126+
$amount->expects($this->exactly(2))
127+
->method('getValue')
128+
->willReturn($amountValue);
129+
$minAmount->expects($this->exactly(2))
130+
->method('getValue')
131+
->willReturn($minAmountValue);
132+
133+
$productRender->expects($this->once())
134+
->method('getStoreId')
135+
->willReturn(1);
136+
$productRender->expects($this->once())
137+
->method('getCurrencyCode')
138+
->willReturn($currencyCode);
139+
140+
$this->formattedPriceInfoBuilder->expects($this->once())
141+
->method('build')
142+
->with($priceInfo, $storeId, $currencyCode);
143+
$productRender->expects($this->once())
144+
->method('setPriceInfo')
145+
->with($priceInfo);
146+
147+
$this->model->collect($productMock, $productRender);
148+
}
149+
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Bundle\Ui\DataProvider\Product\Listing\Collector;
8+
9+
use Magento\Catalog\Api\Data\ProductInterface;
10+
use Magento\Catalog\Api\Data\ProductRender\PriceInfoInterface;
11+
use Magento\Catalog\Api\Data\ProductRender\PriceInfoInterfaceFactory;
12+
use Magento\Catalog\Api\Data\ProductRenderInterface;
13+
use Magento\Catalog\Ui\DataProvider\Product\ProductRenderCollectorInterface;
14+
use Magento\Framework\Pricing\PriceCurrencyInterface;
15+
use Magento\Catalog\Model\ProductRender\FormattedPriceInfoBuilder;
16+
17+
/**
18+
* Collect information about bundle price
19+
*
20+
* This information can be used on front in order to render product list or product view
21+
* Price is collected always with VAT and fixed taxes
22+
*/
23+
class BundlePrice implements ProductRenderCollectorInterface
24+
{
25+
/**
26+
* Product type code
27+
*/
28+
const PRODUCT_TYPE = "bundle";
29+
30+
/**
31+
* @var PriceCurrencyInterface
32+
*/
33+
private $priceCurrency;
34+
35+
/**
36+
* @var array
37+
*/
38+
private $excludeAdjustments;
39+
40+
/**
41+
* @var PriceInfoInterfaceFactory
42+
*/
43+
private $priceInfoFactory;
44+
45+
/**
46+
* @var FormattedPriceInfoBuilder
47+
*/
48+
private $formattedPriceInfoBuilder;
49+
50+
/**
51+
* BundlePrice constructor.
52+
* @param PriceCurrencyInterface $priceCurrency
53+
* @param PriceInfoInterfaceFactory $priceInfoFactory
54+
* @param FormattedPriceInfoBuilder $formattedPriceInfoBuilder
55+
* @param array $excludeAdjustments
56+
*/
57+
public function __construct(
58+
PriceCurrencyInterface $priceCurrency,
59+
PriceInfoInterfaceFactory $priceInfoFactory,
60+
FormattedPriceInfoBuilder $formattedPriceInfoBuilder,
61+
array $excludeAdjustments = []
62+
) {
63+
$this->priceCurrency = $priceCurrency;
64+
$this->excludeAdjustments = $excludeAdjustments;
65+
$this->priceInfoFactory = $priceInfoFactory;
66+
$this->formattedPriceInfoBuilder = $formattedPriceInfoBuilder;
67+
}
68+
69+
/**
70+
* @inheritdoc
71+
*/
72+
public function collect(ProductInterface $product, ProductRenderInterface $productRender)
73+
{
74+
if ($product->getTypeId() == self::PRODUCT_TYPE) {
75+
$priceInfo = $productRender->getPriceInfo();
76+
77+
if (!$productRender->getPriceInfo()) {
78+
/** @var PriceInfoInterface $priceInfo */
79+
$priceInfo = $this->priceInfoFactory->create();
80+
}
81+
82+
$priceInfo->setMaxPrice(
83+
$product
84+
->getPriceInfo()
85+
->getPrice('final_price')
86+
->getMaximalPrice()
87+
->getValue()
88+
);
89+
90+
$priceInfo->setMaxRegularPrice(
91+
$product
92+
->getPriceInfo()
93+
->getPrice('regular_price')
94+
->getMaximalPrice()
95+
->getValue()
96+
);
97+
98+
$priceInfo->setMinimalPrice(
99+
$product
100+
->getPriceInfo()
101+
->getPrice('final_price')
102+
->getMinimalPrice()
103+
->getValue()
104+
);
105+
106+
$priceInfo->setMinimalRegularPrice(
107+
$product
108+
->getPriceInfo()
109+
->getPrice('regular_price')
110+
->getMinimalPrice()
111+
->getValue()
112+
);
113+
$this->formattedPriceInfoBuilder->build(
114+
$priceInfo,
115+
$productRender->getStoreId(),
116+
$productRender->getCurrencyCode()
117+
);
118+
119+
$productRender->setPriceInfo($priceInfo);
120+
}
121+
}
122+
}

app/code/Magento/Bundle/etc/di.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,21 @@
133133
</argument>
134134
</arguments>
135135
</type>
136+
<type name="Magento\Bundle\Ui\DataProvider\Product\Listing\Collector\BundlePrice">
137+
<arguments>
138+
<argument name="excludeAdjustments" xsi:type="array">
139+
<item name="weee" xsi:type="string">weee</item>
140+
<item name="weee_tax" xsi:type="string">weee_tax</item>
141+
</argument>
142+
</arguments>
143+
</type>
144+
<type name="Magento\Catalog\Ui\DataProvider\Product\ProductRenderCollectorComposite">
145+
<arguments>
146+
<argument name="productProviders" xsi:type="array">
147+
<item name="bundle_price" xsi:type="object">\Magento\Bundle\Ui\DataProvider\Product\Listing\Collector\BundlePrice</item>
148+
</argument>
149+
</arguments>
150+
</type>
136151
<type name="Magento\Catalog\Model\Product\Price\SpecialPriceStorage">
137152
<arguments>
138153
<argument name="allowedProductTypes" xsi:type="array">
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!--
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
-->
7+
<if args="hasPriceRange($row())">
8+
<div class="price-from">
9+
<with args="getPriceByCode('minimal_price')">
10+
<render args="getBody()" />
11+
</with>
12+
<with args="getPriceByCode('minimal_regular_price')">
13+
<render args="getBody()" />
14+
</with>
15+
</div>
16+
<div class="price-to">
17+
<with args="getPriceByCode('max_price')">
18+
<render args="getBody()" />
19+
</with>
20+
<with args="getPriceByCode('max_regular_price')">
21+
<render args="getBody()" />
22+
</with>
23+
</div>
24+
</if>
25+
26+
<ifnot args="hasPriceRange($row())">
27+
<with args="getPriceByCode('minimal_price')">
28+
<render args="getBody()" />
29+
</with>
30+
<with args="getPriceByCode('minimal_regular_price')">
31+
<render args="getBody()" />
32+
</with>
33+
</ifnot>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!--
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
-->
7+
<if args="getMinimalPriceAmount($row()) < getMaximumPriceAmount($row())">
8+
<span class="price-container"
9+
css="getAdjustmentCssClasses($row())">
10+
<span if="label"
11+
class="price-label"
12+
text="label"/>
13+
14+
<span class="price-wrapper"
15+
css="priceWrapperCssClasses"
16+
attr="priceWrapperAttr"
17+
data-price-amount=""
18+
data-price-type=""
19+
html="getMinimalPrice($row())"/>
20+
21+
<each args="data: getAdjustments(), as: '$adj'">
22+
<render args="$adj.getBody()"/>
23+
</each>
24+
</span>
25+
</if>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
9+
<columns name="widget_columns">
10+
<column name="price">
11+
<argument name="data" xsi:type="array">
12+
<item name="config" xsi:type="array">
13+
<item name="renders" xsi:type="array">
14+
<item name="prices" xsi:type="array">
15+
<item name="bundle" xsi:type="array">
16+
<item name="bodyTmpl" xsi:type="string">Magento_Bundle/product/final_price</item>
17+
<item name="children" xsi:type="array">
18+
<item name="minimal_price" xsi:type="array">
19+
<item name="label" xsi:type="string" translate="true">From</item>
20+
<item name="component" xsi:type="string">Magento_Catalog/js/product/list/columns/final-price</item>
21+
<item name="bodyTmpl" xsi:type="string">Magento_Bundle/product/price/minimal_price</item>
22+
<item name="sortOrder" xsi:type="number">1</item>
23+
</item>
24+
<item name="special_price" xsi:type="array">
25+
<item name="label" xsi:type="string" translate="true">Special Price</item>
26+
<item name="component" xsi:type="string">Magento_Catalog/js/product/list/columns/final-price</item>
27+
<item name="bodyTmpl" xsi:type="string">Magento_Catalog/product/price/special_price</item>
28+
<item name="sortOrder" xsi:type="number">2</item>
29+
</item>
30+
<item name="max_price" xsi:type="array">
31+
<item name="label" xsi:type="string" translate="true">To</item>
32+
<item name="showMaximumPrice" xsi:type="string">true</item>
33+
<item name="sortOrder" xsi:type="number">3</item>
34+
</item>
35+
</item>
36+
</item>
37+
</item>
38+
</item>
39+
</item>
40+
</argument>
41+
</column>
42+
</columns>
43+
</listing>

0 commit comments

Comments
 (0)