-1

I need to achieve a discount on a Drupal site with Commerce through rules.

Event :
When you have to decide a product price [ Calculating the sell price of a product ]

Conditions :
If the logged user have role 'role to trigger'
and there are at least 2 products in the cart with product_type = 'magazine' and field_mag_type == 'tipo'

Action :
Take the products with field_mag_type == 'tipo' in the cart and discount it by 15% [amount * 0.75]

Can someone did something like this and want to help me?

For now I have this rule

{ "rules_sconto_riviste_multiple" : {
    "LABEL" : "Sconto riviste multiple",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [
      "rules",
      "commerce_cart",
      "commerce_order",
      "commerce_line_item",
      "commerce_product_reference"
    ],
    "ON" : [ "commerce_product_calculate_sell_price" ],
    "IF" : [
      { "user_has_role" : {
          "account" : [ "site:current-user" ],
          "roles" : { "value" : { "6" : "6" } },
          "operation" : "OR"
        }
      },
      { "entity_has_field" : { "entity" : [ "commerce-line-item" ], "field" : "commerce_product" } },
      { "component_rules_product_is_magazine" : { "product" : [ "commerce-line-item:commerce-product" ] } },
      { "commerce_order_is_cart" : { "commerce_order" : [ "site:current-cart-order" ] } },
      { "commerce_order_contains_product_type" : {
          "commerce_order" : [ "site:current-cart-order" ],
          "product_type" : { "value" : { "magazine" : "magazine" } },
          "operator" : "\u003E=",
          "value" : "2"
        }
      }
    ],
    "DO" : [
      { "commerce_line_item_unit_price_multiply" : {
          "commerce_line_item" : [ "commerce_line_item" ],
          "amount" : ".75",
          "component_name" : "discount",
          "round_mode" : "1"
        }
      }
    ]
  }
}

This rule work fine but the field_mag_type == 'tipo' check is missing because I don't know how to check a field in all products in the cart and count if they are > 2.

If I can't solve this I'm bound to clone the 'magazine' product type and add a new one with the same fields.. but I want to avoid it..

1

You should use the Calculating the sell price of a product event instead of the add to cart event.

The use case you are trying to implement is actually discussed in the commerce users guide. If you fail to make your rule work after going through the documentation, then please update your question with the exported rule.

  • In this users guide I do not find a solution to this issues. I readed it before write here. For now I didn't figure how to solve this.. I can export the rule I wrote but is not working like I want.. – Shyghar Dec 2 '13 at 10:29
  • @Shyghar: Please export it nevertheless and post it in your question. Like this it is possible for other people to take a close look at it. – znerol Dec 2 '13 at 10:42

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.