# Get order number in plugin after order is placed

**URL:** https://forum.shopware.com/t/get-order-number-in-plugin-after-order-is-placed/53293
**Category:** International (English Only)
**Tags:** programming
**Created:** [5. Juni 2018 um 16:00 UTC](https://forum.shopware.com/t/get-order-number-in-plugin-after-order-is-placed/53293 "2018-06-05T16:00:38Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![roberto](https://avatars.discourse-cdn.com/v4/letter/r/8baadc/32.png) [@roberto](https://forum.shopware.com/u/roberto)
#### Post date: [5. Juni 2018 um 16:00 UTC](https://forum.shopware.com/t/get-order-number-in-plugin-after-order-is-placed/53293/1 "2018-06-05T16:00:38Z")

</div>

Hi,

I’m trying to get the order number after an order is placed in my shop to send that to a different place the problem is I can’t find the correct event to get this. I’ve been trying with ‘Enlight\_Controller\_Action\_Frontend\_Checkout\_Finish’ and ‘Shopware\_Modules\_Order\_SaveOrder\_ProcessDetails’ but sOrderNumber doesn’t seem to be defined at that point. Is there any other event to which I can subscribe to?

Thanks

---

<div class="post-metadata">

### Author: ![Moritz\_Naczenski](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/moritz_naczenski/32/7792_2.png) [@Moritz\_Naczenski](https://forum.shopware.com/u/Moritz_Naczenski)
#### Post date: [5. Juni 2018 um 16:17 UTC](https://forum.shopware.com/t/get-order-number-in-plugin-after-order-is-placed/53293/2 "2018-06-05T16:17:54Z")

</div>

Hi,

have you tried using the same way the core gets the ordernumber?

> <https://github.com/shopware/shopware/blob/bafaa350a794ea9c24246891a3e4e15e801288f1/engine/Shopware/Core/sOrder.php#L834>

It should be in the Session at that time. Try something like:

```
$sOrder = $this->container->get('session')->offsetGet('sOrderVariables');

```

Otherwhise&nbsp;Shopware\_Modules\_Order\_SendMail\_FilterVariables has the ordernumber too.

---

<div class="post-metadata">

### Author: ![roberto](https://avatars.discourse-cdn.com/v4/letter/r/8baadc/32.png) [@roberto](https://forum.shopware.com/u/roberto)
#### Post date: [5. Juni 2018 um 16:23 UTC](https://forum.shopware.com/t/get-order-number-in-plugin-after-order-is-placed/53293/3 "2018-06-05T16:23:06Z")

</div>

Hi [@Moritz Naczenski]([http://forum.shopware.com/profile/14574/Moritz](http://forum.shopware.com/profile/14574/Moritz) Naczenski “Moritz Naczenski”)‍

Yes I’m using something like this (and after your comment tried exactly that) but still not getting the order number, it’s not defined in sOrderVariables but if I refresh the page and resend the information the order number is there, so I think it’s because I’m using Enlight\_Controller\_Action\_Frontend\_Checkout\_Finish and the order number is not saved yet?

---

<div class="post-metadata">

### Author: ![PogoWorks](https://avatars.discourse-cdn.com/v4/letter/p/3ab097/32.png) [@PogoWorks](https://forum.shopware.com/u/PogoWorks)
#### Post date: [5. Juni 2018 um 16:47 UTC](https://forum.shopware.com/t/get-order-number-in-plugin-after-order-is-placed/53293/4 "2018-06-05T16:47:25Z")

</div>

You can try get the order number with&nbsp; **Enlight\_Controller\_Action\_PostDispatchSecure\_Frontend\_Checkout\_Finish,&nbsp;** or maybe you can look working with the session:

$this-\>session = Shopware()-\>Session();  
$sOrderVariables = $this-\>session[‘sOrderVariables’]-\>getArrayCopy()

In this way you have complete order variables where it is also included sOrderNumber.

---

<div class="post-metadata">

### Author: ![roberto](https://avatars.discourse-cdn.com/v4/letter/r/8baadc/32.png) [@roberto](https://forum.shopware.com/u/roberto)
#### Post date: [5. Juni 2018 um 16:57 UTC](https://forum.shopware.com/t/get-order-number-in-plugin-after-order-is-placed/53293/5 "2018-06-05T16:57:47Z")

</div>

I must be doing something really wrong because still can’t see the order number. Let me share some code with you guys and see, this is part of my code

```
public static function getSubscribedEvents()
  {
      return [
          'Enlight_Controller_Action_PostDispatchSecure_Frontend_Checkout_Finish' => 'onProcessDetails'
      ];
  }

public function onProcessDetails(\Enlight_Event_EventArgs $args)
{
      
      $this->session = Shopware()->Session();
      $sOrderVariables = $this->session['sOrderVariables']->getArrayCopy();
      
      var_dump($sOrderVariables);
}

```

I’m able to see all the order details but the order number

---

<div class="post-metadata">

### Author: ![PogoWorks](https://avatars.discourse-cdn.com/v4/letter/p/3ab097/32.png) [@PogoWorks](https://forum.shopware.com/u/PogoWorks)
#### Post date: [5. Juni 2018 um 17:16 UTC](https://forum.shopware.com/t/get-order-number-in-plugin-after-order-is-placed/53293/6 "2018-06-05T17:16:19Z")

</div>

In your case, I think it is better to go with&nbsp; **Sendmail\_FilterVariables** &nbsp;- ‘Shopware\_Modules\_Order\_SendMail\_FilterVariables’ =\> ‘onSaveOrder’

you can also find some inspiration&nbsp;here:&nbsp;[Advanced Example how to create 2 custom fields, fill them in order process, display them in backend order list as new columns and make them editable in order detail view · GitHub](https://gist.github.com/sthamann/5343247)

---

<div class="post-metadata">

### Author: ![roberto](https://avatars.discourse-cdn.com/v4/letter/r/8baadc/32.png) [@roberto](https://forum.shopware.com/u/roberto)
#### Post date: [5. Juni 2018 um 17:22 UTC](https://forum.shopware.com/t/get-order-number-in-plugin-after-order-is-placed/53293/7 "2018-06-05T17:22:08Z")

</div>

Still getting same information but no the order number. I’m using cash on delivery as payment method, don’t know if this has anything to do with my problem

---

<div class="post-metadata">

### Author: ![Moritz\_Naczenski](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/moritz_naczenski/32/7792_2.png) [@Moritz\_Naczenski](https://forum.shopware.com/u/Moritz_Naczenski)
#### Post date: [5. Juni 2018 um 17:29 UTC](https://forum.shopware.com/t/get-order-number-in-plugin-after-order-is-placed/53293/8 "2018-06-05T17:29:32Z")

</div>

&nbsp;Shopware\_Modules\_Order\_SendMail\_FilterVariables worked for me. With this event you do not need to access the session, because it is directly in the filtered variable.&nbsp;I can check the other cases tomorrow.

---

<div class="post-metadata">

### Author: ![PogoWorks](https://avatars.discourse-cdn.com/v4/letter/p/3ab097/32.png) [@PogoWorks](https://forum.shopware.com/u/PogoWorks)
#### Post date: [5. Juni 2018 um 17:34 UTC](https://forum.shopware.com/t/get-order-number-in-plugin-after-order-is-placed/53293/9 "2018-06-05T17:34:05Z")

</div>

No, the payment it is not an issue if it is cash or something else.

As [Moritz Naczenski](https://forum.shopware.com/profile/14574/Moritz%20Naczenski)&nbsp;says, also on mine side it is working properly, but the question it is after you click on submit order&nbsp;button and you go to the backend you can find the order there or just you’ve got an error before order confirmation ?..

---

<div class="post-metadata">

### Author: ![Moritz\_Naczenski](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/moritz_naczenski/32/7792_2.png) [@Moritz\_Naczenski](https://forum.shopware.com/u/Moritz_Naczenski)
#### Post date: [5. Juni 2018 um 18:07 UTC](https://forum.shopware.com/t/get-order-number-in-plugin-after-order-is-placed/53293/10 "2018-06-05T18:07:00Z")

</div>

I tried it like this (in the new plugin system):

```
scheduleClearCache(ActivateContext::CACHE_LIST_DEFAULT);
    }
    public function deactivate(DeactivateContext $context)
    {
        $context->scheduleClearCache(DeactivateContext::CACHE_LIST_DEFAULT);
    }
    public static function getSubscribedEvents()
    {
        return [
            'Shopware_Modules_Order_SendMail_FilterVariables' => 'onOrdermail',
        ];
    }

    public function onOrdermail(\Enlight_Event_EventArgs $args)
    {
        $variables = $args->getReturn();
        $sOrder = $this->container->get('session')->offsetGet('sOrderVariables');

        die(print_r($variables));
    }
}

```

Both ways (from session and filterevent) worked for me.

---

<div class="post-metadata">

### Author: ![roberto](https://avatars.discourse-cdn.com/v4/letter/r/8baadc/32.png) [@roberto](https://forum.shopware.com/u/roberto)
#### Post date: [6. Juni 2018 um 06:10 UTC](https://forum.shopware.com/t/get-order-number-in-plugin-after-order-is-placed/53293/11 "2018-06-06T06:10:24Z")

</div>

Thank you very much, it is working now! Still can’t see it on the session but it’s on the the filterevent
