I need to know which price function is called when product is added to cart as i have overridden the function getFinalPrice() but still when product is added to cart it takes the default price. Why ?
Thanks
You can change the product price while add to cart via Event to listen to checkout_cart_product_add_after by following code:
In your /app/code/local/{namespace}/{yourmodule}/etc/config.xml:
<config>
...
<frontend>
...
<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>
...
</frontend>
...
And then create an Observer class at /app/code/local/{namespace}/{yourmodule}/Model/Observer.php
<?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;
}
}
This is depends on your product type. default class is Mage_Catalog_Model_Product_Type_Price.
You can open config.xml in catalog module
<catalog>
<product>
<type>
<simple translate="label" module="catalog">
<label>Simple Product</label>
<model>catalog/product_type_simple</model>
<composite>0</composite>
<index_priority>10</index_priority>
</simple>
<grouped translate="label" module="catalog">
<label>Grouped Product</label>
<model>catalog/product_type_grouped</model>
<price_model>catalog/product_type_grouped_price</price_model>
<composite>1</composite>
<allow_product_types>
<simple/>
<virtual/>
</allow_product_types>
<index_priority>50</index_priority>
<price_indexer>catalog/product_indexer_price_grouped</price_indexer>
</grouped>
..........
here price_model, tag is the actual price model by product type.