Vote up!
Vote down!

Fixed Quantity of feed products to alter the price

My case:
I import with commerce feeds various products with different attributes.
The products have quantities like so 60,80,100,120,140 etc.
I need to calculate the unit price with the quantity price.
When I add a field quantity to the product I cannot get it in Rules to show and not perform a calculation rule.
Also tried as a line item, but cannot see it in the data selectors.
The quantity field is shwn from the unit price, so this is not what I need.
Because they order 5 x 80 , or 7x 100 = 0.50 (unit price must be shown) and then the total price 7x100x 0.50=350 total price.
I was a Ubercart fan, now I am a commerce believer.
Thanks for sharing

Asked by: boban_dj
on September 2, 2013

1 Answer

Vote up!
Vote down!

Giving answer, and hope to help others:
This is the rule I used for this simple calculation.
Add a field custom_quantity to your product variation type

{ "rules_multiply_quantity" : {
"LABEL" : "My custom quantity rule",
"PLUGIN" : "reaction rule",
"REQUIRES" : [ "rules", "commerce_cart" ],
"ON" : [ "commerce_cart_product_add" ],
"IF" : [
{ "entity_has_field" : { "entity" : [ "commerce-product" ], "field" : "field_custom_quantity" } }
"DO" : [
{ "data_calc" : {
"USING" : {
"input_1" : [ "commerce-product:commerce-price:amount" ],
"op" : "*",
"input_2" : [ "commerce-product:field-custom-quantity" ]
"PROVIDE" : { "result" : { "result_custom" : "Calculation result custom" } }
{ "data_set" : {
"data" : [ "commerce-product:commerce-price:amount" ],
"value" : [ "result-custom" ]

In human: and link:

I found the solution to this, so I thought I would post it to help anyone else out who is struggling:

1) Before you can call your field under actions, you have to bring it "into scope" under conditions. Select "Entity has field". Under data selectors choose "commerce-product (saved commerce product).

2) For some reason, it seems impossible to use the "Multiple the Unit Amount by" option, as no matter what data selector you use, you will get an error. Instead select "Calculate a value"

3) Under "Input Value 1" select "commerce-product:commerce-price:amount".

4) Select which calculation to use. In my use case, I used multiply (*).

5) Under "Input Value 2" click the "switch to data selection button". You can now select your custom field. It will be located under "commerce-product: (saved commerce product)"

6) Under "Provided variables" give the result of the calculation a name. Choose a good name, as you will be using it later on.

7) Now create a new action called "Set a data value".

8) For the data select pick "commerce-product:commerce-price:amount"

9) Finally, under value, click the "switch to data selection button". You can now select the variable you created in step 6.

This is everything you need to change the price based on the value of a custom field.

Notes: 1) For the event, I used "Before saving a commerce product" 2) I would recommend creating a custom field called "base price", where the user can enter the price before calculations. The rule is applied every time a product is saved, so the commerce price field will keep on changing each time the product is saved. If you use a base price field, you can avoid this problem.

Answer by: boban_dj
Posted: Sep 2, 2013