Discussions

Custom Line Item and Pricing Rules

Hi

I have a project were the client wants to sell tickets to an event. There are three different versions of these tickets at three different price points:

dinner and concert ticket - $75
concert ticket - $15
concert ticket (family pass) - $30

The site is designed to use a fast checkout type of setup with a single form once the add to cart button is selected. Using rules the user goes directly to the checkout form.

Using the editablefields module and the commerce custom product module I was able to create a custom line item where the user can choose the ticket type from a select list.

I then created three pricing rules that is supposed to change the unit price based on the user selection in the line item form. Here's the concert ticket item rule:

{ "rules_ticket_cost_concert" : {
"LABEL" : "Ticket Cost Concert",
"PLUGIN" : "reaction rule",
"REQUIRES" : [ "rules", "commerce_line_item", "commerce_product_reference", "entity" ],
"ON" : [ "commerce_product_calculate_sell_price", "commerce_line_item_update" ],
"IF" : [
{ "entity_has_field" : { "entity" : [ "commerce-line-item" ], "field" : "field_type" } },
{ "data_is" : { "data" : [ "commerce-line-item:field-type" ], "value" : "15" } }
],
"DO" : [
{ "commerce_line_item_unit_price_amount" : {
"commerce_line_item" : [ "commerce_line_item" ],
"amount" : "15",
"component_name" : "base_price",
"round_mode" : "1"
}
}
]
}
}

The problem is the line item unit price doesn't get updated. The price doesn't get updated when changing the quantity field either. What am I doing wrong. I know there must be a simpler more elegant way of achieving the same thing. Please forgive my commerce noobness!!

Posted: Sep 5, 2012

Comments

denpub on September 5, 2012

Is there an easy way of debugging rules (like adding an alert at a certain point to see if it's executing as desired)?

denpub on September 6, 2012

After going over Randy Fay's excellent video tutorials (mainly the one "Donations with Custom Line Item Types in Drupal Commerce") I was able to gather enough info to find a couple of places I was going wrong. First my custom line item was set up as a field type list(text) which prevented me from using it in a calculation, after changing it to list(integer) it was available to work with.

The problem now is it works the first time the product is added to the cart, but if I change the custom line item it doesn't dynamically update the unit price. My gut feeling is that I need to find another trigger event because "Calculating the sell price of a product" does't seem to fire when changing the custom line item list. Is there something else I'm missing? Changing the quantity amount at the line item level doesn't dynamically change the total either. I want to be able to have the user select the ticket type and have the unit price and total change dynamically and have them change the quantity to have the total change dynamically.

Any help would be greatly appreciated.

Thanks in Advance

jawad.shah on September 24, 2013

Denpub, I'm also facing same problem. In my case price is updated for first product only :(
Have you solved this issue ? If yes, then let me know about this issue please.

Thanks.

MrPeanut on October 30, 2012

Wish I could be of more help. I'm trying to do the same thing (however, with three fields instead of one).

if I change the custom line item it doesn't dynamically update the unit price

Could you explain this more? What are you changing?