Magento 2 create Order programatically and set a custom date to ithow to set custom field in orderHow to create quote and order programmatically in Magento2Programatically Create Order in Magento 2.1Magento 2 How to create new order attribute programaticallyDate validation on my custom form on frontend magento 2Magento 2: Get Order Information Outside Magento Issue for DateCustom Date Fields in CMS Block in magento 2How to create Magento Order programatically in Amazon M2eproCreate Order programatically, not working via cronMagento 1.9 set custom field/attribute when order is set to complete

Why would future John risk sending back a T-800 to save his younger self?

How to retract an idea already pitched to an employer?

Inconsistent behavior of compiler optimization of unused string

Using a found spellbook as a Sorcerer-Wizard multiclass

BGP multihome issue

Interview not reimboursed if offer is made but not accepted

Taxi Services at Didcot

Using "subway" as name for London Underground?

Should I compare a std::string to "string" or "string"s?

Were Alexander the Great and Hephaestion lovers?

Where does "0 packages can be updated." come from?

Movie about a boy who was born old and grew young

Facebook Marketing API asset access suddenly denied

How did students remember what to practise between lessons without any sheet music?

"You've got another thing coming" - translation into French

What could have caused a rear derailleur to end up in the back wheel suddenly?

How is water heavier than petrol, even though its molecular weight is less than petrol?

How to tell your grandparent to not come to fetch you with their car?

Compiling c files on ubuntu and using the executable on Windows

Words that signal future content

Chemmacros scheme translation

Can anyone identify this tank?

Are there downsides to using std::string as a buffer?

Is it a problem if <h4>, <h5> and <h6> are smaller than regular text?



Magento 2 create Order programatically and set a custom date to it


how to set custom field in orderHow to create quote and order programmatically in Magento2Programatically Create Order in Magento 2.1Magento 2 How to create new order attribute programaticallyDate validation on my custom form on frontend magento 2Magento 2: Get Order Information Outside Magento Issue for DateCustom Date Fields in CMS Block in magento 2How to create Magento Order programatically in Amazon M2eproCreate Order programatically, not working via cronMagento 1.9 set custom field/attribute when order is set to complete






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








0















I have a order to create an order in magento 2. But the order it create is with the date when i run the script. I don't want to save the current date for the order. I want to set a certain date to the that order.










