如何应用从magento我们自己的自定义表中获取的价格

时间:2012-11-26 09:09:40

标签: magento

我想应用从我的自定义表格中提取的价格(比如my_own_prices)。我有一定的情况,我不能使用magento的价格(如分层价格或特价),我需要从我的表中获取数据并将其应用于购物车。如果可能,请回复。

1 个答案:

答案 0 :(得分:1)

您可以使用catalog_product_get_final_price观察者来完成。

首先在你的模块中声明观察者(假设你已经有模块)etc/config.xml

<config>
    ...
    <frontend>
        <events>
            <catalog_product_get_final_price>
                <observers>
                    <something_unique_here>
                        <type>singleton</type>
                        <class>YourCompany_YourModule_Model_Observer</class>
                        <method>catalogProductGetFinalPrice</method>
                    </something_unique_here>
                </observers>
            </catalog_product_get_final_price>
        </events>
    </frontend>
    ...
</config>

然后在你的模块中Model\Observer.php添加以下方法:

public function catalogProductGetFinalPrice($observer)
{
    $product = $observer->getEvent()->getProduct();

    // Do your queries to your custom tables here and if necessary ..
    $product->setFinalPrice(..);
}