1

on product detail page i want to show price other than original price via observer.

Say product with price 100 will show price as 120 or 110

which observer should i use to do same

I found product price comes from catalog/product/price.phtml

is there any way in admin > catalog > category > custom deign

to call my custom price.html for specifi category

something like below

<reference name="product.info">
            <action method="setTemplate"><template>catalog/product/view_mour.phtml</template></action>
</reference>

Update code:

<?xml version="1.0"?>
<config>
  <modules>
    <Mour_Customgroup>
      <version>0.1.0</version>
    </Mour_Customgroup>
  </modules>
  <frontend>
    <events>
         <catalog_product_load_after>
            <observers>
                <setadiscountprice>
                    <type>singleton</type>
                    <class>Mour_Customgroup_Model_Observer</class>
                    <method>changeprice</method>
                </setadiscountprice>
            </observers>
          <catalog_product_load_after>
    </events>
  </frontend>
</config> 

and observer.php

<?php
class Mour_Customgroup_Model_Observer
{

    public function changeprice(Varien_Event_Observer $event) {
    if($_GET['id']){
        $pricetoadd=Mage::getModel('catalog/product')->load($_GET['id'])->getPrice(); // error comes after adding this line

        $product = $event->getEvent()->getProduct();
        $originalprice = $product->getPrice();
        $customprice = $originalprice+$pricetoadd;
        $product->setPrice($customprice);
    }
   }
}

i am trying to add price of product (id from get parameter) to product price

if i remove this line : $pricetoadd=Mage::getModel('catalog/product')->load($_GET['id'])->getPrice();

it works fine

4
  • you can use the checkout_cart_save_after or checkout_cart_product_add_after event. you want to change this for all products or for only particular products Jan 6, 2015 at 5:06
  • no i want to show different price on product detail pages only not in cart Jan 6, 2015 at 5:12
  • you want the same price to be added to cart also Jan 6, 2015 at 5:14
  • yeah i am able to do that via observer ,just need to show different price on product detail page via observer' Jan 6, 2015 at 5:21

1 Answer 1

5

you can use catalog_product_load_after event to change the product price in view page.

  <catalog_product_load_after>
            <observers>
                <custom_checkout_observer>
                    <type>singleton</type>
                    <class>Custom_Custom_Model_Observer</class>
                    <method>loadaftercatalog</method>
                </custom_checkout_observer>
            </observers>
    </catalog_product_load_after>

public function loadaftercatalog($event) {
    $product = $event->getEvent()->getProduct();
    $originalprice = $product->getPrice();
    $customprice = $originalprice+20;
    $product->setPrice($customprice);
   }

}
9
  • getting same price nothing adds Jan 6, 2015 at 5:43
  • I tried this, it works good for me. Please clear cache and check and check you can call the coreect observer file Jan 6, 2015 at 5:44
  • see i update my code according to you, cleared cache still not working Jan 6, 2015 at 5:46
  • hii after adding your code i get error maximum nesting level of 200 exceeded why so ??.. Jan 6, 2015 at 6:33
  • check the product price before set new price Jan 6, 2015 at 7:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.