There is a rule "Assign an anonymous order to a pre-existing user", but not "Assign an anonymous invoice to a pre-existing user". So result is that when anonymous customer makes an order, generated invoice is saved for user/0 aka anonymous, not to user account which e-mail was used to make this order. So Commerce Invoice needs rule like "Assign an anonymous order to a pre-existing user".

I tried to make it myself, but can't make it work.
I need it for my custom invoice view.

CommentFileSizeAuthor
invoice_uid.jpg138.49 KBUrmasZ
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

NecroHill’s picture

I am facing exactly the same issue on beta and dev version, no issues with registered users though. any ideas how to resolve it?

NecroHill’s picture

this module does not assign an invoice to a pre-existing user on my configuration as I set the "Update the order status on checkout completion" rule to set orders status to completed instead of pending (for non-shippable products) - it works ok when you change orders status from pending to completed manually

C-Logemann’s picture

Category: task » feature

When you are using a workflow where invoices should be generated before assigning existing users to order then you need a solution.
But I think this is a feature request.

sportel’s picture

I agree, this should be a feature request. I'm generating invoices when the order status is set to pending, so that a customer gets an invoice before he made a payment and the order status is set to complete. That works fine, until an existing customer makes a new order without logging in first.
I believe my workflow is quite common.

Mike.

sportel’s picture

Issue summary: View changes

I've solved this issue (I think) with a simple Rules Component:

{ "rules_create_an_invoice" : {
    "LABEL" : "Create an invoice",
    "PLUGIN" : "rule",
    "REQUIRES" : [ "commerce_invoice", "rules" ],
    "USES VARIABLES" : { "order" : { "label" : "order", "type" : "commerce_order" } },
    "IF" : [
      { "NOT commerce_invoice_exists" : { "commerce_order" : [ "order" ] } },
      { "NOT data_is" : { "data" : [ "order:uid" ], "value" : "0" } }
    ],
    "DO" : [ { "commerce_invoice_generate" : { "commerce_order" : [ "order" ] } } ]
  }
}

This Rules Component creates an invoice for a given Commerce Order. Now you can add this Rules Component with a new action to every rule that creates an order (e.g.: Assign an anonymous order to a pre-existing user, Create a new account for an anonymous order).
Make sure it's the last action of that rule.

Perhaps it's wise to add a condition to the standard rule (for creating an invoice) to make sure an invoice is never created with UID = 0. A rules link could be added to the Orders View to create an invoice manually for when this happens?

Please let me know what you think.

Mike.

C-Logemann’s picture

Status: Active » Needs review

When the rule works fine it can be included as default rule by code. But there should be some testing and reviewing before.
Because it's a rule it can be tested by copy and paste. So I ignore that there isn't currently a patch provided. But if somebody wants to get this faster into code (s)he should provide additionally a patch.

sportel’s picture

It works for me, but I'd like some confirmation.

steveoriol’s picture

Hello Sportel,
I comfirme to you, Your Rules works for me too on an production site.
Big Merci.

sportel’s picture

@steveoriol,

Thanks for confirming. It's up to the maintainer of this module now to decide if the rule should be included.

Mike.

dwkitchen’s picture

Status: Needs review » Closed (won't fix)

Closing all Drupal 7 issues as this project will only be supported for Drupal 8