Magento 2:如何使自定义费用征税


9
  • 我想对自定义费用加税。税收计算是完美的,可以获取税收金额,但未在数据库中quote_address的TAX文件中设置。

    public function collect(
        \Magento\Quote\Model\Quote $quote,
        \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment,
        \Magento\Quote\Model\Quote\Address\Total $total
    ){
    
      $total->setTaxAmount($total->getTaxAmount()+$taxAmount);
      $total->setBaseTaxAmount($total->getBaseTaxAmount()+$taxAmount); 
    }
  • 我尝试在collect方法中设置tax Amount,但未设置。

  • 我想像这个代码一样。它是Magento1,但我想要Magento 2


尝试按照以下步骤向您的小计magento.stackexchange.com/questions/92774/…
Abhinav Singh

Answers:


1

您可以使用以下代码在报价地址和报价表中设置税额:

$quote->setTaxAmount($total->getTaxAmount() + $taxAmount);
$quote->setBaseTaxAmount($total->getBaseTaxAmount() + $taxAmount);

$address = $shippingAssignment->getShipping()->getAddress();
$address->setTaxAmount($total->getTaxAmount() + $taxAmount);
$address->setBaseTaxAmount($total->getBaseTaxAmount() + $taxAmount);

希望对您有帮助。如果您有其他疑问,请随时询问。

乐意效劳!

谢谢,


0

无需致电,$total->setTaxAmount()您需要使用addTotalAmount

$total->addTotalAmount('tax', $amount);
$total->addBaseTotalAmount('tax', $baseAmount);
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.