-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1116 from magento-tsg/2.1.8-develop-pr11
[TSG] Backporting for 2.1 (pr11) (2.1.8)
- Loading branch information
Showing
67 changed files
with
2,313 additions
and
320 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
app/code/Magento/Catalog/Pricing/Price/MinimalPriceCalculatorInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
/** | ||
* Copyright © 2013-2017 Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Catalog\Pricing\Price; | ||
|
||
use Magento\Framework\Pricing\SaleableInterface; | ||
use Magento\Framework\Pricing\Amount\AmountInterface; | ||
|
||
/** | ||
* Interface define methods which control display of "As low as" price. | ||
*/ | ||
interface MinimalPriceCalculatorInterface | ||
{ | ||
/** | ||
* Get raw value for "as low as" price. | ||
* | ||
* @param SaleableInterface $saleableItem | ||
* @return float|null | ||
*/ | ||
public function getValue(SaleableInterface $saleableItem); | ||
|
||
/** | ||
* Return structured object with "as low as" value. | ||
* | ||
* @param SaleableInterface $saleableItem | ||
* @return AmountInterface|null | ||
*/ | ||
public function getAmount(SaleableInterface $saleableItem); | ||
} |
67 changes: 67 additions & 0 deletions
67
app/code/Magento/Catalog/Pricing/Price/MinimalTierPriceCalculator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
/** | ||
* Copyright © 2013-2017 Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Catalog\Pricing\Price; | ||
|
||
use Magento\Framework\Pricing\SaleableInterface; | ||
use Magento\Framework\Pricing\Adjustment\CalculatorInterface; | ||
use Magento\Framework\Pricing\Amount\AmountInterface; | ||
|
||
/** | ||
* MinimalTierPriceCalculator shows minimal value of Tier Prices. | ||
*/ | ||
class MinimalTierPriceCalculator implements MinimalPriceCalculatorInterface | ||
{ | ||
/** | ||
* Price Calculator interface. | ||
* | ||
* @var CalculatorInterface | ||
*/ | ||
private $calculator; | ||
|
||
/** | ||
* @param CalculatorInterface $calculator | ||
*/ | ||
public function __construct(CalculatorInterface $calculator) | ||
{ | ||
$this->calculator = $calculator; | ||
} | ||
|
||
/** | ||
* Get raw value of "as low as" as a minimal among tier prices. | ||
* | ||
* @param SaleableInterface $saleableItem | ||
* @return float|null | ||
*/ | ||
public function getValue(SaleableInterface $saleableItem) | ||
{ | ||
/** @var TierPrice $price */ | ||
$price = $saleableItem->getPriceInfo()->getPrice(TierPrice::PRICE_CODE); | ||
$tierPriceList = $price->getTierPriceList(); | ||
|
||
$tierPrices = []; | ||
foreach ($tierPriceList as $tierPrice) { | ||
/** @var AmountInterface $price */ | ||
$price = $tierPrice['price']; | ||
$tierPrices[] = $price->getValue(); | ||
} | ||
|
||
return $tierPrices ? min($tierPrices) : null; | ||
} | ||
|
||
/** | ||
* Return calculated amount object that keeps "as low as" value. | ||
* | ||
* @param SaleableInterface $saleableItem | ||
* @return AmountInterface|null | ||
*/ | ||
public function getAmount(SaleableInterface $saleableItem) | ||
{ | ||
$value = $this->getValue($saleableItem); | ||
|
||
return $value === null ? null : $this->calculator->getAmount($value, $saleableItem); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.