I want to change the product price to custom price through getFinalPrice() in product.php is there any way i am not getting how to do it ?
Asked
Active
Viewed 1,066 times
2
-
can you explain some more specific? – Manikandan May 05 '16 at 07:05
2 Answers
3
If you want to add your own price calculation, use the catalog_product_get_final_price and catalog_product_prepare_index_select events. Using observer events is always better than rewriting models or codepool overrides.
The price index gets used for product listings. The final price event gets used for all other situations (product page, cart/quote, order placement).
Erfan
- 3,117
- 26
- 32
-
1actually i have made an attribute custom_price so i want to use its value instead of the original price of products so how could I do it , i am trying it through getFinalPrice() method but nothing happened – user39175 May 05 '16 at 09:00
-
Well, then you're doing it wrong. Check out these answers: http://magento.stackexchange.com/questions/69095/magento-events-catalog-product-get-final-price-not-working – Erfan May 05 '16 at 09:20
-
But Erfan i applied according to the link but it get applied only when I add product to cart i want to have the price on view and list page also and those pricing rules and product rules get apllied to it – user39175 May 05 '16 at 12:30
-
1So then the get_final_price observer works :) On the list page you need to use
catalog_product_prepare_index_selectto modify the price index, because that's where the price comes from in that scenario. The product view page should work for you as well, as that uses the get final price routine - not sure why that's not working for you – Erfan May 06 '16 at 01:20 -
<catalog_product_get_final_price> <observers> <ybizz_pricechange_observer> <class>ybizz_pricechange/observer</class> <method>getFinalPrice</method> </ybizz_pricechange_observer> </observers> </catalog_product_get_final_price>Checkout i have used catalog_product_get_final_price event
– user39175 May 06 '16 at 04:52
0
My observer
<?php
class YBizz_PriceChange_Model_Observer {
public function getFinalPrice($observer) {
$product = $observer->getProduct();
$productIds = array($product->getId());
$prices = $this->ProductPrice($productIds);
$product->setPrice($new_price);
}
public function ProductPrice(array $productIds) {
$item = Mage::getModel('catalog/product')->load($productIds);
if ($item->getParentItem()) {
$item = $item->getParentItem();
}
if($item->getSuggested_price()){
$new_price = $item->getSuggested_price();
} else {
$new_price = $item->getProduct()->getPrice();
}
return $new_price;
}
}
?>
Michael Yaeger
- 487
- 8
- 22
user39175
- 91
- 11