share|improve this question






























    0















    I have a order to create an order in magento 2. But the order it create is with the date when i run the script. I don't want to save the current date for the order. I want to set a certain date to the that order.










    share|improve this question


























      0












      0








      0








      I have a order to create an order in magento 2. But the order it create is with the date when i run the script. I don't want to save the current date for the order. I want to set a certain date to the that order.










      share|improve this question
















      I have a order to create an order in magento 2. But the order it create is with the date when i run the script. I don't want to save the current date for the order. I want to set a certain date to the that order.







      magento2 magento-2.1 sales-order






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited May 30 at 5:57







      Avesh Naik

















      asked May 29 at 11:16









      Avesh NaikAvesh Naik

      485114




      485114




















          2 Answers
          2






          active

          oldest

          votes


















          0














          A tricky wat, you set your desired time to created_at field



          Magento 2 has a method setCreatedAt() and using this method can set Order created time.



          So add below code after the end of your order creation code and run update() of this code.



          public function __construct(
          MagentoSalesApiOrderRepositoryInterface $orderRepository,
          MagentoSalesModelResourceModelOrder $orderResourceModel
          )
          $this->orderResourceModel = $orderResourceModel;
          $this->orderRepository = $orderRepository;


          public function update()

          $order = $this->orderRepository->get(1); // 1 is order id
          $order->setCreatedAt($createdAt); // set time
          $this->orderRepository->save($order);







          share|improve this answer

























          • No it didn't worked.

            – Avesh Naik
            May 31 at 7:22


















          0














          Finally i found the solution.



          My question was not fully complete. Sorry about that. I wanted the order date to be on certain date. The order is not yet created. I am creating the order using my custom code. To create an order i need to create Quote. So if i change the quote create and update date then i reflects to order date too.






          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%2f276573%2fmagento-2-create-order-programatically-and-set-a-custom-date-to-it%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            A tricky wat, you set your desired time to created_at field



            Magento 2 has a method setCreatedAt() and using this method can set Order created time.



            So add below code after the end of your order creation code and run update() of this code.



            public function __construct(
            MagentoSalesApiOrderRepositoryInterface $orderRepository,
            MagentoSalesModelResourceModelOrder $orderResourceModel
            )
            $this->orderResourceModel = $orderResourceModel;
            $this->orderRepository = $orderRepository;


            public function update()

            $order = $this->orderRepository->get(1); // 1 is order id
            $order->setCreatedAt($createdAt); // set time
            $this->orderRepository->save($order);







            share|improve this answer

























            • No it didn't worked.

              – Avesh Naik
              May 31 at 7:22















            0














            A tricky wat, you set your desired time to created_at field



            Magento 2 has a method setCreatedAt() and using this method can set Order created time.



            So add below code after the end of your order creation code and run update() of this code.



            public function __construct(
            MagentoSalesApiOrderRepositoryInterface $orderRepository,
            MagentoSalesModelResourceModelOrder $orderResourceModel
            )
            $this->orderResourceModel = $orderResourceModel;
            $this->orderRepository = $orderRepository;


            public function update()

            $order = $this->orderRepository->get(1); // 1 is order id
            $order->setCreatedAt($createdAt); // set time
            $this->orderRepository->save($order);







            share|improve this answer

























            • No it didn't worked.

              – Avesh Naik
              May 31 at 7:22













            0












            0








            0







            A tricky wat, you set your desired time to created_at field



            Magento 2 has a method setCreatedAt() and using this method can set Order created time.



            So add below code after the end of your order creation code and run update() of this code.



            public function __construct(
            MagentoSalesApiOrderRepositoryInterface $orderRepository,
            MagentoSalesModelResourceModelOrder $orderResourceModel
            )
            $this->orderResourceModel = $orderResourceModel;
            $this->orderRepository = $orderRepository;


            public function update()

            $order = $this->orderRepository->get(1); // 1 is order id
            $order->setCreatedAt($createdAt); // set time
            $this->orderRepository->save($order);







            share|improve this answer















            A tricky wat, you set your desired time to created_at field



            Magento 2 has a method setCreatedAt() and using this method can set Order created time.



            So add below code after the end of your order creation code and run update() of this code.



            public function __construct(
            MagentoSalesApiOrderRepositoryInterface $orderRepository,
            MagentoSalesModelResourceModelOrder $orderResourceModel
            )
            $this->orderResourceModel = $orderResourceModel;
            $this->orderRepository = $orderRepository;


            public function update()

            $order = $this->orderRepository->get(1); // 1 is order id
            $order->setCreatedAt($createdAt); // set time
            $this->orderRepository->save($order);








            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited May 29 at 12:23

























            answered May 29 at 11:43









            Amit BeraAmit Bera

            60.8k1682181




            60.8k1682181












            • No it didn't worked.

              – Avesh Naik
              May 31 at 7:22

















            • No it didn't worked.

              – Avesh Naik
              May 31 at 7:22
















            No it didn't worked.

            – Avesh Naik
            May 31 at 7:22





            No it didn't worked.

            – Avesh Naik
            May 31 at 7:22













            0














            Finally i found the solution.



            My question was not fully complete. Sorry about that. I wanted the order date to be on certain date. The order is not yet created. I am creating the order using my custom code. To create an order i need to create Quote. So if i change the quote create and update date then i reflects to order date too.






            share|improve this answer



























              0














              Finally i found the solution.



              My question was not fully complete. Sorry about that. I wanted the order date to be on certain date. The order is not yet created. I am creating the order using my custom code. To create an order i need to create Quote. So if i change the quote create and update date then i reflects to order date too.






              share|improve this answer

























                0












                0








                0







                Finally i found the solution.



                My question was not fully complete. Sorry about that. I wanted the order date to be on certain date. The order is not yet created. I am creating the order using my custom code. To create an order i need to create Quote. So if i change the quote create and update date then i reflects to order date too.






                share|improve this answer













                Finally i found the solution.



                My question was not fully complete. Sorry about that. I wanted the order date to be on certain date. The order is not yet created. I am creating the order using my custom code. To create an order i need to create Quote. So if i change the quote create and update date then i reflects to order date too.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered May 31 at 7:25









                Avesh NaikAvesh Naik

                485114




                485114



























                    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%2f276573%2fmagento-2-create-order-programatically-and-set-a-custom-date-to-it%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

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

                    Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

                    Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?