Magento个人客户目录定价规则

时间:2015-09-22 14:23:54

标签: magento magento-1.9

我正在尝试以编程方式在每个客户的基础上应用目录定价规则,但我发现目录定价规则基于客户群,而不是基于个人客户。有谁知道解决这个问题?

由于

1 个答案:

答案 0 :(得分:1)

虽然你可以找到一个扩展来做到这一点,但有一种方法可以使用Magento观察者来做到这一点。可能有其他方法可以做到,但这个方法在某种程度上相当简单。

创建一个模块并首先在config.xml中配置一个abserver:

</global>
    <events>
        <catalog_product_load_after>
            <observers>
                <productloadhandle>
                    <type>singleton</type>
                    <class>Yourcompany_Customprices_Model_Observer</class>
                    <method>getCustomPrice</method>
                </productloadhandle>
            </observers>
        </catalog_product_load_after>
        <catalog_product_get_final_price>
            <observers>
                <getfinalpricehandle>
                    <type>singleton</type>
                    <class>Yourcompany_Customprices_Model_Observer</class>
                    <method>getCustomPrice</method>
                </getfinalpricehandle>
            </observers>
        </catalog_product_get_final_price>
    </events>
</global>

然后创建将实现getCustomPrice方法的观察者模型。

class Yourcompany_Customprices_Model_Observer extends Mage_Core_Model_Abstract
{

    public function getCustomPrice($observer)
    {
        // If not logged in just get outta here
        if (! Mage::getSingleton('customer/session')->isLoggedIn()) {
            return;
        }

        $event = $observer->getEvent();
        if (Mage::getSingleton('customer/session')->isLoggedIn()) {
            // THis is where you will want to have your price mechanism going on.
            if (Mage::getSingleton('customer/session')->getCustomer()->getId() == $someIdFromCustomModuleTable) {
                $product = $event->getProduct();
                if ($product && null != $product->getSku()) {
                    // This is where you can tweak product price, using setPrice or setFinal
                    $product->setFinalPrice($customerPrice);
                }
            }
        }
        return $this;
    }
}

您可能必须使用表来实现模块的其余部分以存储自定义价格和从后端管理它的网格,这是非常标准的,我不会在这里解释,但这应该让您开始。

相关问题