2

I have a real estate website using the drealty module. In the real estate RETS feed, there is a numeric field called "Area". That numeric value refers to a specific area... for example, "22" might be "Miami Beach", and "32" might be "Miami Beach" and "South Beach".

When new real estate listings are created (via a command line in drush), I need for the corresponding "verbose" name of the area(s) to be selected from a specific taxonomy. For example, if the RETS feed returns "22" for the area value, then "Miami Beach" should be checked in that taxonomy field on the listings entities. Likewise, if the RETS feed returns "48", then both "Miami Beach" and "South Beach" should be checked.

I created a Rules Component for each area numerical value. The Miami Beach Rules Component is below:

 { "rules_set_area_miami_miami_beach" : {
 "LABEL" : "Set Area - Miami - Miami Beach",
 "PLUGIN" : "rule",
 "OWNER" : "rules",
 "REQUIRES" : [ "rules" ],
 "USES VARIABLES" : { "drealtylisting" : { "label" : "drealtylisting", "type" : "drealty_listing" } },
 "IF" : [
   { "entity_has_field" : { "entity" : [ "drealtylisting" ], "field" : "field_area" } },
   { "entity_has_field" : { "entity" : [ "drealtylisting" ], "field" : "field_area_taxonomy_" } },
   { "data_is" : {
       "data" : [ "drealtylisting:field-area" ],
       "op" : "IN",
       "value" : { "value" : [ "22", "32" ] }
     }
   }
 ],
 "DO" : [
   { "data_set" : {
       "data" : [ "drealtylisting:field-area-taxonomy-" ],
       "value" : { "value" : { "35" : "35" } }
     }
   }
  ]
 }
}

The same type of Rules Component exists for South Beach:

  { "rules_set_area_miami_south_beach" : {
  "LABEL" : "Set Area - Miami - South Beach",
  "PLUGIN" : "rule",
  "OWNER" : "rules",
  "REQUIRES" : [ "rules" ],
  "USES VARIABLES" : { "drealtylisting" : { "label" : "drealtylisting", "type" : "drealty_listing" } },
  "IF" : [
    { "entity_has_field" : { "entity" : [ "drealtylisting" ], "field" : "field_area" } },
    { "entity_has_field" : { "entity" : [ "drealtylisting" ], "field" : "field_area_taxonomy_" } },
    { "data_is" : {
        "data" : [ "drealtylisting:field-area" ],
        "op" : "IN",
        "value" : { "value" : [ "32" ] }
      }
    }
  ],
  "DO" : [
    { "data_set" : {
        "data" : [ "drealtylisting:field-area-taxonomy-" ],
        "value" : { "value" : { "23" : "23" } }
      }
    }
  ]
 }
}

I then created a Rule with Event "After saving a new drealty listing" and Actions: "rule: Set Area - Miami - Miami Beach" and "rule: Set Area - Miami - South Beach".

    { "rules_set_area_on_drealty_listing_cloned_" : {
    "LABEL" : "Set Area on Drealty Listing (cloned)",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "drealty" ],
    "ON" : { "drealty_listing_insert" : [] },
    "DO" : [
      { "component_rules_set_area_miami_miami_beach" : { "drealtylisting" : [ "drealty-listing" ] } },
      { "component_rules_set_area_miami_south_beach" : { "drealtylisting" : [ "drealty-listing" ] } }
    ]
  }
}

When I run a RETS import and the website creates the new listings, I expected it to evaluate each of those Rule actions in succession and check the taxonomy boxes when necessary, but instead it appears that only the South Beach Rule Action is taking effect, and thus only South Beach is checked in that field. Is this because it is listed last in the Rule action list? Is there a better way for me to set this up so that I can get the desired end result?

2 Answers 2

2

I see "data set" which I'm 99% sure means your field is either set to one value.. Or in taxonomy, it could mean that setting data overwrites previous values. So your rules might simply overwriting each other.

I can't remember much about taxonomy but change your field to infinite values if not already and use the rules action, " Add an item to list" if possible.

On a separate note, you should avail of the action "fetch entity by property" and only have maybe one rule for everything. So you'd add an integer field to your taxonomy terms and use the rules action to fetch it using the integer provided. Let me know if you want to try it.

1
  • Thanks, Niall. Your suggestion of using "Add item to list" worked very well.
    – hockey2112
    Feb 22, 2016 at 15:26
1

Below is a possible alternative to achieve the same result (as per your "Is there a better way for me to set this up so that I can get the desired end result?") ...

You might want to try to consolidate those 2 (similar) rules in a single rule, by using the Conditional Rules module: the condition for each rule would be replaced by a similar "if condition" (contained in the Rules Action), and the Rules action for each group would only be executed if the "if condition" would be true. For a sample using the Conditional Rules module (for which there is not a lot of docu available), refer to my answer to the question "How to prevent a node being saved when using the Rules module?".

Instead of using Conditional (if/else) logic within the Rules Action, you can also use Switch logic.

Be aware: this module only has a beta release for D7, though it's used in over 8K sites (which makes it seem like a pretty robust module though).

1
  • Thank you for this suggestion, Pierre. I will investigate it as an alternative to my current setup. Niall's suggestion of using "Add item to list" worked very well, so I am going to stick with that method for now.
    – hockey2112
    Feb 22, 2016 at 15:25

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.