Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect currency-conversion in HistoricalPriceBox.php #6

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 39 additions & 2 deletions Pricing/Render/HistoricalPriceBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}