forked from magento/magento2
-
Notifications
You must be signed in to change notification settings - Fork 0
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 magento#3856 from magento-arcticfoxes/2.3.1-qwerty-pr
[2.3.1-qwerty] Sync with 2.3.1-release
- Loading branch information
Showing
27 changed files
with
451 additions
and
55 deletions.
There are no files selected for viewing
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
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
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
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
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,64 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Magento\Msrp\Pricing; | ||
|
||
use Magento\Catalog\Api\Data\ProductInterface; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
class MsrpPriceCalculator implements MsrpPriceCalculatorInterface | ||
{ | ||
/** | ||
* @var MsrpPriceCalculatorInterface[] | ||
*/ | ||
private $msrpPriceCalculators; | ||
|
||
/** | ||
* @param array $msrpPriceCalculators | ||
*/ | ||
public function __construct(array $msrpPriceCalculators) | ||
{ | ||
$this->msrpPriceCalculators = $this->getMsrpPriceCalculators($msrpPriceCalculators); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getMsrpPriceValue(ProductInterface $product): float | ||
{ | ||
$productType = $product->getTypeId(); | ||
if (isset($this->msrpPriceCalculators[$productType])) { | ||
$priceCalculator = $this->msrpPriceCalculators[$productType]; | ||
$msrp = $priceCalculator->getMsrpPriceValue($product); | ||
} else { | ||
$msrp = (float)$product->getMsrp(); | ||
} | ||
|
||
return $msrp; | ||
} | ||
|
||
/** | ||
* Convert the configuration of MSRP price calculators. | ||
* | ||
* @param array $msrpPriceCalculatorsConfig | ||
* @return array | ||
*/ | ||
private function getMsrpPriceCalculators(array $msrpPriceCalculatorsConfig): array | ||
{ | ||
$msrpPriceCalculators = []; | ||
foreach ($msrpPriceCalculatorsConfig as $msrpPriceCalculator) { | ||
if (isset($msrpPriceCalculator['productType'], $msrpPriceCalculator['priceCalculator'])) { | ||
$msrpPriceCalculators[$msrpPriceCalculator['productType']] = | ||
$msrpPriceCalculator['priceCalculator']; | ||
} | ||
} | ||
return $msrpPriceCalculators; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
app/code/Magento/Msrp/Pricing/MsrpPriceCalculatorInterface.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,23 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Msrp\Pricing; | ||
|
||
use Magento\Catalog\Api\Data\ProductInterface; | ||
|
||
/** | ||
* Provide information about MSRP price of a product. | ||
*/ | ||
interface MsrpPriceCalculatorInterface | ||
{ | ||
/** | ||
* Return the value of MSRP product price. | ||
* | ||
* @param ProductInterface $product | ||
* @return float | ||
*/ | ||
public function getMsrpPriceValue(ProductInterface $product): float; | ||
} |
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,62 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Magento\Msrp\Pricing\Render; | ||
|
||
use Magento\Catalog\Model\Product; | ||
use Magento\Framework\Json\Helper\Data; | ||
use Magento\Framework\Math\Random; | ||
use Magento\Framework\Pricing\Price\PriceInterface; | ||
use Magento\Framework\Pricing\Render\RendererPool; | ||
use Magento\Framework\View\Element\Template\Context; | ||
use Magento\Msrp\Pricing\MsrpPriceCalculatorInterface; | ||
|
||
/** | ||
* MSRP price box render. | ||
*/ | ||
class PriceBox extends \Magento\Catalog\Pricing\Render\PriceBox | ||
{ | ||
/** | ||
* @var MsrpPriceCalculatorInterface | ||
*/ | ||
private $msrpPriceCalculator; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param Context $context | ||
* @param Product $saleableItem | ||
* @param PriceInterface $price | ||
* @param RendererPool $rendererPool | ||
* @param Data $jsonHelper | ||
* @param Random $mathRandom | ||
* @param MsrpPriceCalculatorInterface $msrpPriceCalculator | ||
*/ | ||
public function __construct( | ||
Context $context, | ||
Product $saleableItem, | ||
PriceInterface $price, | ||
RendererPool $rendererPool, | ||
Data $jsonHelper, | ||
Random $mathRandom, | ||
MsrpPriceCalculatorInterface $msrpPriceCalculator | ||
) { | ||
$this->msrpPriceCalculator = $msrpPriceCalculator; | ||
parent::__construct($context, $saleableItem, $price, $rendererPool, $jsonHelper, $mathRandom); | ||
} | ||
|
||
/** | ||
* Return MSRP price calculator. | ||
* | ||
* @return MsrpPriceCalculatorInterface | ||
*/ | ||
public function getMsrpPriceCalculator(): MsrpPriceCalculatorInterface | ||
{ | ||
return $this->msrpPriceCalculator; | ||
} | ||
} |
Oops, something went wrong.