【发布时间】:2014-10-10 10:16:13
【问题描述】:
我需要为每种产品显示自定义价格,管理员将为每种产品设置不同的价格。并且该产品价格只应显示在产品列表和产品查看页面中,不改变产品实际价格。同样的价格也应该适用于购物车。我尝试使用 catalog_product_get_final_price 观察者,但它将价格显示为特价但不会改变产品价格的显示。请给我一个想法,我该怎么做?在此先感谢:)
【问题讨论】:
标签: magento
我需要为每种产品显示自定义价格,管理员将为每种产品设置不同的价格。并且该产品价格只应显示在产品列表和产品查看页面中,不改变产品实际价格。同样的价格也应该适用于购物车。我尝试使用 catalog_product_get_final_price 观察者,但它将价格显示为特价但不会改变产品价格的显示。请给我一个想法,我该怎么做?在此先感谢:)
【问题讨论】:
标签: magento
on list page and view page just check whether your custom price is null nor not if it is null show original price and if it not null show custom price.
create a event in config file **checkout_cart_product_add_after** as given below
<events>
<checkout_cart_product_add_after>
<observers>
<unique_event_name>
<class>modulename/observer</class>
<method>modifyPrice</method>
</unique_event_name>
</observers>
</checkout_cart_product_add_after>
</events>
create new file **Observer.php**
class namespace_modulename_Model_Observer
{
public function modifyPrice(Varien_Event_Observer $obs)
{
// Get the quote item
$item = $obs->getQuoteItem();
// Ensure we have the parent item, if it has one
$item = ( $item->getParentItem() ? $item->getParentItem() : $item );
// Load the custom price
$price = $this->_getPriceByItem($item);
// Set the custom price
$item->setCustomPrice($price);
$item->setOriginalCustomPrice($price);
// Enable super mode on the product.
$item->getProduct()->setIsSuperMode(true);
}
protected function _getPriceByItem(Mage_Sales_Model_Quote_Item $item)
{
$price;
//use $item to determine your custom price.
return $price;
}
}
【讨论】: