1

I want to add a new price field called Discount to a product. So now I have two price fields, Price and Discount.

Then with the help of the rule, I am interested in showing in the node page the price(with line-trough) and the discount.

Then when adding the product to the cart, the discount price will be added, instead of the normal price. How can I achieve this with rules?

PS: I don't want to use the Commerce Sale price module since it doesn't integrate with Search api.

I have found these instructions but I am not sure how to create the rule!

  1. Add another price field to your product type.
  2. Add a rule that applies the discount to the price on that product if the extra price field exists. Make sure you use the Discount price component when creating the rule.
  3. Use Extra Price Formatters to display the difference.
1

I finally found a solution:I cloned the rule of the Commerce Sale module: I created a Component: Conditions: -Entity has field:Parameter: Entity: [line-item], Field: commerce_product -Entity has field:Parameter: Entity: [line-item:commerce-product], Field: field_discount_price -NOT Data value is empty:line-item:commerce-product:field-discount-price:amount

Actions:Set the unit price to a specific amount (Specify the numeric amount to set the price to:Price:Amount Value:Discount

Then I created a rule: Events:Calculating the sell price of a product Action:The previous component (Data selector:Commerce line items)

Then I used a price formatter and its done https://www.drupal.org/project/commerce_extra_price_formatters Thanks!

0

I had a similar case and tried to build the rule as you described. At start I did not get it right but then I looked into the component setup here: Commerce Saleprice rules code

I used this module to manage the formatters: Drupal Commerce Extra Price Formatters

I added a Discount field to my product fields and a Rule to calculate price using the above component. I also went for a % instead of using a final price so I used the Multiply option.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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