Tags/topics: 
1
Answers
Vote up!
0
Vote down!

How do I change the price of an item in the cart??

Unable to change price of product in cart using rules.

Situation: I have a complex registration form with a cost field that is populated by rules after the form is submitted. I need to charge people this cost

Attempt: I have a rule that adds a product to the cart called itw_retreat. This product has a cost of 0 by default. Then the cost is taken from the form where I have it stored and applied to the product in the cart.
I have tried this several different ways but this is the most boiled down version.

Expectation: The rule should create my product in the cart, and then apply the price from the entityform to it.

What happens: The rule executes, creates the product in the cart, and throws no error message. I do have a php statement to put the line item object (new_retreat) into the logs. As you can see in the picture below, the price of 235 is being added to the new retreat object amount, but it has several amount fields, and some of them are still set to zero. Also pictured below is the shopping cart still displaying zero.

My rule is:
Event : After saving a new entityform

Condition: Entity has field Parameter: Entity: [entityform], Field: field_cost //this is the field on the entityform with my price

Action1: Add a product to the cart
Parameter: User: [entityform:user], Product SKU: itw_retreat, Combine similar items in the cart: false
Provides variables: New Retreat (new_retreat)

Action2: Set the unit price to a specific amount
Parameter: Line item: [new-retreat], Amount: [entityform:field-cost]

Action3: execute php to return new_retreat object to watchdog (see below)

This is the new_retreat object returned to watchdog after everything else is done:

stdClass Object ( [type] => product [order_id] => 2 [quantity] => 1 [data] => Array ( ) [line_item_id] => 25 [line_item_label] => itw_retreat [created] => 1359654671 [changed] => 1359654671 [commerce_product] => Array ( [und] => Array ( [0] => Array ( [product_id] => 5 ) ) ) [commerce_display_path] => Array ( [und] => Array ( [0] => Array ( [value] => ) ) ) [commerce_unit_price] => Array ( [und] => Array ( [0] => Array ( [amount] => 235 [currency_code] => USD [data] => Array ( [components] => Array ( [0] => Array ( [name] => base_price [price] => Array ( [amount] => 0 [currency_code] => USD [data] => Array ( [components] => Array ( ) ) ) [included] => 1 ) [1] => Array ( [name] => base_price [price] => Array ( [amount] => 235 [currency_code] => USD [data] => Array ( ) ) [included] => 1 ) ) ) ) ) ) [commerce_total] => Array ( [und] => Array ( [0] => Array ( [amount] => 0 [currency_code] => USD [data] => Array ( [components] => Array ( [0] => Array ( [name] => base_price [price] => Array ( [amount] => 0 [currency_code] => USD [data] => Array ( [components] => Array ( ) ) ) [included] => 1 ) ) ) ) ) ) )

any help here would be greatly appreciated!

Asked by: jas891
on January 31, 2013

1 Answer

Vote up!
0
Vote down!

Anybody have any idea on this one?

Answer by: jas891
Posted: Feb 15, 2013