I need to display a custom price for some products to a certain group of customers. I made it, but I only see the custom price in the product view page, and I need to display it in all the web. Now I see the regular price in the product list, and it should also display the custom price.
First I created the custom price attribute private_price
for the products.
Then I created a module, and listen for the catalog_product_get_final_price
event:
<events>
<catalog_product_get_final_price>
<observers>
<catalog_product_get_final_price_handler>
<type>singleton</type>
<class>privatesales/observer</class>
<method>modifyFinalPrice</method>
</catalog_product_get_final_price_handler>
</observers>
</catalog_product_get_final_price>
</events>
and in the observer:
public function modifyFinalPrice(Varien_Event_Observer $observer)
{
$isLoggedIn = Mage::getSingleton('customer/session')->isLoggedIn();
/* If customer is logged in */
if($isLoggedIn) {
/* Get the logged in customer's group ID */
$customerGroupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
/* Check if the logged in customer's group ID matches with the ID you are after */
if ($customerGroupId==2) {
$product = $observer->getEvent()->getProduct();
$privatePrice = (double) $product->getPrivatePrice();
if ($privatePrice>0 && !empty($privatePrice) && !is_null($privatePrice)) {
$product->setFinalPrice($privatePrice);
}
}
}
}
I'm using magento 1.9.2.4
Update: I also tried the event catalog_product_load_after
with same result, price changed in product view, but price remains unchanged in product list.