I can clear the Tax when the subtotal is below USD800 when the front-end currency was in USD. However, if changed to another currency (e.g. HKD), the subtotal will change to 3,336.17 (HKD) instead of 424.99 (USD).
Our store’s based currency is in USD.
No matter $total[‘base_subtotal’] or $total[‘subtotal’], it still get the price based on the front-end currency.
May I know how to get the subtotal in USD or convert it to USD?
I really appreciate any help you can provide.
<?php
namespace AbcUsImportTaxObserver;
use PsrLogLoggerInterface;
use MagentoFrameworkEventObserverInterface;
use MagentoFrameworkEventObserver;
class ChangeTaxTotal implements ObserverInterface
{
protected $logger;
public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
}
public function execute(Observer $observer)
{
/** @var MagentoQuoteModelQuoteAddressTotal */
$total = $observer->getData('total');
$baseSubTotal = $total->getBaseSubtotal();
$additionalTaxAmt = 0;
if (count($total->getAppliedTaxes() ?? []) > 0) {
$subtotal = $total['base_subtotal'];
$this->logger->info('Base Subtotal: '.$subtotal);
if ($subtotal < 800) {
$additionalTaxAmt = round($subtotal*0.09,2);
$additionalTaxAmt = -$additionalTaxAmt;
$total->setTotalAmount('tax', 0);
$total->setGrandTotal($total->getGrandTotal() + $additionalTaxAmt);
}
}
return $this;
}
}