From 5f2fe94e94eadc38a9042b5a12014a906df722db Mon Sep 17 00:00:00 2001 From: Stefan Teichmann Date: Mon, 17 Apr 2023 13:08:45 +0200 Subject: [PATCH 1/2] Respect currency-conversion in HistoricalPriceBox.php. Solves https://github.com/macopedia/magento2-omnibusdirective/issues/4 --- Pricing/Render/HistoricalPriceBox.php | 41 +++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/Pricing/Render/HistoricalPriceBox.php b/Pricing/Render/HistoricalPriceBox.php index 2d5912c..5983128 100644 --- a/Pricing/Render/HistoricalPriceBox.php +++ b/Pricing/Render/HistoricalPriceBox.php @@ -2,17 +2,54 @@ namespace Macopedia\OmnibusDirective\Pricing\Render; +use Magento\Catalog\Model\Product\Pricing\Renderer\SalableResolverInterface; use Magento\Catalog\Pricing\Price\FinalPrice; +use Magento\Catalog\Pricing\Price\MinimalPriceCalculatorInterface; use Magento\Catalog\Pricing\Render\FinalPriceBox; +use Magento\Framework\Pricing\Helper\Data; +use Magento\Framework\Pricing\Price\PriceInterface; +use Magento\Framework\Pricing\Render\RendererPool; +use Magento\Framework\Pricing\SaleableInterface; +use Magento\Framework\View\Element\Template\Context; class HistoricalPriceBox extends FinalPriceBox { + + + protected $_priceHelper; + + /** + * @param Context $context + * @param SaleableInterface $saleableItem + * @param PriceInterface $price + * @param RendererPool $rendererPool + * @param array $data + * @param SalableResolverInterface $salableResolver + * @param MinimalPriceCalculatorInterface $minimalPriceCalculator + * @param Data $priceHelper + */ + public function __construct( + Context $context, + SaleableInterface $saleableItem, + PriceInterface $price, + RendererPool $rendererPool, + array $data = [], + SalableResolverInterface $salableResolver = null, + MinimalPriceCalculatorInterface $minimalPriceCalculator = null, + Data $priceHelper + ) + { + $this->_priceHelper = $priceHelper; + parent::__construct($context, $saleableItem, $price, $rendererPool, $data, $salableResolver, $minimalPriceCalculator); + } + public function canShowPrice(): float { $product = $this->getSaleableItem(); + $historicalPrice = $this->_priceHelper->currency($product->getData('historical_price', false, false)); return (int) $product->getPriceInfo()->getPrice(FinalPrice::PRICE_CODE)->getValue() - > (int) $product->getData('historical_price') - && (int) $product->getData('historical_price') > 0; + > (int) $historicalPrice + && (int) $historicalPrice > 0; } } From 906fa7a81dfb96b382a9018b4ada0d570c16c379 Mon Sep 17 00:00:00 2001 From: Stefan Teichmann Date: Mon, 17 Apr 2023 14:09:42 +0200 Subject: [PATCH 2/2] Respect currency-conversion in HistoricalPriceBox.php. Solves macopedia/magento2-omnibusdirective#4 --- Pricing/Render/HistoricalPriceBox.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Pricing/Render/HistoricalPriceBox.php b/Pricing/Render/HistoricalPriceBox.php index 5983128..cbe0722 100644 --- a/Pricing/Render/HistoricalPriceBox.php +++ b/Pricing/Render/HistoricalPriceBox.php @@ -46,7 +46,7 @@ public function __construct( public function canShowPrice(): float { $product = $this->getSaleableItem(); - $historicalPrice = $this->_priceHelper->currency($product->getData('historical_price', false, false)); + $historicalPrice = $this->_priceHelper->currency($product->getData('historical_price'), false, false); return (int) $product->getPriceInfo()->getPrice(FinalPrice::PRICE_CODE)->getValue() > (int) $historicalPrice