Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Trouble creating a quote/order through custom code (programmatically for use with API)
 
rajesh.malli6
Jr. Member
 
Total Posts:  13
Joined:  2009-07-29
 
kapilreddy - 18 December 2009 11:41 AM

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’

File Attachments
Api.php  (File Size: 3KB - Downloads: 455)
 
Magento Community Magento Community
Magento Community
Magento Community
 
kapilreddy
Jr. Member
 
Total Posts:  14
Joined:  2009-11-27
 

hi calling confirm order from make quote solves your problem.. I hope it helps

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

Hi kapil the same error was generating , have you worked out on the order section?

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

Yeah i ran your code and calling it through make quote function seems to make it run

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

Hi kapil can you plz post that code what you have used? I will try it. have you checked the database that the subtotal value is null or not when u r creating the quote?

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

yes kapil i had got solved the issue by passing the parameters product id in the soap function. and it was working fine. thanks for your help and you have done a really great job.

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

Hi ,

i am able to create the order,but the the product cost is saving in the database as zero. any ideas from anybody?

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

Hi To all i found the mistake wat i have found. please make sure the product is passing in the makeQuote function. then it will work smoothly

 
Magento Community Magento Community
Magento Community
Magento Community
 
Divyesh K
Jr. Member
 
Total Posts:  1
Joined:  2010-01-07
 

Hi jesse_dev,

Thanks for posting with best solution of this topic.
I am developing script of Import Sales Order using SOAP API and working well as you suggest ...
in you provided code, you have taken customer object.  see my code

///
const USER_ORDER_IMPORTER = 125;

customerObj = Mage::getModel(’customer/customer’)->load(self::USER_ORDER_IMPORTER);
$storeId = $customerObj->getStoreId();
$customerObj->setEmail($email);
$quoteObj = Mage::getModel(’sales/quote’)->assignCustomer($customerObj); //sets ship/bill address
$storeObj = $quoteObj->getStore()->load($storeId);
$quoteObj->setStore($storeObj);

$quoteObj->getBillingAddress()->setFirstname($arrOrderImport[’billing_address’][’firstname’]);
$quoteObj->getBillingAddress()->setLastname($arrOrderImport[’billing_address’][’lastname’]);
$quoteObj->getBillingAddress()->setStreet($arrOrderImport[’billing_address’][’address’]);
$quoteObj->getBillingAddress()->setPostcode($arrOrderImport[’billing_address’][’zip’]);
$quoteObj->getBillingAddress()->setCity($arrOrderImport[’billing_address’][’city’]);
$quoteObj->getBillingAddress()->setTelephone($arrOrderImport[’billing_address’][’telephone’]);
$quoteObj->getBillingAddress()->setEmail($arrOrderImport[’billing_address’][’email’]);
$quoteObj->getBillingAddress()->setCountryId(self::COUNTRY);


$quoteObj->getShippingAddress()->setFirstname($arrOrderImport[’shipping_address’][’firstname’]);
$quoteObj->getShippingAddress()->setLastname($arrOrderImport[’shipping_address’][’lastname’]);
$quoteObj->getShippingAddress()->setStreet($arrOrderImport[’shipping_address’][’address’]);
$quoteObj->getShippingAddress()->setPostcode($arrOrderImport[’shipping_address’][’zip’]);
$quoteObj->getShippingAddress()->setCity($arrOrderImport[’shipping_address’][’city’]);
$quoteObj->getShippingAddress()->setTelephone($arrOrderImport[’shipping_address’][’telephone’]);
$quoteObj->getShippingAddress()->setCountryId(self::COUNTRY);

$productModel = Mage::getModel(’catalog/product’);
$productObj=$productModel->load(self::DUMMY_PRODUCT);

$intItemQty = (int) $arrOrderImport[’item_quantity’];
$intItemQty = $intItemQty>0 ? $intItemQty : 1;
$intPrice = Mage::app()->getLocale()->getNumber($arrOrderImport[’item_totalprice’]);
$intPrice = $intPrice>0 ? $intPrice : 0;

$quoteItem = Mage::getModel(’sales/quote_item’)->setProduct($productObj);
$quoteItem->setQuote($quoteObj);
$quoteItem->setQty($intItemQty);
$quoteItem->setCustomPrice($intPrice);
$quoteObj->addItem($quoteItem);

$quoteObj->collectTotals();
$quoteObj->save();
$quoteId = $quoteObj->getId();
//

but now I want ot little change in above code

I need import order only for Guest user/customer not Register Customer. so how to do change in above code.
In short I want to changes in bellow points.
* import Order by Guest customer
* set Guest customer email address (in above code : $customerObj->setEmail($email))
* set Store for that guest customer (in above code :  $quoteObj->setStore($storeObj))

Thanking you

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->setParentIte

 
Magento Community Magento Community
Magento Community
Magento Community
 
dolu
Member
 
Total Posts:  41
Joined:  2009-05-25
 
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
    
}

Thanks a lot, it works good!

Has someone somekind of ShipOrder() function?

It would help me a lot!

Thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
 
VijayGadhavi
Jr. Member
 
Avatar
Total Posts:  11
Joined:  2008-07-17
India
 

How to import order as guest customer?

 
Magento Community Magento Community
Magento Community
Magento Community
 
swissChris
Jr. Member
 
Total Posts:  2
Joined:  2008-08-07
 

First thanks all helper 4 this amazing thread!!!

How can you add the value from custom option to a quote?

Thanks 4 your answers!

Cheers Chris

 
Magento Community Magento Community
Magento Community
Magento Community
 
swissChris
Jr. Member
 
Total Posts:  2
Joined:  2008-08-07
 

The solution looks quite easy. But I searched around a week 4 it.

To add Options to quote I made this code:

$input=     array('options'=>array(
                    
'732'=>"A text 4 a Option Textfield"//Textfield Option
                    
'733'=>'2428' //Dropdown Option
                
));
            
$request = new Varien_Object();
            
$request->setData($input);
            
$quoteObj->addProduct($productObj,$request);

Find out the option ID’s:

$tempOption=array_reverse($productObj->getOptions(), true);
            foreach (
$tempOption as $option{                
                $temp
=$option->getData();
                echo 
"<br/>".$temp["option_id"].":".$temp["default_title"];
                
$values=$option->getValues();
                if(
count($values)>0){                    
                    
foreach ($values as $value){
                        
echo $value->getId()."-".$value["sku"]."|";
                        
                    
}
                }
            }


Let me know if it the code helps you!

Cheers Chris

 
Magento Community Magento Community
Magento Community
Magento Community
 
MagentoBackups
Jr. Member
 
Total Posts:  16
Joined:  2010-02-02
Los Angeles
 

@Fooman:
Thank you so much!!!

If you want a different price than the current store price try with
$quoteItem->setCustomPrice(’10.00’);

not sure any more if the following is needed additionally
$quoteItem->setCalculationPrice(’10.00’);

Those two little lines, along with the sales_quote_item_set_product event and I can set prices on the fly!!
Been trying to figure out this combination for quite a long, long time!
Thanks again!

 
Magento Community Magento Community
Magento Community
Magento Community
 
joshpennington
Member
 
Total Posts:  54
Joined:  2009-06-04
Benton Harbor, MI
 

First of all this thread rocks.  Thanks to everyone who has helped here.  You have no idea how much time you have saved me.

One question I have is how can I take the order from the “Processing” status to “Complete” (or whatever that is).

Do I need to create a shipment?  Something else?

Any help would be appreciated.

Josh Pennington

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