0

I am working with Drupal Commerce and Commerce Billy to generate invoices. My question is :

In Complete checkout process I want to edit all orders status to "Invoiced" !! .

I already created this Rules Component and it works fine. With component I can add 1 order for me(admin) and other orders to user concerned , is that make sense.

So what I want to do is : after complete checkout process I want to change all these orders status to "invoiced"

{ "rules_add_prod_to_cart_6" : {
"LABEL" : "Add Prod to cart 6",
"PLUGIN" : "rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules", "commerce_cart" ],
"USES VARIABLES" : { "commerce_product" : { "label" : "Commerce Product", "type" : "commerce_product" } },
"IF" : [
  { "entity_has_field" : { "entity" : [ "commerce-product" ], "field" : "field_user_concerned" } }
],
"DO" : [
  { "commerce_cart_product_add_by_sku" : {
      "USING" : {
        "user" : [ "site:current-user" ],
        "sku" : "[commerce-product:sku]\t",
        "quantity" : "1",
        "combine" : "1"
      },
      "PROVIDE" : { "product_add_line_item" : { "product_add_line_item" : "Added product line item" } }
    }
  },
  { "commerce_cart_product_add_by_sku" : {
      "USING" : {
        "user" : [ "commerce-product:field-user-concerned" ],
        "sku" : "[commerce-product:sku]\t",
        "quantity" : "1",
        "combine" : "1"
      },
      "PROVIDE" : { "product_add_line_item" : { "product_add_line_item2" : "Added product line item 2" } }
    }
  }
]

} }

Example :
SKU | Label | Price | User |
001 | Product 1 | $10 | Userexample1 |
002 | Product 2 | $40 | Userexample2 |
003 | Product 3 | $20 | Userexample1 |
004 | Product 4 | $70 | Userexample2 |

what I already done:

So after Clicking on "Add product and generate order" button :
In the above example I get 3 orders

the owner of the first order = [site:current-user] and it will return :
All Products (Product1,Product2,Product3,Product4)

The owner of the second order = Userexample1 and it will contain
Product1 and Product 3

The owner of the last order = Userexample2 and it it will contain
Product2 and product 4

So the order status of all those orders = Shopping cart (because we didn't complete the checkout yet), and when we complete the checkout it will change ONLY the FIRST ORDER status to "Invoiced", because [site:current-user] is the owner of it.

I want to change all the above orders status when "Complete checkout process" event is fired !

Please see images below:

After Clicking on "Add products to cart and generate orders" enter image description here

"New 3 orders" enter image description here

Complete checkout process enter image description here

First order status = Invoiced , BUT THE TWO OTHERS DOSEN'T CHANGE enter image description here

Is that possible ? How could I do that using Rules Module ?

9
  • @Pierre.Vriens , Thanks for your answer , it's a drupal 7
    – Media WEB
    Feb 20, 2017 at 16:16
  • @Pierre.Vriens Oh sorry it was my fault , I am a new member here , and I really not sure how things work here , anyway thanks !
    – Media WEB
    Feb 20, 2017 at 17:05
  • No need for sorry, and merci for accepting my advice (and the update of your question). Yes it's not obvious to get used to the Rrrrrrrules of this site (getting started with Drupal may seem easier ...). Feb 20, 2017 at 17:22
  • Thanks , Do you have any idea about " How could I do that using Rules module to change all orders status to "Invoiced" when "Complete checkout process" event is fired ?
    – Media WEB
    Feb 20, 2017 at 17:25
  • 1
    I don't "like" chat ... you cannot "delete" anything in there anymore, and I've trouble using its UI. Can you please try to EDIT your question to further improve it (ie to make me less confused)? Feb 20, 2017 at 17:58

1 Answer 1

0

I fixed this issue by adding this PHP code:

$orders = commerce_order_load_multiple(array(), array('status'=>'cart'), TRUE); foreach($orders as $order){ $order_wrapper = entity_metadata_wrapper('commerce_order', $order); foreach($order_wrapper->commerce_line_items as $line_item_wrapper){ $product = $line_item_wrapper->commerce_product; $node_product = $node_wrapper->field_product; $order_wrapper->status = 'invoiced'; $line_item_wrapper->save(); $order_wrapper->save(); } }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.