1

HOW TO UPDATE TAX WITH CUSTOM VALUE IN CART OR CHECKOUT.My requirement was when customer click add to cart and he move to cart that time i want to update tax with some API so do the needful.

  • Do you find how to set tax amount? if yes than please post it how to do this? – Newbie Apr 25 '17 at 11:11
1

One approach is :

You can try to overide the default collect total tax function.

Add this dependency :

<preference for="Magento\Tax\Model\Sales\Total\Quote\Tax" type="Vendor\Module\Model\Tax\Sales\Total\Quote\Tax"/>

Create you own Quote Tax Collection function based on native one.

Add your logic inside the collect function.

Example :

/**
 * Custom Collect tax totals for quote address
 *
 * @param Quote $quote
 * @param ShippingAssignmentInterface $shippingAssignment
 * @param Address\Total $total
 * @return $this
 * @throws RemoteServiceUnavailableException
 */
public function collect(
    Quote $quote,
    ShippingAssignmentInterface $shippingAssignment,
    Address\Total $total
) {
    $address = $shippingAssignment->getShipping()->getAddress();

    $storeId = $quote->getStoreId();

    if ($this->doNotUseCustomTax()
    ) {
        return parent::collect($quote, $shippingAssignment, $total);
    }

    $this->processCustomTax($quote);

    return $this;
}
  • ok i will try now – sangan Apr 18 '17 at 12:39
  • i am new to magento 2 can you please elaborate this answer with detail..because i tried but .. – sangan Apr 19 '17 at 6:39
  • I do not have the detail of the implementation sorry, I just share you an approach. Let's wait other answers. – Franck Garnier Apr 19 '17 at 7:10
  • ok,i am getting tax in my custom module and updated the tax trying to set with ""$total->setTaxAmount($taxAmount);"" but $total not getting value – sangan Apr 19 '17 at 7:26
  • Try to find how this module works : github.com/classyllama/ClassyLlama_AvaTax It is used to setup custom taxes for the US. – Franck Garnier Apr 19 '17 at 7:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.