Magento Themes and Magento Extensions

Creating Magento order programmatically


If you’re working with Magento , most probably you’ll face a situation when you need existing fake orders, and there are none at the moment. It’s not relevant to create orders (or customers) using the Magento interface, as you can do it programmatically, which takes less time and effort.

This action can be of great help if you need to create a number of orders quickly to test your store features.

Now, in this article I’ll explain now to create Magento orders programmatically, also adding information on creating customers programmatically, as these two actions are closely connected.

Creating Magento order programmatically

OrderGenerator.php is a class for orders generation – download it here.

Orders are created with createOrder($products) method. You can use an array, which specifies the products you want to add to the order, as an argument.

Parameters format corresponds to $_POST variable values format when adding products to cart using the front end.

Here’s an example:

Let’s set shipping and billing methods before creating orders:

Also we can point out the customer which the order is assigned to:

You can pass customer ID, Mage_Customer_Model_Customer object or OrderGenerator::CUSTOMER_RANDOM constant to the function.

If you use OrderGenerator::CUSTOMER_RANDOM, the generator will pick a random one from the existing customers.

Comments are closed.