沃梦达 / 编程问答 / php问题 / 正文

Magento:在审查期间向报价添加关税/税款

Magento: adding duties/taxes to a quote during review(Magento:在审查期间向报价添加关税/税款)

本文介绍了Magento:在审查期间向报价添加关税/税款的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要调用第 3 方 API,以便在结帐流程的审核阶段了解国际运输的最新关税/税费.我已准备好 API 调用,但是我缺少将退回的关税和税款添加到报价中的方法.

I need to make a call to a 3rd party API to get up to date Duties/Taxes for international shipping during the review stage of the checkout process. I have the API call ready to go, however I am missing a way to add the returned duties and taxes to the quote.

有没有内置的方法来做到这一点?

Is there a built in way to do this?

我希望有类似的东西

$quote->addCostComponent("Duties", 5.0);

推荐答案

您需要执行以下步骤:

  1. 首先,您需要为您的关税/税款创建属性以按顺序显示它们,而不仅仅是添加到总计中.应该至少有两个属性,一个是网站货币的价值(用于支付捕获,它应该有 base_ 前缀)和一个显示货币的价值(仅用于显示客户所需货币的金额).应将此属性添加到具有财务部分(quote_address、order、invoice)的每个实体.例如它应该是:base_your_attribute_codeyour_attribute_code 十进制类型.

  1. First of all you need to create attributes for your custom duties/taxes for displaying them in order, not only just add to the grand total. There should be at least two attributes one for value in website currency (used in payment capture and it should have base_ prefix) and one value in displayed currency (used just for displaying amount in desired currency for customer). This attributes should be added to every entity with financial part (quote_address, order, invoice). For instance it should be: base_your_attribute_code and your_attribute_code with decimal type.

然后你需要创建你的总收集器模型,它应该从 Mage_Sales_Model_Quote_Address_Total_Abstract 扩展,并实现像这个例子中的收集和获取方法:

Then you need create your total collector model that should be extended from Mage_Sales_Model_Quote_Address_Total_Abstract and implement collect and fetch methods like in this example:

/**
 * Your custom total model
 *
 */
class Your_Module_Model_Total_Custom extends Mage_Sales_Model_Quote_Address_Total_Abstract
{
    /** 
     * Constructor that should initiaze 
     */
    public function __construct()
    {
        $this->setCode('your_attribute_code');
    }

    /**
     * Used each time when collectTotals is invoked
     * 
     * @param Mage_Sales_Model_Quote_Address $address
     * @return Your_Module_Model_Total_Custom
     */
    public function collect(Mage_Sales_Model_Quote_Address $address)
    {
        parent::collect($address);

        // ... Some your api calls to retrive amount ...

        // Set base amount of your custom fee
        $this->_setBaseAmount($calculatedAmount);

        // Set amount of your custom fee in displayed currency
        $this->_setAmount(
            $address->getQuote()->getStore()->convertPrice($calculatedAmount, false)
        );

        return $this;
    }

    /**
     * Used each time when totals are displayed
     * 
     * @param Mage_Sales_Model_Quote_Address $address
     * @return Your_Module_Model_Total_Custom
     */
    public function fetch(Mage_Sales_Model_Quote_Address $address)
    {
        // Display total only if it is not zero
        if ($address->getYourAttributeCode() != 0) {
            $address->addTotal(array(
                'code' => $this->getCode(),
                'title' => 'My Custom Duty',
                'value' => $address->getYourAttributeCode()
            ));
        }
    }
}

  • 收集器模型创建后,您需要将其添加到配置中:

  • After you the collector model is created you need add it to configuration:

    <config>
        <global>
            <sales>
                <quote>
                    <totals>
                        <your_total_code>
                            <class>your_module/total_custom</class>
                            <before>grand_total</before>
                            <after>shipping</after>
                        </your_total_code>
                    </totals>
                </quote>
            </sales>
        </global>
    </config>
    

    • class 节点包含收集器模型的类别名
    • beforeafter 节点表示收集器的调用顺序.
      • class node contains the class alias of your collector model
      • before and after nodes indicate invocation order of your collector.
      • 您需要将您的总属性添加到将用于将计算数据复制到订单或发票中的字段集:

        You need to add your total attributes to field-sets that will be used for copying calculated data into order or invoice:

        <config>
            <global>
                <fieldsets>
                    <!-- copies data from quote address to order during the order placement -->
                    <sales_convert_quote_address>
                        <base_your_attribute_code><to_order>*</to_order></base_your_attribute_code>
                        <your_attribute_code><to_order>*</to_order></your_attribute_code>
                    </sales_convert_quote_address>
        
                    <!-- copies data from order to invoice/shipment/creditmemo during their creation -->
                    <sales_convert_order>
                        <base_your_attribute_code><to_invoice>*</to_invoice><to_shipment>*</to_shipment><to_cm>*</to_cm></base_your_attribute_code>
                        <your_attribute_code><to_invoice>*</to_invoice><to_shipment>*</to_shipment><to_cm>*</to_cm></your_attribute_code>
                    </sales_convert_order>
        
                </fieldsets>
            </global>
        </config>
        

      • 执行此步骤后,您将能够在订单总额中看到自定义费用

      • After performing this steps you will be able to see your custom fee in order totals

        这篇关于Magento:在审查期间向报价添加关税/税款的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

  • 本文标题为:Magento:在审查期间向报价添加关税/税款

    基础教程推荐