duanlu6114 2014-05-26 14:42
浏览 9

在Magento观察员中设置产品税

I'm using sales_quote_add_item and I'd like to change the tax class of a product. In observer, I retrieve product:

$event = $observer->getEvent();
$item = $event->getQuoteItem();
$product = $item->getProduct();

I tried $item->setTaxClassId() and $product->setTaxClassId() methods but this didn't work.

Any other approaches available?

  • 写回答

3条回答 默认 最新

  • dougan7657 2014-05-27 16:54
    关注

    If you want to change product_tax_class using observer then you have to use sales_quote_item_set_product.

    The function Mage_Sales_Model_Quote_Item::setProduct resets some of the basic information each time a product is saved

    config.xml
    
    <config>
    ...
        <global>
            <events>
                <sales_quote_item_set_product>
                    <observers>
                        <samples>
                            <type>singleton</type>
                            <class>samples/observer</class>
                            <method>salesQuoteItemSetProduct</method>
                        </samples>
                    </observers>
                </sales_quote_item_set_product>
            </events>
        <global>
    ...
    </config>
    
    Observer.php
    
    class Mynamespace_Samples_Model_Observer
    {
        public function salesQuoteItemSetProduct(Varien_Event_Observer $observer)
        {
            /* @var $item Mage_Sales_Model_Quote_Item */
            $item = $observer->getQuoteItem();
    
            $item->setTaxClassId('2');
    
            return $this;
        }
    }
    

    Let me know if you have any query

    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料