1

i create my observer for change price at cart page

My config.xml is

      <events>
          <checkout_cart_product_add_after>
              <observers>
                 <brain_priceedit_model_observer>
                    <type>singleton</type>
                    <class>Brain_Priceedit_Model_Observer</class>
                    <method>updatePrice</method>
                 </brain_priceedit_model_observer>
             </observers>
          </checkout_cart_product_add_after>
      </events>

and my Observer.php is

public function updatePrice( Varien_Event_Observer $obs ) 
 {
    $quote = $obs->getEvent()->getQuote();
        $item = $obs->getQuoteItem();
        $product_id=$item->getProduct_id();
        $_product=Mage::getModel('catalog/product')->load($product_id);
        $newprice=$_product->getPrice();
        echo$price=$newprice*10;
        $item->setCustomPrice($price);
        $item->setOriginalCustomPrice($price);
        $item->getProduct()->setIsSuperMode(true);
  }

this observer working when customer is log in but when customer not log in it's show error like this

enter image description here

5
  • cannot understand customer is logout?
    – Amit Bera
    Jan 2 '15 at 5:33
  • i mean when customer not log in Jan 2 '15 at 5:36
  • still confusing... please explain in detail
    – Keyul Shah
    Jan 2 '15 at 5:56
  • simply forget it i want to change price at cart page so what to do ? Jan 2 '15 at 5:59
  • How can be cart price and this question related?? @vaibhavahalpara
    – dh47
    Jan 2 '15 at 6:05
1

instead of you can use event checkout_cart_product_add_after to change or update price in cart

here i can just show you some little example

In your /app/code/local/{namespace}/{yourmodule}/etc/config.xml:

<config>
    <frontend>
        <events>
            <checkout_cart_product_add_after>
                <observers>
                    <your_event_name>
                        <class>{{modulename}}/observer</class>
                        <method>updatePrice</method>
                    </your_event_name>
                </observers>
            </checkout_cart_product_add_after>
        </events>    
    </frontend>

And then create an Observer class at /app/code/local/namespace/modulename/Model/Observer.php

<?php
    class namespace_modulename_Model_Observer
    {
        public function updatePrice(Varien_Event_Observer $obs)
        {
            // Get the quote item
            $item = $obs->getQuoteItem();

            // Set the custom price
            $item->setCustomPrice($price);
            $item->setOriginalCustomPrice($price);
            // Enable super mode on the product.
            $item->getProduct()->setIsSuperMode(true);
        }

    }

its just idea, you may know better to how to use observer.

hope this will sure help to you.

4
0

I got the solution.There are issue with save function and product id

remove $quote_item->save(); and

Change to $quote_item->getProductId(); from $quote_item->getProduct_id();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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