Php Magento:在审核期间向报价中添加关税/税费
我需要调用第三方API,以便在结帐过程的审查阶段了解国际航运的最新关税/税费。我已经准备好了API调用,但是我缺少了将返回的关税和税款添加到报价中的方法 有没有一种内置的方法可以做到这一点 我希望有类似的事情Php Magento:在审核期间向报价中添加关税/税费,php,magento,Php,Magento,我需要调用第三方API,以便在结帐过程的审查阶段了解国际航运的最新关税/税费。我已经准备好了API调用,但是我缺少了将返回的关税和税款添加到报价中的方法 有没有一种内置的方法可以做到这一点 我希望有类似的事情 $quote->addCostComponent("Duties", 5.0); 您需要执行以下步骤: 首先,您需要为自定义关税/税款创建属性,以便按顺序显示它们,而不仅仅是将其添加到总计中。至少应该有两个属性,一个是网站货币的值(用于支付捕获,并且它应该有base_uu前缀),另
$quote->addCostComponent("Duties", 5.0);
您需要执行以下步骤:
base_uu
前缀),另一个是显示货币的值(仅用于显示客户所需货币的金额)。此属性应添加到每个具有财务部分(报价单地址、订单、发票)的实体。例如,它应该是:base\u-your\u-attribute\u-code
和your\u-attribute\u-code
,使用十进制类型/**
* 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()
));
}
}
}
<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>
您的\u模块/总\u自定义
总计
航运
- class节点包含收集器模型的类别名
- before和after节点指示收集器的调用顺序
<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>
*
*
***
***
是的,有。但我忘了是怎么回事了。在magento论坛上问这个问题不是更好吗?@Joe,如果你想寻求代码方面的帮助,那么magento论坛就是一片荒地。因为这是一个与代码相关的问题,所以对这里的观众来说似乎更合适。@JosephMastey关于magento,所以,请看,我仍然在看可能出了什么问题,但计算出的税额显示在总数中,但它并没有显示为它自己的行item@rennat,您是否定义了
fetch
方法?是,我添加了一些调试日志,我想知道它是否与getYourAttributeCode()方法的命名约定有关?我在每个实例中都使用了BJLTAX,但是getBJLTAX()不返回任何内容,事实上getBJLTAX()和getBJLTAX()也不返回任何内容。@rennat trygetData('BJLTAX')
。是的,您是对的,getBJLTAX
将与getData
不同,因为Magento使用方法名称中的每个大写字母作为下一个单词的开头,因此您的方法将转换为getData('B_J_L_T_A_X')
那么当getData('BJLTAX'没有返回任何内容时,我应该注意什么呢