Discussions

Use Case for an Event Registration w/Early Bird Discount - UPDATED to suggest a different approach...need to hide certain lines

I've been working on this all week, and have gotten somewhere with Randy Fay's help, but I need further assistance in understanding this.

Here's what I posted to IRC #drupal-commerce, but no response.

cmcoppenbarger> I have a use case I need help writing a rule for in commerce.
basically, I have a custom line item list(integer) with the 3 different prices.
But these represent the early bird prices for an event.
It works okay for a rule to calculate the sale price based on whether they select one of the 3 items
However, after the early bird date passes, I need the first to add $10, 2nd to add $15, and 3rd to add $20.

My thought is to do a loop in the action area to detect values, but Rules doesn't offer that or it doesn't seem to. Should I be looking a component that I call on a loop? When I try to use a loop, it doesn't find the "field_seminar_day_select".

I'm trying to accomplish this without making multiple SKUs for the same day.

Export of rule that works for early bird calculating.

{ "rules_registration_pricing" : {
"LABEL" : "Registration Pricing",
"PLUGIN" : "reaction rule",
"ACTIVE" : false,
"REQUIRES" : [ "rules", "commerce_line_item", "commerce_product_reference" ],
"ON" : [ "commerce_product_calculate_sell_price" ],
"IF" : [
{ "entity_has_field" : {
"entity" : [ "commerce-line-item" ],
"field" : "field_seminar_day_select"
}
},
{ "entity_has_field" : { "entity" : [ "commerce-line-item" ], "field" : "commerce_product" } },
{ "entity_has_field" : {
"entity" : [ "commerce-line-item:commerce-product" ],
"field" : "field_seminar_early_date"
}
},
{ "data_is" : {
"data" : [ "site:current-date" ],
"op" : "\u003E",
"value" : [ "commerce-line-item:commerce-product:field-seminar-early-date" ]
}
}
],
"DO" : [
{ "data_calc" : {
"USING" : {
"input_1" : [ "commerce-line-item:field-seminar-day-select" ],
"op" : "*",
"input_2" : "100"
},
"PROVIDE" : { "result" : { "seminar_early_price" : "Seminar early price" } }
}
},
{ "commerce_line_item_unit_price_amount" : {
"commerce_line_item" : [ "commerce_line_item" ],
"amount" : [ "seminar-early-price" ],
"component_name" : "base_price",
"round_mode" : "1"
}
}
]
}
}

Posted: Feb 10, 2012

Comments

ccoppen on February 10, 2012

Based on a suggestion from someone in #drupal-commerce, I created a new line-item field which contained the regular prices.

Now my issue is to hide certain attributes based on date using rules.

Basically, hiding and showing line-item fields based on date.

Any ideas on this are welcome.

It seems it should be straight forward similar rules to above, but I'm having no such luck finding a way to hide the fields in actions.

ccoppen on February 10, 2012

I now have 4 pricing rules, one for the early bird registration which just takes the value from the list and sets the price to it.

The other 3 detect what the value is set to, adds the additional amount for registration, and multiplies by 100 and adds to base price.

No problem there. Works great.

Here's my latest idea on the line items. I think I've figured out that you cannot technically get rid of a line item field.

However, is there a way to switch line item references?

Such as I'm using a custom line item type with the field that I want to go away after a certain date. In my display node, I'm referencing that line item type. Can I switch line item types after a certain date using rules?

rfay Randy Fay on February 16, 2012

I didn't grok everything you posted, but please remember that nearly everything is a view. So every time a line item is presented it's part of a view. So you can filter the view...