1

In a webshop I’ve build I want to send individual e-mails to owners of a prodruct in the shop after a product is sold. To do this I got this as a solution: Send mail to product owner with Rules

But with this I’m only able to send the product owner an e-mail about the product. I am not able to add a shipping/billing address or mailadres form the customer profile to it.

When I try to add the customer profile as a parameter to the component the rules breaks and doesn't work anymore.

This is an export of my component:

{ "rules_perform_an_action_on_a_selected_line_item" : {
    "LABEL" : "Perform an action on a selected line item",
    "PLUGIN" : "rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "mimemail" ],
    "USES VARIABLES" : {
      "selected_line_item" : { "label" : "Selected Line Item", "type" : "commerce_line_item" },
      "commerce_order" : { "label" : "Commerce Order", "type" : "commerce_order" },
      "commerce_customer" : { "label" : "Commerce Customer", "type" : "commerce_customer_profile" }
    },
    "IF" : [
      { "entity_has_field" : { "entity" : [ "selected-line-item" ], "field" : "commerce_product" } }
    ],
    "DO" : [
      { "entity_fetch" : {
          "USING" : {
            "type" : "commerce_product",
            "id" : [ "selected-line-item:commerce-product:product-id" ]
          },
          "PROVIDE" : { "entity_fetched" : { "product_fetched" : "Fetched Product" } }
        }
      },
      { "entity_fetch" : {
          "USING" : { "type" : "commerce_customer_profile", "id" : [ "commerce-order:uid" ] },
          "PROVIDE" : { "entity_fetched" : { "entity_fetched" : "Fetched user" } }
        }
      },
      { "drupal_message" : { "message" : "Product Mail = [product-fetched:field-e-mailadres-product]" } },
      { "mimemail" : {
          "key" : "[commerce-order:order-id]",
          "to" : "[product-fetched:field-e-mailadres-product]",
          "subject" : "Product order",
          "body" : "OUTPUT PRODUCT INFORMATION AND USER INFORMATION HERE",
          "language" : [ "" ]
        }
      }
    ]
  }
}

This is the export of my rule to loop trough the line-items:

{ "rules_send_mail_to_product_owner" : {
    "LABEL" : "Send mail to product owner",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "TAGS" : [ "Custom" ],
    "REQUIRES" : [ "rules", "entity" ],
    "ON" : { "commerce_order_presave" : [] },
    "DO" : [
      { "LOOP" : {
          "USING" : { "list" : [ "commerce-order:commerce-line-items" ] },
          "ITEM" : { "line_items" : "Commerce Line Items" },
          "DO" : [
            { "component_rules_perform_an_action_on_a_selected_line_item" : { "selected_line_item" : [ "line-items" ] } }
          ]
        }
      }
    ]
  }
}

I set the rules action to order presave as this is the easiest way testing the rule, in the end it should run on when payment is first payed in full.

The rule isn't running because of my fault in the parameter settings the parameter commerce_customer is giving problems, I get an error that says: "Missing configuration for parameter commerce_customer".

How can I get to this information in my component?

2
  • Can you expand (edit) your question to also include an export of the rule and rules component you already have so far? And also provide more details about that "rules breaks" (like what error are you getting or something similar)? – Pierre.Vriens Jul 24 '18 at 15:35
  • Of course, just added more information. – Joost Jul 25 '18 at 20:16
0

The rule isn't running because of my fault in the parameter settings the parameter commerce_customer is giving problems, I get an error that says: "Missing configuration for parameter commerce_customer".

How can I get to this information in my component?

It looks like you have a mismatch in the variables of your rules component (which has 3 of them) and the rule which invokes that rules component (which only passes a value for the first variable selected_line_item).

Here is what I suggest you try to get the 2 remaining variables for your rules component fixed:

  • commerce_order: in your rule (which invokes the rules component), add the value of it as your 2nd variable (to actually pass that value to your rules component). For sure you have a token available to actually pass it (= commerce-order), since your rule already refers to commerce-order:commerce-line-items also (which you would not be able to do if you wouldn't have commerce-order).

  • commerce_customer: just remove (delete) that as your 3rd variable in your rules component. It seems you don't need to "pass" that as a variable, as per the (2nd) entity_fetch included in your rules component. Whereas this (2nd) entity_fetch will return you that entity_fetched (BTW, a terribly bad name IMO, consider changing that to something more meaningful like fetched_user, or even better fetched_customer).

    Whatever you end up using (i.e. entity_fetched, fetched_user, or fetched_customer) that's what you can then use within the body of your eMail (any of the tokens related to it).

1
  • I finally ended up deleting the commerce_customer and changing the second entity_fetch to fetch the commerce-order:order-id instead of the commerce-order:uid from this fetch it was possible to get the customers' email address and billing/shipping information. – Joost Aug 27 '18 at 12:46

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.