Create Order and Invoice using Magento

Create Order and Invoice using Magento

In this Post We Will Explain About is Create Order and Invoice using Magento With Example and Demo.Welcome on – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to create order invoice programmatically in Magento Example

In this post we will show you Best way to implement How To Create Transaction In Magento2 Programmatically, hear for create order programmatically customer as guest in magento with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Step 1 : set Store Id

1 First off all We need to set Store Id by changing the source code as below simple source code:

/* Set Store Id */
$dataStoreId = 2; // Here 2 is some Store Id
$infoStore = Mage::getModel('core/store')->load($dataStoreId);

Step 2 : user information / address

2 Set or assigned your user information / address and make user if not any user exist. Do this as the simple step to following source code:

Read Also:  ng click Event Function with Parameters using Angular Example

// Set User Information /Address
$productId = 989825; // Magento Product Id
$user_email = “[email protected]”; // User Email Address
$user_fname = “jaydeep Gondaliya”; 
$user_lname = “Gondaliya”;
$street = “USA Rajkot 360002”;
$city = USA;
$region = “Region”;
$postcode = “123589”;
$mobile = “9898225074”;
$country_id = “+61”;
$user_ip =“”;

// Check user by website id
$user = Mage::getModel("user/user");

// If store some data of website not found,so here set admin store id


Step 3: sales quote model to make sales order

here simple condition some sales dataQuote make model to make some sales order. display the some source code below:

$dataQuote = Mage::getModel('sales/dataQuote')->setStoreId($dataStoreId);

Step 4 : Assign customer to the quote

Assign user to the dataQuote as the following simple source code:

    // For some Existing User
    // For Guest Orders Only

Step 5 : billing/shipping address,

Last and Most important step which will some magento execute the final orcer process. From this Last step We will get simple assigned crate new product, assigned simple way to billing/shipping address like as a below some code, assigned simple or best way to payment method, maked a simple data customer order and liveInvoice. Display the source code below:

Read Also:  Top 10 Tips Advanced PHP Developers

// Get Product data from Id							
$_product = Mage::getModel('catalog/product')->setStoreId($dataStoreId)->load($productId);

    // Assign product(s) to qoute
    $infoBuy = array('qty'=>1,'product'=>$_product->getId());
    $dataQuote->addProduct($_product,new Varien_Object($infoBuy));
    /* Check simple region for country */
    $write = Mage::getSingleton('core/resource')->getConnection('core_write');
    //Select Query
    $query = $write->query("SELECT * FROM `directory_country_region` WHERE `country_id`='".$country_id."'");
        $addressData = array(
            'firstname' => $user_fname, //firstname
            'lastname' => $user_lname, //lastname
            'street' => $street,  //streetname
            'city' => $city,   //cityname
            'region_id' =>$region,
            'postcode' => $postcode, //69555
            'mobile' => $mobile,  //9898526522
            'country_id' => $country_id  //+1
        $addressData = array(
            'firstname' => $user_fname, //mayur
            'lastname' => $user_lname,  // dhameliya
            'street' => $street,
            'city' => $city, //city name
            'region' =>$region, // region name
            'postcode' => $postcode, // 360002
            'mobile' => $mobile,  //9898225052
            'country_id' => $country_id //+91
    // Add Billing Address to qoute
    $billingAddress = $dataQuote->getBillingAddress()->addData($addressData);
    // Assign payment method i.e Check or Money Order
    $dataQuote->getPayment()->importData(array('method' => 'checkmo'));
    // Save dataQuote data
    $service = Mage::getModel('sales/service_dataQuote', $dataQuote);
    $order = $service->getOrder();
        //Now set newly entered order's remote IP.
        //Finally we save our order after setting it's IP.
            // Start Automatic Invoice Create								
                Mage::throwException(Mage::helper('core')->__('Cannot create an liveInvoice.'));
            $liveInvoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
            if (!$liveInvoice->getTotalQty()) {
                Mage::throwException(Mage::helper('core')->__('Cannot save Make an liveInvoice without products.'));
            $saveTransData = Mage::getModel('core/resource_transaction')

You are Most welcome in my youtube Channel Please subscribe my channel. and give me FeedBack.
More Details……
Angularjs Example

Read Also:  jQuery AJAX Inline Insert Update Delete using PHP MySQL


I hope you have Got What is php – Create an Invoice after order is placed And how it works.I would Like to have Feed Back From My Blog( readers.Your Valuable Feed Back,Any Question,or any Comments about This Article( Are Most Always Welcome.

Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  Smooth Scroll to Top with jQuery
  2. Read Also:  vue js image slider - carousel multiple image slider with thumbnail
  3. Read Also:  PHP Important Interview questions and answers
  4. Read Also:  how to put images next to each other in html?
  5. Read Also:  Nested select sql multiple subqueries
  6. Read Also:  oops concepts in php with realtime examples (Classes and Objects)
  7. Read Also:  Create a Fixed Sticky Navigation Menu Bar
  8. Read Also:  vue js image slider - carousel multiple image slider with thumbnail
  9. Read Also:  Nested select sql multiple subqueries
  10. Read Also:  ng click Event Function with Parameters using Angular Example