0

I have this observer listening: sales_quote_product_add_after

Inside the observer I run this code to change the price of the item when added to the cart.

 $item = $items[0];
        $request = Mage::app()->getRequest();
        $newPrice = $request->getParam("new_price");

        $item->setCustomPrice($newPrice);
        $item->setOriginalCustomPrice($newPrice);
        $item->getProduct()->setIsSuperMode(true);
        $item->save();

This works perfectly when a customer is logged in, however when a customer isn't logged in I get a red error message on the front end saying: "Cannot add the item to shopping cart." and it doesn't add to the cart.

2 Answers 2

0

Did you track down where in core code that error is generated? Did you place some form of debug code around that? (Preferably you are using xdebug with a means to set breakpoints in the code)

Once you do that, your reasons will most likely be revealed. Should be easy for you to find, as the error is really specific, generated from one specific point in the code. Easy to target and debug.

Once you get the real reason (will most likely be an exception or missing data in your create request) we can help further. Most likely you will then already know what is wrong as well.

Hope that helps

0

I just found what's wrong. You can't ever call save() on a customer not logged in or even something related to them. I just removed that line of code and it works perfectly for signed in and not signed in.

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.