Skip to content

Commit ff253a7

Browse files
author
Volodymyr Klymenko
authored
Merge pull request #1116 from magento-tsg/2.1.8-develop-pr11
[TSG] Backporting for 2.1 (pr11) (2.1.8)
2 parents 0acbc57 + 37028f0 commit ff253a7

File tree

67 files changed

+2313
-320
lines changed

Some content is hidden

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

67 files changed

+2313
-320
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Pricing\Price;
8+
9+
use Magento\Framework\Pricing\SaleableInterface;
10+
use Magento\Framework\Pricing\Amount\AmountInterface;
11+
12+
/**
13+
* Interface define methods which control display of "As low as" price.
14+
*/
15+
interface MinimalPriceCalculatorInterface
16+
{
17+
/**
18+
* Get raw value for "as low as" price.
19+
*
20+
* @param SaleableInterface $saleableItem
21+
* @return float|null
22+
*/
23+
public function getValue(SaleableInterface $saleableItem);
24+
25+
/**
26+
* Return structured object with "as low as" value.
27+
*
28+
* @param SaleableInterface $saleableItem
29+
* @return AmountInterface|null
30+
*/
31+
public function getAmount(SaleableInterface $saleableItem);
32+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Pricing\Price;
8+
9+
use Magento\Framework\Pricing\SaleableInterface;
10+
use Magento\Framework\Pricing\Adjustment\CalculatorInterface;
11+
use Magento\Framework\Pricing\Amount\AmountInterface;
12+
13+
/**
14+
* MinimalTierPriceCalculator shows minimal value of Tier Prices.
15+
*/
16+
class MinimalTierPriceCalculator implements MinimalPriceCalculatorInterface
17+
{
18+
/**
19+
* Price Calculator interface.
20+
*
21+
* @var CalculatorInterface
22+
*/
23+
private $calculator;
24+
25+
/**
26+
* @param CalculatorInterface $calculator
27+
*/
28+
public function __construct(CalculatorInterface $calculator)
29+
{
30+
$this->calculator = $calculator;
31+
}
32+
33+
/**
34+
* Get raw value of "as low as" as a minimal among tier prices.
35+
*
36+
* @param SaleableInterface $saleableItem
37+
* @return float|null
38+
*/
39+
public function getValue(SaleableInterface $saleableItem)
40+
{
41+
/** @var TierPrice $price */
42+
$price = $saleableItem->getPriceInfo()->getPrice(TierPrice::PRICE_CODE);
43+
$tierPriceList = $price->getTierPriceList();
44+
45+
$tierPrices = [];
46+
foreach ($tierPriceList as $tierPrice) {
47+
/** @var AmountInterface $price */
48+
$price = $tierPrice['price'];
49+
$tierPrices[] = $price->getValue();
50+
}
51+
52+
return $tierPrices ? min($tierPrices) : null;
53+
}
54+
55+
/**
56+
* Return calculated amount object that keeps "as low as" value.
57+
*
58+
* @param SaleableInterface $saleableItem
59+
* @return AmountInterface|null
60+
*/
61+
public function getAmount(SaleableInterface $saleableItem)
62+
{
63+
$value = $this->getValue($saleableItem);
64+
65+
return $value === null ? null : $this->calculator->getAmount($value, $saleableItem);
66+
}
67+
}

app/code/Magento/Catalog/Pricing/Render/FinalPriceBox.php

Lines changed: 57 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,52 +8,61 @@
88

99
use Magento\Catalog\Pricing\Price;
1010
use Magento\Framework\App\ObjectManager;
11-
use Magento\Framework\Module\Manager;
12-
use Magento\Framework\Pricing\Render;
1311
use Magento\Framework\Pricing\Render\PriceBox as BasePriceBox;
14-
use Magento\Msrp\Pricing\Price\MsrpPrice;
15-
use Magento\Catalog\Model\Product\Pricing\Renderer\SalableResolverInterface;
16-
use Magento\Framework\View\Element\Template\Context;
1712
use Magento\Framework\Pricing\SaleableInterface;
1813
use Magento\Framework\Pricing\Price\PriceInterface;
1914
use Magento\Framework\Pricing\Render\RendererPool;
15+
use Magento\Msrp\Pricing\Price\MsrpPrice;
16+
use Magento\Framework\View\Element\Template\Context;
2017

2118
/**
22-
* Class for final_price rendering
19+
* Class for final_price rendering.
2320
*
2421
* @method bool getUseLinkForAsLowAs()
2522
* @method bool getDisplayMinimalPrice()
26-
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2723
*/
2824
class FinalPriceBox extends BasePriceBox
2925
{
3026
/**
31-
* @var SalableResolverInterface
27+
* Interface resolver provided to check is product available for sale.
28+
*
29+
* @var \Magento\Catalog\Model\Product\Pricing\Renderer\SalableResolverInterface
3230
*/
3331
private $salableResolver;
3432

35-
/** @var Manager */
33+
/**
34+
* Module statuses manager.
35+
*
36+
* @var \Magento\Framework\Module\Manager
37+
*/
3638
private $moduleManager;
3739

40+
/**
41+
* Shows minimal value of Tier Prices.
42+
*
43+
* @var \Magento\Catalog\Pricing\Price\MinimalPriceCalculatorInterface
44+
*/
45+
private $minimalPriceCalculator;
46+
3847
/**
3948
* @param Context $context
4049
* @param SaleableInterface $saleableItem
4150
* @param PriceInterface $price
4251
* @param RendererPool $rendererPool
4352
* @param array $data
44-
* @param SalableResolverInterface $salableResolver
53+
* @param \Magento\Catalog\Model\Product\Pricing\Renderer\SalableResolverInterface $salableResolver
4554
*/
4655
public function __construct(
4756
Context $context,
4857
SaleableInterface $saleableItem,
4958
PriceInterface $price,
5059
RendererPool $rendererPool,
5160
array $data = [],
52-
SalableResolverInterface $salableResolver = null
61+
\Magento\Catalog\Model\Product\Pricing\Renderer\SalableResolverInterface $salableResolver = null
5362
) {
5463
parent::__construct($context, $saleableItem, $price, $rendererPool, $data);
55-
$this->salableResolver = $salableResolver ?: \Magento\Framework\App\ObjectManager::getInstance()
56-
->get(SalableResolverInterface::class);
64+
$this->salableResolver = $salableResolver ?: ObjectManager::getInstance()
65+
->get(\Magento\Catalog\Model\Product\Pricing\Renderer\SalableResolverInterface::class);
5766
}
5867

5968
/**
@@ -116,7 +125,7 @@ private function isMsrpPriceApplicable()
116125
}
117126

118127
/**
119-
* Wrap with standard required container
128+
* Wrap with standard required container.
120129
*
121130
* @param string $html
122131
* @return string
@@ -130,17 +139,21 @@ protected function wrapResult($html)
130139
}
131140

132141
/**
133-
* Render minimal amount
142+
* Render minimal amount.
134143
*
135144
* @return string
136145
*/
137146
public function renderAmountMinimal()
138147
{
139-
/** @var \Magento\Catalog\Pricing\Price\FinalPrice $price */
140-
$price = $this->getPriceType(\Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE);
141148
$id = $this->getPriceId() ? $this->getPriceId() : 'product-minimal-price-' . $this->getSaleableItem()->getId();
149+
$amount = $this->getMinimalPriceCalculator()->getAmount($this->getSaleableItem());
150+
151+
if ($amount === null) {
152+
return '';
153+
}
154+
142155
return $this->renderAmount(
143-
$price->getMinimalPrice(),
156+
$amount,
144157
[
145158
'display_label' => __('As low as'),
146159
'price_id' => $id,
@@ -151,7 +164,7 @@ public function renderAmountMinimal()
151164
}
152165

153166
/**
154-
* Define if the special price should be shown
167+
* Define if the special price should be shown.
155168
*
156169
* @return bool
157170
*/
@@ -163,23 +176,25 @@ public function hasSpecialPrice()
163176
}
164177

165178
/**
166-
* Define if the minimal price should be shown
179+
* Define if the minimal price should be shown.
167180
*
168181
* @return bool
169182
*/
170183
public function showMinimalPrice()
171184
{
185+
$minTierPrice = $this->getMinimalPriceCalculator()->getValue($this->getSaleableItem());
186+
172187
/** @var Price\FinalPrice $finalPrice */
173188
$finalPrice = $this->getPriceType(Price\FinalPrice::PRICE_CODE);
174189
$finalPriceValue = $finalPrice->getAmount()->getValue();
175-
$minimalPriceAValue = $finalPrice->getMinimalPrice()->getValue();
190+
176191
return $this->getDisplayMinimalPrice()
177-
&& $minimalPriceAValue
178-
&& $minimalPriceAValue < $finalPriceValue;
192+
&& $minTierPrice !== null
193+
&& $minTierPrice < $finalPriceValue;
179194
}
180195

181196
/**
182-
* Get Key for caching block content
197+
* Get Key for caching block content.
183198
*
184199
* @return string
185200
*/
@@ -203,19 +218,19 @@ public function getCacheKeyInfo()
203218

204219
/**
205220
* @deprecated
206-
* @return Manager
221+
* @return \Magento\Framework\Module\Manager
207222
*/
208223
private function getModuleManager()
209224
{
210225
if ($this->moduleManager === null) {
211-
$this->moduleManager = ObjectManager::getInstance()->get(Manager::class);
226+
$this->moduleManager = ObjectManager::getInstance()->get(\Magento\Framework\Module\Manager::class);
212227
}
213228
return $this->moduleManager;
214229
}
215230

216231
/**
217-
* Get flag that price rendering should be done for the list of products
218-
* By default (if flag is not set) is false
232+
* Get flag that price rendering should be done for the list of products.
233+
* By default (if flag is not set) is false.
219234
*
220235
* @return bool
221236
*/
@@ -224,4 +239,18 @@ public function isProductList()
224239
$isProductList = $this->getData('is_product_list');
225240
return $isProductList === true;
226241
}
242+
243+
/**
244+
* @deprecated
245+
* @return \Magento\Catalog\Pricing\Price\MinimalPriceCalculatorInterface
246+
*/
247+
private function getMinimalPriceCalculator()
248+
{
249+
if ($this->minimalPriceCalculator == null) {
250+
$this->minimalPriceCalculator = ObjectManager::getInstance()
251+
->get(\Magento\Catalog\Pricing\Price\MinimalPriceCalculatorInterface::class);
252+
}
253+
254+
return $this->minimalPriceCalculator;
255+
}
227256
}

0 commit comments

Comments
 (0)