Magento Forum

   
Trouble creating a quote/order through custom code (programmatically for use with API)
 
jesse_dev
Jr. Member
 
Total Posts:  27
Joined:  2009-03-03
 

yea that’s a different issue than creating customers. I haven’t worked with guest profiles. It should be easier than figuring out how to create a customer. It sounds like you might have to over-ride some core functionality too.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Saggy
Sr. Member
 
Total Posts:  131
Joined:  2009-02-03
 

Thanks Jesse for your help anyway. I’ll find out myself and post my finding here.

Cheers
S

 
Magento Community Magento Community
Magento Community
Magento Community
 
pumba
Jr. Member
 
Total Posts:  28
Joined:  2008-05-14
 

Thank you jesse_dev for your brilliant solution.

I have a couple of questions though:

1) how can I specify date when creating order/invoice/shipment
2) how can I create shipment in the same way you create invoice?

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
jesse_dev
Jr. Member
 
Total Posts:  27
Joined:  2009-03-03
 

I haven’t gone through automating shipments. Obviously it’s just a matter of looking in the right files. As far as specifying the date on the order/invoice/shipment, the most you would have to do is build a simple table of the product_id’s created in the import, along with the timestamp you’d like to set it to, then run a script once or every 5 minutes with cron. The least you would have to do is make sure it is an instance of Varien Object and do obj->setCreatedAt(’bla’)->setUpdatedAt(’bla’) .. the Varien Object uses magic functions for setters and getters so you can pretty much set and get anything you want, just by looking at the right db table and switching the naming from field_a in the db to fieldA in your setter/getter .. most of Magento doesn’t really look at what it’s saving, because of the flexibility that attributes offers.. for example, you can save a customer without attaching the state they live in .. its flexibility has both pros and cons.. the only other advice I can offer is (if you haven’t already) learn to use firebug and grep -r or some file searching equivalent..try and dig into the right controller from the form, etc..that’s probably obvious to most here..

 
Magento Community Magento Community
Magento Community
Magento Community
 
allan2fluid
Jr. Member
 
Total Posts:  17
Joined:  2009-08-04
 
jesse_dev - 21 April 2009 10:52 AM

here’s another set of code, adding items as quote_items rather than products
also the functions are split in 2, one to create the quote and the other converts it to an order
in my system, these are set up as soap functions, so it loads Mage separately in each function.
the top 3 lines in each function could be taken out and called just once at the top of the file

