Skip to content

Commit c0123f3

Browse files
author
Sergii Kovalenko
committed
MAGETWO-56062: [Github #3890] Recently Viewed Products block does not appear when FPC is enabled
--fix health index
1 parent bab4284 commit c0123f3

File tree

216 files changed

+12860
-56
lines changed

Some content is hidden

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

216 files changed

+12860
-56
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: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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+
class BundlePrice implements ProductRenderCollectorInterface
21+
{
22+
const PRODUCT_TYPE = "bundle";
23+
24+
/**
25+
* @var PriceCurrencyInterface
26+
*/
27+
private $priceCurrency;
28+
29+
/**
30+
* @var array
31+
*/
32+
private $excludeAdjustments;
33+
34+
/**
35+
* @var PriceInfoInterfaceFactory
36+
*/
37+
private $priceInfoFactory;
38+
39+
/**
40+
* @var FormattedPriceInfoBuilder
41+
*/
42+
private $formattedPriceInfoBuilder;
43+
44+
/**
45+
* BundlePrice constructor.
46+
* @param PriceCurrencyInterface $priceCurrency
47+
* @param PriceInfoInterfaceFactory $priceInfoFactory
48+
* @param FormattedPriceInfoBuilder $formattedPriceInfoBuilder
49+
* @param array $excludeAdjustments
50+
*/
51+
public function __construct(
52+
PriceCurrencyInterface $priceCurrency,
53+
PriceInfoInterfaceFactory $priceInfoFactory,
54+
FormattedPriceInfoBuilder $formattedPriceInfoBuilder,
55+
array $excludeAdjustments = []
56+
) {
57+
$this->priceCurrency = $priceCurrency;
58+
$this->excludeAdjustments = $excludeAdjustments;
59+
$this->priceInfoFactory = $priceInfoFactory;
60+
$this->formattedPriceInfoBuilder = $formattedPriceInfoBuilder;
61+
}
62+
63+
/**
64+
* @inheritdoc
65+
*/
66+
public function collect(ProductInterface $product, ProductRenderInterface $productRender)
67+
{
68+
if ($product->getTypeId() == self::PRODUCT_TYPE) {
69+
$priceInfo = $productRender->getPriceInfo();
70+
71+
if (!$productRender->getPriceInfo()) {
72+
/** @var PriceInfoInterface $priceInfo */
73+
$priceInfo = $this->priceInfoFactory->create();
74+
}
75+
76+
$priceInfo->setMaxPrice(
77+
$product
78+
->getPriceInfo()
79+
->getPrice('final_price')
80+
->getMaximalPrice()
81+
->getValue()
82+
);
83+
84+
$priceInfo->setMaxRegularPrice(
85+
$product
86+
->getPriceInfo()
87+
->getPrice('regular_price')
88+
->getMaximalPrice()
89+
->getValue()
90+
);
91+
92+
$priceInfo->setMinimalPrice(
93+
$product
94+
->getPriceInfo()
95+
->getPrice('final_price')
96+
->getMinimalPrice()
97+
->getValue()
98+
);
99+
100+
$priceInfo->setMinimalRegularPrice(
101+
$product
102+
->getPriceInfo()
103+
->getPrice('regular_price')
104+
->getMinimalPrice()
105+
->getValue()
106+
);
107+
$this->formattedPriceInfoBuilder->build(
108+
$priceInfo,
109+
$productRender->getStoreId(),
110+
$productRender->getCurrencyCode()
111+
);
112+
113+
$productRender->setPriceInfo($priceInfo);
114+
}
115+
}
116+
}

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: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!--
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
-->
7+
<span class="price-container"
8+
css="getAdjustmentCssClasses($row())">
9+
<span if="label"
10+
class="price-label"
11+
text="label"/>
12+
13+
<span class="price-wrapper"
14+
css="priceWrapperCssClasses"
15+
attr="priceWrapperAttr"
16+
data-price-amount=""
17+
data-price-type=""
18+
html="getMinimalPrice($row())"/>
19+
20+
<each args="data: getAdjustments(), as: '$adj'">
21+
<render args="$adj.getBody()"/>
22+
</each>
23+
</span>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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>
23+
<item name="max_price" xsi:type="array">
24+
<item name="label" xsi:type="string" translate="true">To</item>
25+
<item name="showMaximumPrice" xsi:type="string">true</item>
26+
</item>
27+
</item>
28+
</item>
29+
</item>
30+
</item>
31+
</item>
32+
</argument>
33+
</column>
34+
</columns>
35+
</listing>

0 commit comments

Comments
 (0)