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

                    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