Magento:在审核期间在报价中添加关税/税款 [英] Magento: adding duties/taxes to a quote during review

查看:46
本文介绍了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.

有内置的方法吗?

我希望有类似的东西

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

推荐答案

您需要执行以下步骤:

  1. 首先,您需要为自定义关税/税款创建属性,以便按顺序显示它们,而不仅仅是添加到总计中.至少应有两个属性,一个是网站币种的值(用于付款捕获,应具有base_前缀),另一个是显示币种的值(仅用于为客户显示所需币种的金额).此属性应添加到具有财务部分(quote_address,订单,发票)的每个实体.例如,应为: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扩展的总收集器模型,并实现本示例中的collect和fetch方法:

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 节点包含您的收集器模型的类别名
    • 之前之后节点指示收集器的调用顺序.
      • 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:在审核期间在报价中添加关税/税款的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