5

In my Drupal Commerce store, I have a field called Commission.

The Commission is input as a percentage (i.e. its not a fixed global value).

I need the final price to be updated so it incorporates the commission. I then need VAT to be added to the commission (but not the original price). The user should be able to see the full price (with commission and commission-VAT) before they add a product to cart.

I thought Rules would be perfect for this situation, especially as it has an action called "Multiply the unit price by some amount". However, this action doesn't seem to accept values from custom fields, even if you bring them into scope in the conditions area of the Rule.

I have watched Randy Fey's excellent tutorials on the Rules and Commercial modules, and I have tried to adapt them to my use case. However, I can't get it to work.

Could some one give me some pointers. Thanks!

3 Answers 3

6

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.

1
  • Thanks for the tip! It helped me with another issue where "Multiple the Unit Amount by" would not do numbers less than 1, I needed a percentage 0.2. Plus you helped me understand rules a LOT more. Cheers! Commented Mar 22, 2012 at 20:34
2

Though this is an old question, I came across the same problem as bench. I finally solved it by using the following conditions:

Entity has field -> Entity: [commerce-line-item] -> Field: commerce_product
Entity has field -> Entity: [commerce-line-item:commerce-product] -> Field: field_your_custom_field

So you have to do it in two steps. Wished someone told me that 2 hours ago..;-)

0

for 1): 'Under data selectors choose "commerce-product (saved commerce product)."'

Under data selectors i can only add "commerce-line-item..." ?? And also there is a block "field" - "The name of the field to check for." ??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.