# doppelte Ordermail bei Backend Bestellugen SW Plugin

**URL:** https://forum.shopware.com/t/doppelte-ordermail-bei-backend-bestellugen-sw-plugin/34019
**Category:** Programmierung
**Created:** [28. Januar 2016 um 15:52 UTC](https://forum.shopware.com/t/doppelte-ordermail-bei-backend-bestellugen-sw-plugin/34019 "2016-01-28T15:52:36Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Creatixx](https://avatars.discourse-cdn.com/v4/letter/c/c67d28/32.png) [@Creatixx](https://forum.shopware.com/u/Creatixx)
#### Post date: [28. Januar 2016 um 15:52 UTC](https://forum.shopware.com/t/doppelte-ordermail-bei-backend-bestellugen-sw-plugin/34019/1 "2016-01-28T15:52:36Z")

</div>

Hallo,  
wer das Plugin Backend Bestellungen (aktuelle Version 1.0&nbsp;von SW einsetzt, der hat das Problem das die Bestellbestätigungsmail **2 mal** an den Kunden gesendet wird.

Als Beispiel:  
erste Mail: [kunde@kundenmail.de](mailto:kunde@kundenmail.de)  
zweite Mail: [kunde@kundenmail.de](mailto:kunde@kundenmail.de), [office@meinshop.de](mailto:office@meinshop.de)

Also einmal Kundenemailadresse und einmal die, die in der Konfiguration des Shops hinterlegt ist.

Dazu gibt es seit längerem auch dieses [Ticket PT-3960](https://issues.shopware.com/#/issues/PT-3960?status=1&status=3&status=10001&status=4&status=10010&status=10025&status=10017&plugin=BackendOrder&projects=PT). **Vielleicht können hier ein paar voten um das Ganze etwas zu priorisieren!**

Zuständig dafür ist die folgende Funktion unter  
Pfad: /engine/Shopware/Plugins/Community/Backend/SwagBackendOrder/Controllers/Backend/SwagBackendOrder.php

```
private function sendOrderConfirmationMail($orderModel)
    {
        $context = $this->prepareOrderConfirmationMailData($orderModel);
        $context['sOrderDetails'] = $this->prepareOrderDetailsConfirmationMailData($orderModel);

        $mail = Shopware()->TemplateMail()->createMail('sORDER', $context);
        $mail->addTo($context["additional"]["user"]["email"]);
        $mail->send();

        //If configured send an email to the shop owner
        $mailNotToShopOwner = Shopware()->Config()->get('no_order_mail');
        if (!$mailNotToShopOwner) {
            $mail->addTo(Shopware()->Config()->get('mail'));
            $mail->send();
        }
    }

```

Ich habe nun folgendes im unteren Teil in der if Anweisung zusätzlich eingefügt:

```
        $mail = Shopware()->TemplateMail()->createMail('sORDER', $context);

```

Dadurch werden die eMails wieder korrekt versendet. Eine an den Shopadmin und eine an den Kunden. **Die Frage ist aber ob dieser Weg so ok ist, oder ob es hier eine bessere Vorgehensweise gibt?!**

Hier der komplette Code:

```
    private function sendOrderConfirmationMail($orderModel)
    {
        $context = $this->prepareOrderConfirmationMailData($orderModel);
        $context['sOrderDetails'] = $this->prepareOrderDetailsConfirmationMailData($orderModel);

        $mail = Shopware()->TemplateMail()->createMail('sORDER', $context);
        $mail->addTo($context["additional"]["user"]["email"]);
        $mail->send();

        //If configured send an email to the shop owner
        $mailNotToShopOwner = Shopware()->Config()->get('no_order_mail');
        if (!$mailNotToShopOwner) {
            $mail = Shopware()->TemplateMail()->createMail('sORDER', $context);
            $mail->addTo(Shopware()->Config()->get('mail'));
            $mail->send();
        }
    }

```

Gruß Creatixx

&nbsp;

PS: WOW geiler Editor!!!&nbsp; ![enlightened](https://europe1.discourse-cdn.com/flex013/uploads/shopware/original/1X/08ee70594855dd44287b011742fe7f1252e05ce0.png "enlightened")

---

<div class="post-metadata">

### Author: ![DanielNogel](https://avatars.discourse-cdn.com/v4/letter/d/96bed5/32.png) [@DanielNogel](https://forum.shopware.com/u/DanielNogel)
#### Post date: [28. Januar 2016 um 16:46 UTC](https://forum.shopware.com/t/doppelte-ordermail-bei-backend-bestellugen-sw-plugin/34019/2 "2016-01-28T16:46:46Z")

</div>

Hi,

ja, das erscheint mir sinnvoll, der Fehler ist ja, dass auf dem bestehenden Mail-Model gearbeitet wird - und die Methode “addTo” kein Setter, sondern ein “Adder” ist - darum bekommt der Kunde zwei Mails. Alternativ könnte es auch mit “$mail-\>clearRecipients()” gehen.

Besten Gruß,

Daniel

---

<div class="post-metadata">

### Author: ![Creatixx](https://avatars.discourse-cdn.com/v4/letter/c/c67d28/32.png) [@Creatixx](https://forum.shopware.com/u/Creatixx)
#### Post date: [28. Januar 2016 um 20:10 UTC](https://forum.shopware.com/t/doppelte-ordermail-bei-backend-bestellugen-sw-plugin/34019/3 "2016-01-28T20:10:29Z")

</div>

@Daniel Nögel

Danke für deine Bestätigung. Ich habe es jetzt mal auf&nbsp;$mail-\>clearRecipients(); umgestellt, und funktioniert auch wie gewünscht!&nbsp; ![no](https://europe1.discourse-cdn.com/flex013/uploads/shopware/original/1X/7fcda44f782696668a3d093569d15e88105769e1.png "no")

Gruß Creatixx

---

<div class="post-metadata">

### Author: ![don](https://avatars.discourse-cdn.com/v4/letter/d/ed655f/32.png) [@don](https://forum.shopware.com/u/don)
#### Post date: [7. August 2017 um 08:47 UTC](https://forum.shopware.com/t/doppelte-ordermail-bei-backend-bestellugen-sw-plugin/34019/4 "2017-08-07T08:47:56Z")

</div>

Es ist wirklich traurig, dass der Fehler immer noch aktiv ist und man bei jedem Update händisch nachsteuern muss.

---

<div class="post-metadata">

### Author: ![hbee](https://avatars.discourse-cdn.com/v4/letter/h/f08c70/32.png) [@hbee](https://forum.shopware.com/u/hbee)
#### Post date: [7. August 2017 um 18:23 UTC](https://forum.shopware.com/t/doppelte-ordermail-bei-backend-bestellugen-sw-plugin/34019/5 "2017-08-07T18:23:20Z")

</div>

eigentlich könntest du dir&nbsp;das 2. createMail sparen wenn du das send erst nach der if-abfrage ausführst.

ungetestet:

```
private function sendOrderConfirmationMail($orderModel)
    {
        $context = $this->prepareOrderConfirmationMailData($orderModel);
        $context['sOrderDetails'] = $this->prepareOrderDetailsConfirmationMailData($orderModel);

        $mail = Shopware()->TemplateMail()->createMail('sORDER', $context);
        $mail->addTo($context["additional"]["user"]["email"]);

        //If configured send an email to the shop owner
        $mailNotToShopOwner = Shopware()->Config()->get('no_order_mail');
        if (!$mailNotToShopOwner) {
            $mail->addTo(Shopware()->Config()->get('mail'));
        }

        $mail->send();

    }

```

&nbsp;
