Skip to content

Currency-Conversions not respected in canShowPrice() HistoricalPriceBox.php #4

Open
@stefan-teichmann

Description

@stefan-teichmann

Hello!

In the class HistoricalPriceBox.php currencies are not respected therefore the pricebox will behave differently in stores with multiple currencies.

I would suggest to amend the class to solve this issue:

Use-Statement:

use Magento\Framework\Pricing\Helper\Data;

Class:

  • add $_priceHelper, __construct-method
  • convert the value by using $historicalPrice = $this->_priceHelper->currency($product->getData('historical_price'), false, false);
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) $historicalPrice
            && (int) $historicalPrice > 0;
    }
}

Best regards!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions