【问题标题】:Magento 1.9 - How to update the product price based on customer groupMagento 1.9 - 如何根据客户群更新产品价格
【发布时间】:2019-06-10 12:29:47
【问题描述】:

我注意到,当将商品从客户购物篮(左侧)移至订单(在管理区域 -> “管理 > 销售 > 新订单”中)时,产品价格不会结转客户组价格.因此,如果客户购物篮中的产品价格为 10.00 英镑(这是特定组的价格),并且管理员将其移至订单,则此 10.00 英镑的价格不会结转。篮子里的价格现在是 15.00 英镑(原价)

我认为解决此问题的最佳方法是创建一个事件观察者并在价格移动到订单时更新价格?

【问题讨论】:

    标签: magento magento-1.9


    【解决方案1】:

    我设法通过为 'sales_quote_add_item' adminhtml 事件创建观察者来解决此问题。请看下文。希望这可以帮助某人

    <?xml version="1.0"?>
    <config>
        <modules>
            <Companyname_Extensionname>
                <version>0.0.1</version>
            </Companyname_Extensionname>
        </modules>
        <global>
            <models>
                <Companyname_Extensionname>
                    <class>Companyname_Extensionname_Model_Observer</class>
                </Companyname_Extensionname>
            </models>
        </global>
        <adminhtml>
            <events>
                <sales_quote_add_item>
                    <observers>
                        <companyname_extensionname>
                            <class>companyname_extensionname/observer</class>
                            <method>carttoorder</method>
                        </companyname_extensionname>
                    </observers>
                </sales_quote_add_item>
            </events>
        </adminhtml>
    </config>
    
    
    <?php 
    class Companyname_Extensionname_Model_Observer {
        public function carttoorder(Varien_Event_Observer $observer) {
            $event = $observer->getEvent();
            $quote_item = $event->getQuoteItem();
            $product_sku = $quote_item->getSku();
    
            $sessionquoteId = Mage::getSingleton('adminhtml/session_quote')->getQuote()->getId();
            $sessionCustomerId = Mage::getModel('sales/quote')->loadByIdWithoutStore($sessionquoteId)->getCustomerId();
            $customerData = Mage::getModel('customer/customer')->load($sessionCustomerId);
            $customerId = $customerData->getGroupId();
    
            $_product = Mage::getModel('catalog/product');
            $_product->load($_product->getIdBySku($product_sku));
    
            $groupPrices = $_product->getData('group_price');
    
            if (!is_null($groupPrices) || is_array($groupPrices)) {
                foreach ($groupPrices as $groupPrice) {
                    if($groupPrice['cust_group'] == $customerId){
                        $group_price = $groupPrice['website_price'];
                        break;
                    }
                }
            }
            $quote_item->setOriginalCustomPrice($group_price);
            $quote_item->getProduct()->setIsSuperMode(true);
        } 
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-18
      相关资源
      最近更新 更多