I try to create an order programmatically in magento2 using this code snippet found on webkul.com

Order I want to create for guest customer.while script executing customer creating ... I don't want that Can any one help me to create orders for guest with out creating customers


Following links will help you in creating guest order

https://blog.amasty.com/creating-magento-2-orders-programmatically/ http://webkul.com/blog/create-quote-and-order-programmatically-in-magento2/

  • Sorry Both are same they are creating customers if customers not exist. What i need is if customer not exist need to place order with guest mode only – Pawankumar May 9 '17 at 13:41
  • Anyone found answer for this guest mode order creation programmatically? – Elamurugan Aug 17 '17 at 11:11
  • Yes i found it i was created also order programatically – Pawankumar Sep 4 '17 at 4:42
  • @pawankumar Share link – Arslan Tabassum Mar 10 '20 at 13:49

this worked for me. I would post the entire function but I have heavily modified it to do more custom things relevant to the module I am was working on that will just clutter up the answer

I followed the way done on here using the 3rd answer down which works on 2.1.

How to create order programmatically in Magento 2?

then changed this line

    $cart = $this->cartRepogitoryInterface->get($cart->getId());


        $cart = $this->cartRepositoryInterface->get($quote->getId())->setCheckoutMethod(CartManagementInterface::METHOD_GUEST);

which can be found in this file magento-2/vendor/magento/module-quote/Model/GuestCart/GuestCartManagement.php

you will also need to add

use Magento\Quote\Api\CartManagementInterface;

And don't forget to remove the customer creation parts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.