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

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

Open
stefan-teichmann opened this issue Apr 13, 2023 · 1 comment · May be fixed by #6
Open

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

stefan-teichmann opened this issue Apr 13, 2023 · 1 comment · May be fixed by #6

Comments

@stefan-teichmann
Copy link

stefan-teichmann commented Apr 13, 2023

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!

@idziakjakub
Copy link
Collaborator

Hello @stefan-teichmann,

feel free to create a pull request for this issue and I we will merge it.

Best regards
Jakub Idziak

stefan-teichmann added a commit to stefan-teichmann/magento2-omnibusdirective that referenced this issue Apr 17, 2023
stefan-teichmann added a commit to stefan-teichmann/magento2-omnibusdirective that referenced this issue Apr 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants