Disable sending order email programmaticalyHow to send set password email?Order confirmation email sent multiple time - same order confirmation sent to all - unable to stop sendingOrder emails not sending to Sales Representative (store email address)Magento 1.9.2 not sending new order confirmation emailsEmail sending issue in Magento CE 1.9.2.1is we need to pay and return to site successfully to get paypal order confirmation emailMagento 2 - Place an order without sending emailMagento 2: Split order for every ItemSend emails after the order was placed - Magento 1.9Sending order confirmation email template in Magento 2

What does the homotopy coherent nerve do to spaces of enriched functors?

What is this object?

In Pandemic, why take the extra step of eradicating a disease after you've cured it?

How can I list the different hex characters between two files?

What do you call the action of "describing events as they happen" like sports anchors do?

Professor Roman loves to teach unorthodox Chemistry

Grandpa has another non math question

Why does there seem to be an extreme lack of public trashcans in Taiwan?

How can powerful telekinesis avoid violating Newton's 3rd Law?

ASCII Meme Arrow Generator

What is the STRONGEST end-of-line knot to use if you want to use a steel-thimble at the end, so that you've got a steel-eyelet at the end of the line?

Why do (or did, until very recently) aircraft transponders wait to be interrogated before broadcasting beacon signals?

Is Jesus the last Prophet?

How do I type a hyphen in iOS 12?

Parsing text written the millitext font

Make Gimbap cutter

How much web presence should I have?

Why is it bad to use your whole foot in rock climbing

What is this Amiga 2000 mod?

What does "lit." mean in boiling point or melting point specification?

What's the difference between DHCP and NAT? Are they mutually exclusive?

That's not my X, its Y is too Z

Am I allowed to determine tenets of my contract as a warlock?

Realistic, logical way for men with medieval-era weaponry to compete with much larger and physically stronger foes



Disable sending order email programmaticaly


How to send set password email?Order confirmation email sent multiple time - same order confirmation sent to all - unable to stop sendingOrder emails not sending to Sales Representative (store email address)Magento 1.9.2 not sending new order confirmation emailsEmail sending issue in Magento CE 1.9.2.1is we need to pay and return to site successfully to get paypal order confirmation emailMagento 2 - Place an order without sending emailMagento 2: Split order for every ItemSend emails after the order was placed - Magento 1.9Sending order confirmation email template in Magento 2






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















For some reason, I'm splitting my order in two part (the first is handle by some organization and the other will me handle by the magento owner).



I'm creating programmatically the order, and for one of the part, I need to stop the mail of the order to be sended.



Example :
In quote : watch, Tv, video game.
Splitting in two parts :



  1. watch, tv

  2. video games

Send email for the watch and tvs
Not send mail for video game.



How can I do this ?



EDIT : i'm splitting my code by doing a foreach on the quote item. If the item is in a category, I create a array with those items.



Then I'm creating my order like this : https://www.rakeshjesadiya.com/how-to-create-order-programmatically-in-magento-2/



And i'm calling the method twice, one for the first part, the other for the second.



I've notice that the email is not sended for the second part if I have placed those 2 orders parts. That's ok I guess, but if the first part is not placed, the second part will send a mail.










share|improve this question
























  • Are you able to split the order base on this logic

    – Amit Bera
    Jun 5 at 9:37











  • share the code which you used for split the order.

    – Dhiren Vasoya
    Jun 5 at 9:44











  • I've added an explanation and a link to my methods (my code is exactly the same)

    – Morgan Tartreau
    Jun 5 at 9:55

















0















For some reason, I'm splitting my order in two part (the first is handle by some organization and the other will me handle by the magento owner).



I'm creating programmatically the order, and for one of the part, I need to stop the mail of the order to be sended.



Example :
In quote : watch, Tv, video game.
Splitting in two parts :



  1. watch, tv

  2. video games

Send email for the watch and tvs
Not send mail for video game.



How can I do this ?



EDIT : i'm splitting my code by doing a foreach on the quote item. If the item is in a category, I create a array with those items.



Then I'm creating my order like this : https://www.rakeshjesadiya.com/how-to-create-order-programmatically-in-magento-2/



And i'm calling the method twice, one for the first part, the other for the second.



I've notice that the email is not sended for the second part if I have placed those 2 orders parts. That's ok I guess, but if the first part is not placed, the second part will send a mail.










share|improve this question
























  • Are you able to split the order base on this logic

    – Amit Bera
    Jun 5 at 9:37











  • share the code which you used for split the order.

    – Dhiren Vasoya
    Jun 5 at 9:44











  • I've added an explanation and a link to my methods (my code is exactly the same)

    – Morgan Tartreau
    Jun 5 at 9:55













0












0








0








For some reason, I'm splitting my order in two part (the first is handle by some organization and the other will me handle by the magento owner).



I'm creating programmatically the order, and for one of the part, I need to stop the mail of the order to be sended.



Example :
In quote : watch, Tv, video game.
Splitting in two parts :



  1. watch, tv

  2. video games

Send email for the watch and tvs
Not send mail for video game.



How can I do this ?



EDIT : i'm splitting my code by doing a foreach on the quote item. If the item is in a category, I create a array with those items.



Then I'm creating my order like this : https://www.rakeshjesadiya.com/how-to-create-order-programmatically-in-magento-2/



And i'm calling the method twice, one for the first part, the other for the second.



I've notice that the email is not sended for the second part if I have placed those 2 orders parts. That's ok I guess, but if the first part is not placed, the second part will send a mail.










share|improve this question
















For some reason, I'm splitting my order in two part (the first is handle by some organization and the other will me handle by the magento owner).



I'm creating programmatically the order, and for one of the part, I need to stop the mail of the order to be sended.



Example :
In quote : watch, Tv, video game.
Splitting in two parts :



  1. watch, tv

  2. video games

Send email for the watch and tvs
Not send mail for video game.



How can I do this ?



EDIT : i'm splitting my code by doing a foreach on the quote item. If the item is in a category, I create a array with those items.



Then I'm creating my order like this : https://www.rakeshjesadiya.com/how-to-create-order-programmatically-in-magento-2/



And i'm calling the method twice, one for the first part, the other for the second.



I've notice that the email is not sended for the second part if I have placed those 2 orders parts. That's ok I guess, but if the first part is not placed, the second part will send a mail.







magento2 orders email






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jun 5 at 9:55







Morgan Tartreau

















asked Jun 5 at 9:05









Morgan TartreauMorgan Tartreau

483212




483212












  • Are you able to split the order base on this logic

    – Amit Bera
    Jun 5 at 9:37











  • share the code which you used for split the order.

    – Dhiren Vasoya
    Jun 5 at 9:44











  • I've added an explanation and a link to my methods (my code is exactly the same)

    – Morgan Tartreau
    Jun 5 at 9:55

















  • Are you able to split the order base on this logic

    – Amit Bera
    Jun 5 at 9:37











  • share the code which you used for split the order.

    – Dhiren Vasoya
    Jun 5 at 9:44











  • I've added an explanation and a link to my methods (my code is exactly the same)

    – Morgan Tartreau
    Jun 5 at 9:55
















Are you able to split the order base on this logic

– Amit Bera
Jun 5 at 9:37





Are you able to split the order base on this logic

– Amit Bera
Jun 5 at 9:37













share the code which you used for split the order.

– Dhiren Vasoya
Jun 5 at 9:44





share the code which you used for split the order.

– Dhiren Vasoya
Jun 5 at 9:44













I've added an explanation and a link to my methods (my code is exactly the same)

– Morgan Tartreau
Jun 5 at 9:55





I've added an explanation and a link to my methods (my code is exactly the same)

– Morgan Tartreau
Jun 5 at 9:55










1 Answer
1






active

oldest

votes


















1














Magento has an event to send email for order defined in following file.




vendor/magento/module-quote/etc/frontend/events.xml




<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="sales_model_service_quote_submit_success">
<observer name="sendEmail" instance="MagentoQuoteObserverSubmitObserver" />
</event>
</config>


If you will look into the SubmitObserver File, you will find below code.



public function execute(MagentoFrameworkEventObserver $observer)

/** @var MagentoQuoteModelQuote $quote */
$quote = $observer->getEvent()->getQuote();
/** @var MagentoSalesModelOrder $order */
$order = $observer->getEvent()->getOrder();

/**
* a flag to set that there will be redirect to third party after confirmation
*/
$redirectUrl = $quote->getPayment()->getOrderPlaceRedirectUrl();
if (!$redirectUrl && $order->getCanSendNewEmailFlag())
try
$this->orderSender->send($order);
catch (Exception $e)
$this->logger->critical($e);





So to stop sending email, you can create a plugin in your module as follows.




app/code/vendor/module/etc/di.xml




<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoQuoteObserverSubmitObserver">
<plugin name="custom_order_stop_email" type="VendorModulePluginSubmitObserver" />
</type>
</config>



Vendor/Module/Plugin/SubmitObserver.php




<?php

namespace VendorModulePlugin;

class SubmitObserver

public function beforeExecute($subject, $observer)

$order = $observer->getEvent()->getOrder();

if ('Your product condition')
$order->setCanSendNewEmailFlag(false);


return [$observer];







share|improve this answer























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "479"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f277330%2fdisable-sending-order-email-programmaticaly%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Magento has an event to send email for order defined in following file.




    vendor/magento/module-quote/etc/frontend/events.xml




    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="sales_model_service_quote_submit_success">
    <observer name="sendEmail" instance="MagentoQuoteObserverSubmitObserver" />
    </event>
    </config>


    If you will look into the SubmitObserver File, you will find below code.



    public function execute(MagentoFrameworkEventObserver $observer)

    /** @var MagentoQuoteModelQuote $quote */
    $quote = $observer->getEvent()->getQuote();
    /** @var MagentoSalesModelOrder $order */
    $order = $observer->getEvent()->getOrder();

    /**
    * a flag to set that there will be redirect to third party after confirmation
    */
    $redirectUrl = $quote->getPayment()->getOrderPlaceRedirectUrl();
    if (!$redirectUrl && $order->getCanSendNewEmailFlag())
    try
    $this->orderSender->send($order);
    catch (Exception $e)
    $this->logger->critical($e);





    So to stop sending email, you can create a plugin in your module as follows.




    app/code/vendor/module/etc/di.xml




    <?xml version="1.0"?>

    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="MagentoQuoteObserverSubmitObserver">
    <plugin name="custom_order_stop_email" type="VendorModulePluginSubmitObserver" />
    </type>
    </config>



    Vendor/Module/Plugin/SubmitObserver.php




    <?php

    namespace VendorModulePlugin;

    class SubmitObserver

    public function beforeExecute($subject, $observer)

    $order = $observer->getEvent()->getOrder();

    if ('Your product condition')
    $order->setCanSendNewEmailFlag(false);


    return [$observer];







    share|improve this answer



























      1














      Magento has an event to send email for order defined in following file.




      vendor/magento/module-quote/etc/frontend/events.xml




      <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
      <event name="sales_model_service_quote_submit_success">
      <observer name="sendEmail" instance="MagentoQuoteObserverSubmitObserver" />
      </event>
      </config>


      If you will look into the SubmitObserver File, you will find below code.



      public function execute(MagentoFrameworkEventObserver $observer)

      /** @var MagentoQuoteModelQuote $quote */
      $quote = $observer->getEvent()->getQuote();
      /** @var MagentoSalesModelOrder $order */
      $order = $observer->getEvent()->getOrder();

      /**
      * a flag to set that there will be redirect to third party after confirmation
      */
      $redirectUrl = $quote->getPayment()->getOrderPlaceRedirectUrl();
      if (!$redirectUrl && $order->getCanSendNewEmailFlag())
      try
      $this->orderSender->send($order);
      catch (Exception $e)
      $this->logger->critical($e);





      So to stop sending email, you can create a plugin in your module as follows.




      app/code/vendor/module/etc/di.xml




      <?xml version="1.0"?>

      <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
      <type name="MagentoQuoteObserverSubmitObserver">
      <plugin name="custom_order_stop_email" type="VendorModulePluginSubmitObserver" />
      </type>
      </config>



      Vendor/Module/Plugin/SubmitObserver.php




      <?php

      namespace VendorModulePlugin;

      class SubmitObserver

      public function beforeExecute($subject, $observer)

      $order = $observer->getEvent()->getOrder();

      if ('Your product condition')
      $order->setCanSendNewEmailFlag(false);


      return [$observer];







      share|improve this answer

























        1












        1








        1







        Magento has an event to send email for order defined in following file.




        vendor/magento/module-quote/etc/frontend/events.xml




        <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
        <event name="sales_model_service_quote_submit_success">
        <observer name="sendEmail" instance="MagentoQuoteObserverSubmitObserver" />
        </event>
        </config>


        If you will look into the SubmitObserver File, you will find below code.



        public function execute(MagentoFrameworkEventObserver $observer)

        /** @var MagentoQuoteModelQuote $quote */
        $quote = $observer->getEvent()->getQuote();
        /** @var MagentoSalesModelOrder $order */
        $order = $observer->getEvent()->getOrder();

        /**
        * a flag to set that there will be redirect to third party after confirmation
        */
        $redirectUrl = $quote->getPayment()->getOrderPlaceRedirectUrl();
        if (!$redirectUrl && $order->getCanSendNewEmailFlag())
        try
        $this->orderSender->send($order);
        catch (Exception $e)
        $this->logger->critical($e);





        So to stop sending email, you can create a plugin in your module as follows.




        app/code/vendor/module/etc/di.xml




        <?xml version="1.0"?>

        <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
        <type name="MagentoQuoteObserverSubmitObserver">
        <plugin name="custom_order_stop_email" type="VendorModulePluginSubmitObserver" />
        </type>
        </config>



        Vendor/Module/Plugin/SubmitObserver.php




        <?php

        namespace VendorModulePlugin;

        class SubmitObserver

        public function beforeExecute($subject, $observer)

        $order = $observer->getEvent()->getOrder();

        if ('Your product condition')
        $order->setCanSendNewEmailFlag(false);


        return [$observer];







        share|improve this answer













        Magento has an event to send email for order defined in following file.




        vendor/magento/module-quote/etc/frontend/events.xml




        <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
        <event name="sales_model_service_quote_submit_success">
        <observer name="sendEmail" instance="MagentoQuoteObserverSubmitObserver" />
        </event>
        </config>


        If you will look into the SubmitObserver File, you will find below code.



        public function execute(MagentoFrameworkEventObserver $observer)

        /** @var MagentoQuoteModelQuote $quote */
        $quote = $observer->getEvent()->getQuote();
        /** @var MagentoSalesModelOrder $order */
        $order = $observer->getEvent()->getOrder();

        /**
        * a flag to set that there will be redirect to third party after confirmation
        */
        $redirectUrl = $quote->getPayment()->getOrderPlaceRedirectUrl();
        if (!$redirectUrl && $order->getCanSendNewEmailFlag())
        try
        $this->orderSender->send($order);
        catch (Exception $e)
        $this->logger->critical($e);





        So to stop sending email, you can create a plugin in your module as follows.




        app/code/vendor/module/etc/di.xml




        <?xml version="1.0"?>

        <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
        <type name="MagentoQuoteObserverSubmitObserver">
        <plugin name="custom_order_stop_email" type="VendorModulePluginSubmitObserver" />
        </type>
        </config>



        Vendor/Module/Plugin/SubmitObserver.php




        <?php

        namespace VendorModulePlugin;

        class SubmitObserver

        public function beforeExecute($subject, $observer)

        $order = $observer->getEvent()->getOrder();

        if ('Your product condition')
        $order->setCanSendNewEmailFlag(false);


        return [$observer];








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jun 5 at 9:41









        Yash ShahYash Shah

        1,106210




        1,106210



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Magento Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f277330%2fdisable-sending-order-email-programmaticaly%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

            Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

            Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form