How to make Drupal Commerce send email notification to the author of products sold? I use Drupal Commerce and the rules module to send email which works OK. But it doesn't send the email to author node of product.

Here is an export of my current rule:

{ "commerce_checkout_order_email" : {
    "LABEL" : "Send an order notification e-mail",
    "PLUGIN" : "reaction rule",
    "WEIGHT" : "4",
    "OWNER" : "rules",
    "TAGS" : [ "Commerce Checkout" ],
    "REQUIRES" : [ "rules", "mimemail", "commerce_checkout" ],
    "ON" : { "commerce_checkout_complete" : [] },
    "DO" : [
      { "mimemail" : {
          "USING" : {
            "key" : "emailrenzo",
            "to" : "[commerce-order:mail]",
            "from_name" : "Regalalo",
            "from_mail" : "info@regalalo.pe",
            "subject" : "Pedido # [commerce-order:order-number] en [site:name]",
            "body" : "\u003Cdiv\u003E\r\n\u003Cimg src=\u0022\/http:\/\/34.214.32.99\/sites\/default\/files\/logo-regalalo.png\u0022\u0022\u003E\r\n\u003C\/div\u003E\r\n\r\nHola [commerce-order:owner]!!\r\ngracias por realizar un pedido en [site:name], su n\u00famero de pedido es # [commerce-order:order-number].\r\n\r\nSi este es su primer pedido con nosotros, pronto recibir\u00e1 otro correo electr\u00f3nico con las instrucciones para acceder a nuestro sitio con su nombre de usuario y contrase\u00f1a. Puede ver su historial de pedidos en cualquier momento ingresando a nuestro sitio web:\r\n\r\n[site:login-url]\r\n\r\nPuede consultar el estado de su pedido en:\r\n\r\n\u003Ctable cellspacing=\u00220\u0022 cellpadding=\u002210\u0022 border=\u00221\u0022\u003E\u003Ctr\u003E\u003Ctd\u003E\u003Ctable cellspacing=\u00220\u0022 cellpadding=\u002210\u0022 border=\u00221\u0022\u003E\u003Ctr\u003E\u003Ctd\u003E[commerce-order:commerce_line_items]\u003C\/td\u003E\u003C\/tr\u003E\u003C\/table\u003E\u003C\/td\u003E\u003C\/tr\u003E\u003C\/table\u003E\r\n\r\n[commerce-order:customer-url]\r\n\r\nPor favor comun\u00edquese con nosotros si tiene alguna duda.\r\n\r\n\u00a1Gracias por comprar en nuestra plataforma! Vuelve a visitarnos aqu\u00ed: Regalalo.PE\r\nSi tienes alguna pregunta acerca de tu pedido, contacta la tienda del producto que tendr\u00e1 el agrado de atenderte. \r\nPara otra consulta de asistencia env\u00edanos un correo a \u003Ca href=\u0022mailto:info@regalalo.pe\u0022\u003E info@regalalo.pe\u003C\/a\u003E\r\n",
            "language" : [ "commerce-order:state" ]
          },
          "PROVIDE" : { "send_status" : { "send_status" : "Send status" } }
        }
      },
      { "mail" : {
          "to" : [ "commerce-order:owner:mail" ],
          "subject" : "Pedido # [commerce-order:order-number] en [site:name]",
          "message" : "Hola [commerce-order:owner]!!\r\nGracias por realizar un pedido en [site:name], su n\u00famero de pedido es # [commerce-order:order-number].\r\n\r\nSi este es su primer pedido con nosotros, pronto recibir\u00e1 otro correo electr\u00f3nico con las instrucciones para acceder a nuestro sitio con su nombre de usuario y contrase\u00f1a. Puede ver su historial de pedidos en cualquier momento ingresando a nuestro sitio web:\r\n\r\n[site:login-url]\r\n\r\nPuede consultar el estado de su pedido en:\r\n\r\n[commerce-order:commerce_line_items]\r\n\r\n[commerce-order:customer-url]\r\n\r\nPor favor comun\u00edquese con nosotros si tiene alguna duda.\r\n\r\n\u00a1Gracias por comprar en nuestra plataforma! Vuelve a visitarnos aqu\u00ed: Regalalo.PE\r\nSi tienes alguna pregunta acerca de tu pedido, contacta la tienda del producto que tendr\u00e1 el agrado de atenderte. \r\nPara otra consulta de asistencia env\u00edanos un correo a \u003Ca href=\u0022mailto:info@regalalo.pe\u0022\u003E info@regalalo.pe\u003C\/a\u003E",
          "language" : [ "commerce-order:state" ]
        }
      }
    ]
  }
}


This rule works with user customer but not sellerr or authors, what´s your recommendation?
In short; you should loop over all commerce order line items, obtain the product owner and add it to a list. Then in a new loop, go through the created list to send all product owners a main.

First you need a rules component that checks if a provided line item contains a product field and pushes the author to a given list (enforcing uniqueness makes sure every product owner is only added once). You can import below code on the components tab:

{ "rules_product_on_line_item" : {
    "LABEL" : "get product owner from line item",
    "PLUGIN" : "rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "USES VARIABLES" : {
      "line_item" : { "label" : "Line item", "type" : "commerce_line_item" },
      "owners" : { "label" : "Product owners", "type" : "list\u003Cuser\u003E" }
    },
    "IF" : [
      { "entity_has_field" : { "entity" : [ "line-item" ], "field" : "commerce_product" } }
    ],
    "DO" : [
      { "list_add" : {
          "list" : [ "owners" ],
          "item" : [ "line-item:commerce-product:creator" ],
          "unique" : "1"
        }
      }
    ]
  }
}


Now for the main rule, create a new variable of type list of users. This is where we will store all product owners in.

Create a loop over commerce-order:commerce-line-items. In this loop, use the component that was created above. This will fill the list of product owners.

Finally, loop over the list of product owners, and send each of them a mail. The complete rule would look something like this:

{ "rules_mail_all_product_owners" : {
    "LABEL" : "Mail all product owners on an order",
    "PLUGIN" : "reaction rule",
    "WEIGHT" : "5",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "mimemail", "commerce_checkout" ],
    "ON" : { "commerce_checkout_complete" : [] },
    "DO" : [
      { "variable_add" : {
          "USING" : { "type" : "list\u003Cuser\u003E" },
          "PROVIDE" : { "variable_added" : { "product_owner_list" : "Product owner list" } }
        }
      },
      { "LOOP" : {
          "USING" : { "list" : [ "commerce-order:commerce-line-items" ] },
          "ITEM" : { "list_item" : "Current list item" },
          "DO" : [
            { "component_rules_product_on_line_item" : { "line_item" : [ "list-item" ], "owners" : [ "product-owner-list" ] } }
          ]
        }
      },
      { "LOOP" : {
          "USING" : { "list" : [ "product-owner-list" ] },
          "ITEM" : { "productowner" : "Current product owner" },
          "DO" : [
            { "mimemail" : {
                "key" : "mailkey",
                "to" : [ "productowner:mail" ],
                "from_mail" : [ "site:mail" ],
                "subject" : "",
                "body" : ""
              }
            }
          ]
        }
      }
    ]
  }
}