function PrepareOrder($params{
    
require_once '../app/Mage.php';
    
$app Mage::app();
    
Mage::register('isSecureArea'true); //no output before here, will get a session header error
    
foreach($params as $k=>$v$$k=$v}
    
    $customerObj
=Mage::getModel('customer/customer')->load($AccountNo);
    
$storeId=$customerObj->getStoreId();
    
$quoteObj=Mage::getModel('sales/quote')->assignCustomer($customerObj); //sets ship/bill address
    
$storeObj=$quoteObj->getStore()->load($storeId);
    
$quoteObj->setStore($storeObj);
    
$productModel=Mage::getModel('catalog/product');

    foreach(
$PartCart as $part{
        
foreach($part as $k=>$v$$k=$v}
        $productObj
=$productModel->load($PartId);
        
$quoteItem=Mage::getModel('sales/quote_item')->setProduct($productObj);
        
$quoteItem->setQuote($quoteObj);
        
$quoteItem->setQty($Quantity);
        
$quoteObj->addItem($quoteItem);
    
}
  $quoteObj
->collectTotals();
    
$quoteObj->save();
    
$quoteId=$quoteObj->getId();
    return 
$quoteId;
}

function ConfirmOrder($quoteId{
    
require_once '../app/Mage.php';
    
$app Mage::app();
    
Mage::register('isSecureArea'true);
    
$quoteObj=Mage::getModel('sales/quote')->load($quoteId);
    
$items=$quoteObj->getAllItems();
    
$quoteObj->collectTotals();
    
$quoteObj->reserveOrderId();

    
$quotePaymentObj=$quoteObj->getPayment();
    
//methods: authorizenet, paypal_express, googlecheckout, purchaseorder
    
$quotePaymentObj->setMethod('purchaseorder');
    
$quoteObj->setPayment($quotePaymentObj);
    
$convertQuoteObj=Mage::getSingleton('sales/convert_quote');
    
$orderObj $convertQuoteObj->addressToOrder($quoteObj->getShippingAddress());
    
$orderPaymentObj=$convertQuoteObj->paymentToOrderPayment($quotePaymentObj);

    
$orderObj->setBillingAddress($convertQuoteObj->addressToOrderAddress($quoteObj->getBillingAddress()));
    
$orderObj->setShippingAddress($convertQuoteObj->addressToOrderAddress($quoteObj->getShippingAddress()));
    
$orderObj->setPayment($convertQuoteObj->paymentToOrderPayment($quoteObj->getPayment()));
    
    foreach (
$items as $item{
        
//@var $item Mage_Sales_Model_Quote_Item
        
$orderItem $convertQuoteObj->itemToOrderItem($item);
        if (
$item->getParentItem()) {
            $orderItem
->setParentItem($orderObj->getItemByQuoteItemId($item->getParentItem()->getId()));
        
}
        $orderObj
->addItem($orderItem);
    
}
    
    $orderObj
->setCanShipPartiallyItem(false);
    
    
$totalDue=$orderObj->getTotalDue();
    
$orderObj->place(); //calls _placePayment
    
$orderObj->save(); 
    
$orderId=$orderObj->getId();
    
//$orderObj->sendNewOrderEmail(); //*/
    
return $orderId;
    
}

Thanks for the code Jesse_dev, saved me a good amount of time in replicating the order process, however there is a bug with the code above and the stock-level checking functions in the Mage_CatalogInventory_Model_Observer class.

The above code calls the function _getProductQtyForCheck 3 times over the one session.  These calls are triggered from:

$quoteItem->setQty($Quantity); = 1 call
$quoteObj->addItem($quoteItem); = 1 call
$items=$quoteObj->getAllItems(); = 1 call

This then does a stock-check three times, and increments the _checkedProductsQty counter each time.  The result of this is that orders which process for stock items which have 2 or less items in stock will process as being back-orders instead of orders which are in stock.

This happens because each of these calls are designed to be used once per page-load, and as all are done at the same time, the logic of this check fails.  Im having a think about how to fix this, but it may require some fairly large core code extending unless anyone has any other ideas?

 
Magento Community Magento Community
Magento Community
Magento Community
 
allan2fluid
Jr. Member
 
Total Posts:  17
Joined:  2009-08-04
 
allan2fluid - 29 September 2009 12:00 AM

jesse_dev - 21 April 2009 10:52 AM
here’s another set of code, adding items as quote_items rather than products
also the functions are split in 2, one to create the quote and the other converts it to an order
in my system, these are set up as soap functions, so it loads Mage separately in each function.
the top 3 lines in each function could be taken out and called just once at the top of the file

function PrepareOrder($params{
    
require_once '../app/Mage.php';
    
$app Mage::app();
    
Mage::register('isSecureArea'true); //no output before here, will get a session header error
    
foreach($params as $k=>$v$$k=$v}
    
    $customerObj
=Mage::getModel('customer/customer')->load($AccountNo);
    
$storeId=$customerObj->getStoreId();
    
$quoteObj=Mage::getModel('sales/quote')->assignCustomer($customerObj); //sets ship/bill address
    
$storeObj=$quoteObj->getStore()->load($storeId);
    
$quoteObj->setStore($storeObj);
    
$productModel=Mage::getModel('catalog/product');

    foreach(
$PartCart as $part{
        
foreach($part as $k=>$v$$k=$v}
        $productObj
=$productModel->load($PartId);
        
$quoteItem=Mage::getModel('sales/quote_item')->setProduct($productObj);
        
$quoteItem->setQuote($quoteObj);
        
$quoteItem->setQty($Quantity);
        
$quoteObj->addItem($quoteItem);
    
}
  $quoteObj
->collectTotals();
    
$quoteObj->save();
    
$quoteId=$quoteObj->getId();
    return 
$quoteId;
}

function ConfirmOrder($quoteId{
    
require_once '../app/Mage.php';
    
$app Mage::app();
    
Mage::register('isSecureArea'true);
    
$quoteObj=Mage::getModel('sales/quote')->load($quoteId);
    
$items=$quoteObj->getAllItems();
    
$quoteObj->collectTotals();
    
$quoteObj->reserveOrderId();

    
$quotePaymentObj=$quoteObj->getPayment();
    
//methods: authorizenet, paypal_express, googlecheckout, purchaseorder
    
$quotePaymentObj->setMethod('purchaseorder');
    
$quoteObj->setPayment($quotePaymentObj);
    
$convertQuoteObj=Mage::getSingleton('sales/convert_quote');
    
$orderObj $convertQuoteObj->addressToOrder($quoteObj->getShippingAddress());
    
$orderPaymentObj=$convertQuoteObj->paymentToOrderPayment($quotePaymentObj);

    
$orderObj->setBillingAddress($convertQuoteObj->addressToOrderAddress($quoteObj->getBillingAddress()));
    
$orderObj->setShippingAddress($convertQuoteObj->addressToOrderAddress($quoteObj->getShippingAddress()));
    
$orderObj->setPayment($convertQuoteObj->paymentToOrderPayment($quoteObj->getPayment()));
    
    foreach (
$items as $item{
        
//@var $item Mage_Sales_Model_Quote_Item
        
$orderItem $convertQuoteObj->itemToOrderItem($item);
        if (
$item->getParentItem()) {
            $orderItem
->setParentItem($orderObj->getItemByQuoteItemId($item->getParentItem()->getId()));
        
}
        $orderObj
->addItem($orderItem);
    
}
    
    $orderObj
->setCanShipPartiallyItem(false);
    
    
$totalDue=$orderObj->getTotalDue();
    
$orderObj->place(); //calls _placePayment
    
$orderObj->save(); 
    
$orderId=$orderObj->getId();
    
//$orderObj->sendNewOrderEmail(); //*/
    
return $orderId;
    
}

Thanks for the code Jesse_dev, saved me a good amount of time in replicating the order process, however there is a bug with the code above and the stock-level checking functions in the Mage_CatalogInventory_Model_Observer class.

The above code calls the function _getProductQtyForCheck 3 times over the one session.  These calls are triggered from:

$quoteItem->setQty($Quantity); = 1 call
$quoteObj->addItem($quoteItem); = 1 call
$items=$quoteObj->getAllItems(); = 1 call

This then does a stock-check three times, and increments the _checkedProductsQty counter each time.  The result of this is that orders which process for stock items which have 2 or less items in stock will process as being back-orders instead of orders which are in stock.

This happens because each of these calls are designed to be used once per page-load, and as all are done at the same time, the logic of this check fails.  Im having a think about how to fix this, but it may require some fairly large core code extending unless anyone has any other ideas?

Sorry for the double post, but I fixed this bug by extending Mage_CatalogInventory_Model_Observer->_getProductQtyForCheck() to remove this check in cases where its a custom order (a global variable set for the productId).  Basic code which requires extending core files (not changing) through a custom module.

 
Magento Community Magento Community
Magento Community
Magento Community
 
aBrookland
Jr. Member
 
Total Posts:  4
Joined:  2009-11-04
 
jesse_dev - 28 May 2009 06:15 AM

I bring more code, here’s some code for invoicing an order. I just tested it and it works. It loads the order by the entity id , not increment id.

function InvoiceOrder($orderId{
try {
    
require_once '../app/Mage.php';
    
$app Mage::app();
    
Mage::register('isSecureArea'true);

    
$orderObj=Mage::getModel('sales/order')->load($orderId);
    
$convertOrderObj=Mage::getSingleton('sales/convert_order');
        
$invoiceObj=$convertOrderObj->toInvoice($orderObj);

        foreach (
$orderObj->getAllItems() as $item{

        $invoiceItem 
$convertOrderObj->itemToInvoiceItem($item);

        if (
$item->getParentItem()) {
            $invoiceItem
->setParentItem($invoiceObj->getItemById($item->getParentItem()->getId()));
        
}
            $invoiceItem
->setQty($item->getQtyToInvoice());
            
$invoiceObj->addItem($invoiceItem);
        
}

        $invoiceObj
->collectTotals();
        
$invoiceObj->register();

        
$orderPaymentObj=$orderObj->getPayment();
        
$orderPaymentObj->pay($invoiceObj);

        
$invoiceObj->getOrder()->setIsInProcess(true);
        
$transactionObj Mage::getModel('core/resource_transaction');
        
$transactionObj->addObject($invoiceObj);
        
$transactionObj->addObject($invoiceObj->getOrder());
        
$transactionObj->save();

        
$invoiceObj->save();
        
$invoiceId=$invoiceObj->getId();
    return 
$invoiceId;
catch (Exception $e{

$msg
=$e->getMessage();
$file=$e->getFile().':'.$e->getLine()."\n";
$trace=$e->getTraceAsString();
$str="\n$msg\n$file\n$trace\n";
Mage::log($str);

}
}

also here’s some code for canceling an order:
$orderObj=Mage::getModel('sales/order')->load($entity_id);
    if (
$orderObj->canCancel()) {
        $orderObj
->cancel();
        
$orderObj->save();
        
$success=true;
    
else 
        $success
=false
    
}

First thanks to jesse_dev, your code has helped me a lot to create a module for importing our legacy orders from VirtueMart.

One problem I found was with this code for creating invoices - they were appearing but not showing as paid and so the order wasn’t changed to completed. I found that I had to change the lines:

$orderPaymentObj=$orderObj->getPayment();
$orderPaymentObj->pay($invoiceObj);

to:

$invoiceObj->pay();

Thanks again,

Alan.

 
Magento Community Magento Community
Magento Community
Magento Community
 
aBrookland
Jr. Member
 
Total Posts:  4
Joined:  2009-11-04
 

Here’s some code for issuing a credit memo to cancel an order to add to jesse_devs offerings

<edit>I should point out that this is to cancel an order that has been payed</edit>

function createCreditmemo($orderId{
        $orderObj 
Mage::getModel('sales/order')->load($orderId);
        
$convertOrderObj Mage::getModel('sales/convert_order');
        
$creditmemoObj $convertOrderObj->toCreditmemo($orderObj);
        
        foreach(
$orderObj->getAllItems() as $item{
            $creditmemoItem 
$convertOrderObj->itemToCreditmemoItem($item);
            
$creditmemoObj->addItem($creditmemoItem);
            
$creditmemoItem->setQty($item->getQtyToRefund());
            
$creditmemoItem->calcRowTotal();
        
}
        
        $creditmemoObj
->collectTotals();
        
$creditmemoObj->register();
        
        
$creditmemoObj->save();
        
$orderObj->save();
        
        return 
$creditmemoObj->getId();
    
}

 
Magento Community Magento Community
Magento Community
Magento Community
 
aBrookland
Jr. Member
 
Total Posts:  4
Joined:  2009-11-04
 

I found a small problem with jesse_dev’s ConfirmOrder() code.

When the quote is converted into an order it needs to be updated itself otherwise you leave active quotes in the database, this will mean that unless you’ve got something cleaning out old quotes the user will have the last created quote in their shopping basket the next time they log on (which could be a surprise to them or even over write the items they’d left in their basket)

The code needs to have the following lines added before the end:

$quoteObj->setIsActive(0);
$quoteObj->save();

It might be a good idea to wrap the quote and order saves in a transaction (you would remove the two $....Obj->save() lines and place this code where $orderObj->save() is:

$transactionObj Mage::getModel('core/resource_transaction');
$transactionObj->addObject($orderObj);
$transactionObj->addObject($quoteObj());
$transactionObj->save();

 
Magento Community Magento Community
Magento Community
Magento Community
 
Danton Bustos
Jr. Member
 
Total Posts:  2
Joined:  2008-11-06
 

Hi guys,

Thanks for all the help given to make a optional solution to outside order creation. This solution work for me and maybe for you else.

I think that this code can be optimized and, why not, at last build the create_order API (Not developed by Magento Team).

Any ideas be wellcome.

Best regards.

Danton.

$mageFilename '../app/Mage.php';
require_once 
$mageFilename;
umask(0);
Mage::app();
$session Mage::getSingleton('core/session', array('name'=>'frontend'));
    
$storeId=3;
    
$conecta_soap = new SoapClient('http://xxxx.cl/index.php/api/soap/?wsdl');
    
$sessionId $conecta_soap->login('user''pass');
     
    
$nuevo_cliente = array(
        
'firstname'  => 'Peter',
        
'lastname'   => 'Setera',
        
'email'      => 'pop@gmail.com',
        
'password'   => '',
        
'store_id'   => $storeId,
        
'website_id' => 0
    
);
    
    
$numero_cliente $conecta_soap->call($sessionId'customer.create', array($nuevo_cliente));
    
$billing_address = array(
        
'firstname'  => 'Mario',
        
'lastname'   => 'Mora',
        
'country_id' => 'CL',
        
'region_id'  => '43',
        
'region'     => 'Santiago',
        
'city'       => 'Providencia',
        
'street'     => array('Santa Lora 75','Oficina 13801'),
        
'telephone'  => '654325',
        
'postcode'   => 10021,
     
        
'is_default_billing'  => true,
        
'is_default_shipping' => false
    
);
    
    
$conecta_soap->call($sessionId'customer_address.create', array($numero_cliente$billing_address));
    
    
$shipping_address = array(
        
'firstname'  => 'Juan',
        
'lastname'   => 'Perez',
        
'country_id' => 'CL',
        
'region_id'  => '43',
        
'region'     => 'Santiago',
        
'city'       => 'Santiago Centro',
        
'street'     => array('Marin 444','Depto. 5434'),
        
'telephone'  => '765434',
        
'postcode'   => 10021,
     
        
'is_default_billing'  => false,
        
'is_default_shipping' => true
    
);
    
    
$conecta_soap->call($sessionId'customer_address.create', array($numero_cliente$shipping_address));
    
    
$productId=251;
    
    
$customer=Mage::getModel('customer/customer')->load($numero_cliente);
    
$quote=Mage::getModel('sales/quote')->assignCustomer($customer);
    
$store $quote->getStore()->load($storeId);
    
$quote->setStore($store);
    
$quote->reserveOrderId();
    
    
//SEE PRODUCT LOAD SOON
    
$product Mage::getModel('catalog/product')
                ->
setStore($store)
                ->
setStoreId($storeId)
                ->
load($productId);

    
$product->setSkipCheckRequiredOption(true);
    
$item $quote->addProduct($product1);
    
$product->unsSkipCheckRequiredOption();
    
$item->checkData();
    
    
$quote->collectTotals();    
    
$quote->save();
    
$quoteId $quote->getId();
    
$quoteConvert Mage::getModel('sales/convert_quote');
    
$quote=Mage::getModel('sales/quote')->load($quoteId);
    
//PAYMENT OK
    
$payment=$quote->getPayment();
    
$payment->setMethod('transbank');
    
$quote->setPayment($payment);
    
$order $quoteConvert->addressToOrder($quote->getShippingAddress());
    
//BILLING ADDRESS OK
    
$order->setBillingAddress($quoteConvert->addressToOrderAddress($quote->getBillingAddress()))->setPayment($quoteConvert->paymentToOrderPayment($quote->getPayment()));
    
//SHIPPING ADDRESS OK
    
$order->setShippingAddress($quoteConvert->addressToOrderAddress($quote->getShippingAddress()));
    
//TOTAL DATA OK
    
$order->setSubtotal('55555');
    
$order->setTaxAmount('6789');
    
$order->setDiscountAmount('679');
    
$order->setShippingAmount('1111');
    
$order->setGrandTotal('777777');
    
//TOTAL BASE DATA OK
    
$order->setBaseSubtotal('55555');
    
$order->setBaseTaxAmount('6789');
    
$order->setBaseDiscountAmount('679');
    
$order->setBaseShippingAmount('1111');
    
$order->setBaseGrandTotal('777777');
    
//SHIPPING METHOD OK
    
$order->setShippingMethod('freeshipping_freeshipping');
    
$order->setShippingDescription('Envio Gratuito');
    
//SEE INTEMS SOON
    
foreach ($quote->getShippingAddress()->getAllItems() as $item{
        
/* @var $item Mage_Sales_Model_Quote_Item */
        
$orderItem $quoteConvert->itemToOrderItem($item);
        
$options = array();
        if (
$productOptions $item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct())) {
            
//$productOptions['info_buyRequest']['options'] = prepareOptionsForRequest($item);
            
$options $productOptions;
        
}
        
if ($addOptions $item->getOptionByCode('additional_options')) {
            $options[
'additional_options'unserialize($addOptions->getValue());
        
}
        
if ($options{
            $orderItem
->setProductOptions($options);
        
}
        
if ($item->getParentItem()) {
            $orderItem
->setParentItem($order->getItemByQuoteItemId($item->getParentItem()->getId()));
        
}
        $order
->addItem($orderItem);
    
}
    $order
->setEmailSent(true);   
    
$order->place();
    
$state Mage_Sales_Model_Order::STATE_PROCESSING;
    
$order->setStatus(Mage::getSingleton('sales/order_config')->getStateDefaultStatus($state));
    
$order->save();
    
$order->sendNewOrderEmail();
    
//echo $order->getId();
    
$conecta_soap->call($sessionId'customer.delete'$numero_cliente);

 
Magento Community Magento Community
Magento Community
Magento Community
 
Ehsan Imam
Jr. Member
 
Total Posts:  15
Joined:  2009-08-04
 

Thanks Jesse_dev and allan2fluid, You saved my time, Code is really well written. I am able to use this code very easily.

Can anybody tell me, How we can add purchase order number?

 
Magento Community Magento Community
Magento Community
Magento Community
 
kapilreddy
Jr. Member
 
Total Posts:  14
Joined:  2009-11-27
 
jesse_dev - 21 April 2009 10:52 AM

here’s another set of code, adding items as quote_items rather than products
also the functions are split in 2, one to create the quote and the other converts it to an order
in my system, these are set up as soap functions, so it loads Mage separately in each function.
the top 3 lines in each function could be taken out and called just once at the top of the file

function PrepareOrder($params{
    
require_once '../app/Mage.php';
    
$app Mage::app();
    
Mage::register('isSecureArea'true); //no output before here, will get a session header error
    
foreach($params as $k=>$v$$k=$v}
    
    $customerObj
=Mage::getModel('customer/customer')->load($AccountNo);
    
$storeId=$customerObj->getStoreId();
    
$quoteObj=Mage::getModel('sales/quote')->assignCustomer($customerObj); //sets ship/bill address
    
$storeObj=$quoteObj->getStore()->load($storeId);
    
$quoteObj->setStore($storeObj);
    
$productModel=Mage::getModel('catalog/product');

    foreach(
$PartCart as $part{
        
foreach($part as $k=>$v$$k=$v}
        $productObj
=$productModel->load($PartId);
        
$quoteItem=Mage::getModel('sales/quote_item')->setProduct($productObj);
        
$quoteItem->setQuote($quoteObj);
        
$quoteItem->setQty($Quantity);
        
$quoteObj->addItem($quoteItem);
    
}
  $quoteObj
->collectTotals();
    
$quoteObj->save();
    
$quoteId=$quoteObj->getId();
    return 
$quoteId;
}

function ConfirmOrder($quoteId{
    
require_once '../app/Mage.php';
    
$app Mage::app();
    
Mage::register('isSecureArea'true);
    
$quoteObj=Mage::getModel('sales/quote')->load($quoteId);
    
$items=$quoteObj->getAllItems();
    
$quoteObj->collectTotals();
    
$quoteObj->reserveOrderId();

    
$quotePaymentObj=$quoteObj->getPayment();
    
//methods: authorizenet, paypal_express, googlecheckout, purchaseorder
    
$quotePaymentObj->setMethod('purchaseorder');
    
$quoteObj->setPayment($quotePaymentObj);
    
$convertQuoteObj=Mage::getSingleton('sales/convert_quote');
    
$orderObj $convertQuoteObj->addressToOrder($quoteObj->getShippingAddress());
    
$orderPaymentObj=$convertQuoteObj->paymentToOrderPayment($quotePaymentObj);

    
$orderObj->setBillingAddress($convertQuoteObj->addressToOrderAddress($quoteObj->getBillingAddress()));
    
$orderObj->setShippingAddress($convertQuoteObj->addressToOrderAddress($quoteObj->getShippingAddress()));
    
$orderObj->setPayment($convertQuoteObj->paymentToOrderPayment($quoteObj->getPayment()));
    
    foreach (
$items as $item{
        
//@var $item Mage_Sales_Model_Quote_Item
        
$orderItem $convertQuoteObj->itemToOrderItem($item);
        if (
$item->getParentItem()) {
            $orderItem
->setParentItem($orderObj->getItemByQuoteItemId($item->getParentItem()->getId()));
        
}
        $orderObj
->addItem($orderItem);
    
}
    
    $orderObj
->setCanShipPartiallyItem(false);
    
    
$totalDue=$orderObj->getTotalDue();
    
$orderObj->place(); //calls _placePayment
    
$orderObj->save(); 
    
$orderId=$orderObj->getId();
    
//$orderObj->sendNewOrderEmail(); //*/
    
return $orderId;
    
}

Thanks for the info I have edited the code a bit for bundled products there is another thread in forum asking how to create bundled products programatically so here is what i did. Maybe it can be imporved
Use confirm order as it is

$app Mage::app();
    
Mage::register('isSecureArea'true); //no output before here, will get a session header error
    
foreach($params as $k=>$v$$k=$v}
    
    $customerObj
=Mage::getModel('customer/customer')->load($AccountNo);
    
$storeId=$customerObj->getStoreId();
    
$quoteObj=Mage::getModel('sales/quote')->assignCustomer($customerObj); //sets ship/bill address
    
$storeObj=$quoteObj->getStore()->load($storeId);
    
$quoteObj->setStore($storeObj);
    
$productModel=Mage::getModel('catalog/product');
    
    foreach(
$PartCart as $part{
        
foreach($part as $k=>$v$$k=$v}
    
    
     $productObj
=$productModel->load($PartId);
        
$quoteItem=Mage::getModel('sales/quote_item')->setProduct($productObj);

    
        
$quoteItem->setQuote($quoteObj);
        
$quoteItem->setQty($Quantity);

        
$quoteObj->addItem($quoteItem);
        
        if(isset(
$Child)){
            $parent
$quoteObj->getItemsCollection()->getLastItem();
            foreach(
$Child as $c1)
            
{
            
        
            
foreach($c1 as $k=>$v$$k=$v}
            $productObj
=$productModel->load($PartId);
                
$quoteItem=Mage::getModel('sales/quote_item')->setProduct($productObj);
            
$quoteItem->setParentItem($parent);         
            
$quoteItem->setQuote($quoteObj);
            
$quoteItem->setQty($Quantity);
            
$quoteObj->addItem($quoteItem);
            
}
        }
    }
  $quoteObj
->collectTotals();
    
$quoteObj->save();
    
$quoteId=$quoteObj->getId();


return 
$this->ConfirmOrder($quoteId);
And the input array format for this is ,
$shopping_cart=array();
$part=array("PartId"=>7"Quantity"=>1"Child"=>array
                                                                                           (array(
"PartId"=>100,"Quantity"=>1),
                                                                                      array(
"PartId"=>101,"Quantity"=>2)));
$shopping_cart[]=$part
$params=array("AccountNo"=>1"PartCart"=>$shopping_cart);
I havent checked the repeating part but this one works.
I hope this helps

 
Magento Community Magento Community
Magento Community
Magento Community
 
rajesh.malli6
Jr. Member
 
Total Posts:  13
Joined:  2009-07-29
 

Hi Ehsan Imam,

Can you please explain how the code was executed. I have also used the same code.(i Mean two functions ‘Make Quote’ & ‘Confirm Order’)
First function was working properly but the second function was not working properly. The following error was occuring:
<b>SQLSTATE[23000]: Integrity constraint violation: 1048 Column ‘subtotal’ cannot be null</b>
Please tell me how o overcome the above error?

 
Magento Community Magento Community
Magento Community
Magento Community
 
kapilreddy
Jr. Member
 
Total Posts:  14
Joined:  2009-11-27
 

Hi Rajesh,
Would provide us with array format that you are using to pass parameters to these functions and also functions that you are using ‘Make Quote’ and ‘Confirm Order’

 
Magento Community Magento Community
Magento Community
Magento Community
 
rajesh.malli6
Jr. Member
 
Total Posts:  13
Joined:  2009-07-29
 

Hi Kapil,

When i am submitting the quote the data was entering as subtotal equals to zero. I think that is the reason to get that error. So how to insert the subtotal with the actual price can you plz post?

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top