3

I have multiple restaurants with each another value for minimum order price, this is a custom price field in the content type "Restaurants".

I would need to make a rule where the total order amount is compared to this custom price field. If the total from the order is lower, it should redirect and throw a message.

The problem here is that I don't know what entities to use to get access to the custom price field named "field_leveringsprijs".

The event is on payment selection or checkout completion. The actions would be a page redirect and a message which isn't hard to do. I'm just stuck with the conditions 'Entity has field' and 'Data comparison'.

Any suggestions?

enter image description here

0

I'm assuming that your field_leveringsprijs (with "levering" = delivery, and "prijs" = price) corresponds to your minimum order price of your Restaurants content type.

If such field is not available as a token to use it in a Rules Condition, then the typical approach/solution is to use the Rules Action (not Rules Condition ...) "Fetch entity by id". So if you do have the id of the Retaurant available, just fetch the Restaurant (=some node of content type Restaurants). That will make all its fields, such as your field_leveringsprijs field, available for subsequent processing.

But, such Fetch entity by id is a Rules Action, so that's like you're too late to use the result of that Rules Action within the typical Rules Conditions (as you are trying to do in the data comparison shown in your question). The way to get around that, is to use either of following approaches:

  • Use the Conditional Rules module, which basically allows you to add a Rules Condition as part of the Rules Actions you want to perform. So using this module/technique, you'd specify something equivalent to "if order total is below field_leveringsprijs". And then add the actual Rules Actions you want to perform in that case (= perform a redirect, and show some message).
  • Create a Rules Component in which you execute (as Rules Actions) those actions such as that redirect and display a message). But which also includes a Rules Condition equivalent to "if order total is below field_leveringsprijs". And (this is crucial!) make sure to pass a "parameter" to this Rules Component, which will reprezent your field_leveringsprijs (with same data type). After you QA-tested your Rules Component, go back to your original Rule, and simply execute that Rules Component, by passing the appropriate value of the Rules Component parameter, using ... indeed ... your field_leveringsprijs (which you got via that "Fetch entity by id", remember?).

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.