I want to override a model call (Magento\Tax\Model\Sales\Total\Quote\CommonTaxCollector).
We used preference to override a model call inside di.XML like magento 2.1.x But it is not working on Magento 2.2
etc/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
<preference for="Magento\Tax\Model\Sales\Total\Quote\CommonTaxCollector" type="MyModule\CustomShippingTax\Model\Sales\Total\Quote\CommonTaxCollector" />
</config>
app\code\MyModule\CustomShippingTax\Model\Sales\Total\Quote\CommonTaxCollector.php
<?php
namespace MyModule\CustomShippingTax\Model\Sales\Total\Quote;
/**
* Tax totals calculation model
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class CommonTaxCollector extends \Magento\Tax\Model\Sales\Total\Quote\CommonTaxCollector
{
public function mapAddress(QuoteAddress $address)
{
$customerAddress = $this->customerAddressFactory->create();
$customerAddress->setCountryId($address->getCountryId());
$customerAddress->setRegion(
$this->customerAddressRegionFactory->create()->setRegionId($address->getRegionId())
);
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
var_dump($address->getPostcode());
exit;
$customerAddress->setCity($address->getCity());
$customerAddress->setStreet($address->getStreet());
return $customerAddress;
}
}
Please, can you help me on above issue?Any reference and suggestion is highly appreciated.
Thanks