Hello,

I am using drupal 7.12 with commerce module.
I have added a field of text type to User type that I am using it to store the users phone number. I have a rule assigns an order made from an anonymous user to an existing user if the phone field matches a users phone number.
The rule is as follows:

{ "rules_assign_an_anonymous_order_to_a_pre_existing_user_cell_" : {
    "LABEL" : "Assign an anonymous order to a pre-existing user (cell)",
    "PLUGIN" : "reaction rule",
    "WEIGHT" : "2",
    "ACTIVE" : false,
    "REQUIRES" : [ "rules", "commerce_checkout" ],
    "ON" : [ "commerce_checkout_complete" ],
    "IF" : [
      { "data_is" : { "data" : [ "commerce-order:uid" ], "value" : "0" } },
      { "data_is" : { "data" : [ "commerce-order:type" ], "value" : "commerce_order" } },
      { "entity_has_field" : {
          "entity" : [ "commerce-order:commerce-customer-billing" ],
          "field" : "field_cellphone"
        }
      },
      { "entity_exists" : {
          "type" : "user",
          "property" : "field_cellphone",
          "value" : [ "commerce-order:commerce-customer-billing:field-cellphone" ]
        }
      }
    ],
    "DO" : [
      { "entity_query" : {
          "USING" : {
            "type" : "user",
            "property" : "field_cellphone",
            "value" : [ "commerce-order:commerce-customer-billing:field-cellphone" ],
            "limit" : "1"
          },
          "PROVIDE" : { "entity_fetched" : { "account_fetched" : "Fetched account" } }
        }
      },
      { "LOOP" : {
          "USING" : { "list" : [ "account-fetched" ] },
          "ITEM" : { "list_item" : "Current list item" },
          "DO" : [
            { "data_set" : { "data" : [ "commerce-order:uid" ], "value" : [ "list-item:uid" ] } },
            { "data_set" : {
                "data" : [ "commerce-order:commerce-customer-billing:uid" ],
                "value" : [ "list-item:uid" ]
              }
            }
          ]
        }
      }
    ]
  }
}

When this rule fires I get an exception in the system log saying that there is no column field_cellphone in the user table, which is ofcource true, as it is stored in its own table with a foreign key.

|PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'users.field_cellphone' in 'where clause': SELECT users.uid AS entity_id, :entity_type AS entity_type, NULL AS revision_id, :bundle AS bundle FROM {users} users WHERE (users.field_cellphone = :db_condit on_placeholder_0) LIMIT 1 OFFSET 0; Array ( [:db_condition_placeholder_0] => 6999999999 [:entity_type] => user [:bundle] => user ) in EntityFieldQuery->execute() (line 1136 of /var/www/html/includes/entity.inc)

I have done the exact same thing using the users email in another rule and it works flawlessly:

{ "commerce_checkout_order_convert" : {
    "LABEL" : "Assign an anonymous order to a pre-existing user",
    "PLUGIN" : "reaction rule",
    "WEIGHT" : "1",
    "REQUIRES" : [ "rules", "commerce_checkout" ],
    "ON" : [ "commerce_checkout_complete" ],
    "IF" : [
      { "data_is" : { "data" : [ "commerce-order:uid" ], "value" : "0" } },
      { "entity_exists" : {
          "type" : "user",
          "property" : "mail",
          "value" : [ "commerce-order:mail" ]
        }
      },
      { "data_is" : { "data" : [ "commerce-order:type" ], "value" : "commerce_order" } }
    ],
    "DO" : [
      { "entity_query" : {
          "USING" : {
            "type" : "user",
            "property" : "mail",
            "value" : [ "commerce-order:mail" ],
            "limit" : 1
          },
          "PROVIDE" : { "entity_fetched" : { "account_fetched" : "Fetched account" } }
        }
      },
      { "LOOP" : {
          "USING" : { "list" : [ "account-fetched" ] },
          "ITEM" : { "list_item" : "Current list item" },
          "DO" : [
            { "data_set" : { "data" : [ "commerce-order:uid" ], "value" : [ "list-item:uid" ] } },
            { "data_set" : {
                "data" : [ "commerce-order:commerce-customer-billing:uid" ],
                "value" : [ "list-item:uid" ]
              }
            }
          ]
        }
      }
    ]
  }
}

Comments

TR’s picture

Status: Active » Postponed (maintainer needs more info)

Is this still a problem with the current version of Rules? There haven't been any further reports of a problem, and no comments from the Commerce side of things, so I suspect this has been fixed long ago or was a problem with Commerce or was a configuration problem or something along those lines.

TR’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)