Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Best way to alter price of an quote item as product is added to the cart? 
 
Del Fondente
Jr. Member
 
Total Posts:  28
Joined:  2008-05-27
 

I have a custom pricing scheme for some products, defined through attributes on the products in the backend. I can display this new pricing scheme on the product detail page, but when I add the product to the cart, the info is discarded. So now I need to alter the extended row price of an item in the cart as the product is added to the cart.

I’ve created a method in my module’s helper that responds to the Event “sales_quote_save_before”. In that method, I can isolate the quote item that I want to alter, and have tried changing the following:

* row_total
* base_row_total
* row_total_with_discount
* base_row_total_with_discount

Altering those seems to have no effect on the cart, where the default pricing scheme is still displayed. Any suggestions as to the best way to intercept an item as it is added to the cart and apply my own price for the line item (I can’t just alter the base price, because the calculation isn’t as simple as just price * quantity)?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Del Fondente
Jr. Member
 
Total Posts:  28
Joined:  2008-05-27
 

I can do a var_dump in my method and it appears that the fields I’ve altered are changed in the quote item’s ‘_data’ array. The old values are still in the ‘_origData’ array. But I’m still not seeing any change in the database once the item has been added to the cart. The values in the db are not my altered values. Anyone have any suggestions here? Is using the event system even the correct way to go about this, or should I override the controller and insert my logic there? I was attempting to have my changes be least disruptive to the rest of the system (and was thus trying to avoid overriding the controller).

 
Magento Community Magento Community
Magento Community
Magento Community
 
bradfordw
Jr. Member
 
Total Posts:  14
Joined:  2008-06-10
 

This is an issue I’ve been dealing with as well...I’m still trying to find that insertion point where the product’s info is set to the actual order and is then carried throughout the session without having to reset it each time (not exactly efficient).  And yea, I’m pretty sure prior to checkout it’s attributes are checked again (which makes sense because you don’t want fraud) against the product’s information before finalizing the order.

Anyway, I want to bump this as it’s a pretty interesting topic for those really trying to get a lot of mileage out of Magento in terms of customization.  I’ll ping back with info as I find it.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Del Fondente
Jr. Member
 
Total Posts:  28
Joined:  2008-05-27
 

I’ve given up on doing this through the observer / event system for now, and have been digging through the models and controllers to try to figure out how this all works. I’ll post more info here if / when I find anything useful.

 
Magento Community Magento Community
Magento Community
Magento Community
 
bradfordw
Jr. Member
 
Total Posts:  14
Joined:  2008-06-10
 

Part of me thinks this could be impossible, if (by looking at their db schema) there are foreign key constraints that lock invoice_entities to product entities it makes sense to the point of data integrity but really throws a wrench in things if you’re meaning for it to be dynamic.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Clay S
Jr. Member
 
Total Posts:  15
Joined:  2009-10-02
 

Well, this is an old post, but I’ve been bashing my head against the same exact problem for a few days now.  Did you ever determine if it’s possible to do this through the event/observer system?  This has been driving me nuts.  I’ve tried intercepting prices through the following events:

sales_quote_product_add_after
checkout_cart_product_add_after

These look promising:

checkout_cart_add_product_complete
checkout_cart_save_after

But I have not found the right point to intercept and change the values.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top