Home » Magento14 April 2017

Magento: Create Order Programmatically

This article show how you can create sales order programmatically through code in Magento 1.x.

This code example also includes creating new customer if the customer email is not already registered. It also shows how you can save customer address to the newly created customer. This code has been tested for simple products.

Here are the steps followed in the code below:

– The code has a predefined customer’s name, email, billing and shipping address.

– It also has predefined shipping and payment method.

– It also has predefined array of product id and quantity of each product to be ordered/purchased.

– The code first loads the customer by email.

– If the customer email is not present in the system (i.e. the customer is not yet registered) then it sets the name, email, website and store for the customer.

– And then, the code creates the new customer. It also adds the billing and shipping to the newly created customer. This section of code is optional. If you don’t create a new customer at this point, then the order will be placed as Guest.

– After that, the customer object is added to the quote.

– Then, the product-qty array is looped and the product and qty are added to the quote.

– Then, billing and shipping address are added to the quote along with payment and shipping method.

– Finally, the quote is saved and new order is created.

– Log message is saved in the log file after the order is created and a response data is displayed.

Here is the full source code to create new customer programmatically:

Hope this helps. Thanks.


Get New Post by Email

Find me on

FacebookTwitterGoogle+LinkedInRSS Feed