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

Page 10 of 10
Trouble creating a quote/order through custom code (programmatically for use with API)
 
ddoddsr
Jr. Member
 
Total Posts:  24
Joined:  2012-02-08
 

Hi,
Much good information here.  I’m hoping i can get some direction here

i want to create an order to relieve inventory from an outside system
and have documentation (the order) of the event with
date time items qtys price_each and extended
with totals of items total extended price.

I have a system customer to place all imported orders or could use api user
I have a csv with item, qty, price_each.

the file is created on a local PC drive so I want to read it from there. in the old system i called a javascript from a command (.bat ) file to run an api call to insert the order.

i’d like to use the bat file idea, which is run by the same program that makes the csv file.

I copied and ran Jesse_dev 1st entry and it made an order, but i still need to bring in the line items.

thoughts?

Dan

 
Magento Community Magento Community
Magento Community
Magento Community
 
katherinbridges
Jr. Member
 
Total Posts:  29
Joined:  2009-08-27
 
michael_g08 - 17 January 2011 01:51 AM

@Papiertiger

Hi, take a look at this code. It works for downloadable, and bundle products on my 1.4.1

Best wishes, Michael.

Thanks michael for sharing your code. I have used two function from your code file and the order has been created successfully. but the credit card number is not being stored and it gets empty while go in order detail in admin panel.
I have used these two functio like this way.

$customer_id 2;
$shopping_cart=array();
$part=array("PartId"=>17“Quantity"=>5);
$shopping_cart[]=$part; //repeat as necessary
$params=array("AccountNo"=>$customer_id, â€œPartCart"=>$shopping_cart);
$qoteid $this->PrepareOrder($params);
$this->createOrder($qoteid,’ccsave’,true);
and in createOrder function i have added credit card information like this
$orderObj->getPayment()->setCcNumber('6011111111111117');
                
$orderObj->getPayment()->setCcOwner('ooooo');
                
$orderObj->getPayment()->setCcType('Discover');
                
$orderObj->getPayment()->setCcExpMonth('9');
                
$orderObj->getPayment()->setCcExpYear('2014');
                
$orderObj->getPayment()->setCcLast4(substr('6011111111111117',-4));

I am very much thankful to you if you check this code and tell me where I am wrong.
Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
katherinbridges
Jr. Member
 
Total Posts:  29
Joined:  2009-08-27
 
michael_g08 - 17 January 2011 01:51 AM

@Papiertiger

Hi, take a look at this code. It works for downloadable, and bundle products on my 1.4.1

Best wishes, Michael.

I have used this createOrder.php file and order is being created successfully but i have a problem my credit card is not being store and getting empty in order detail page.

$customer_id 2
        
$shopping_cart=array();
        
$part=array("PartId"=>17"Quantity"=>5);
        
$shopping_cart[]=$part//repeat as necessary
        
$params=array("AccountNo"=>$customer_id"PartCart"=>$shopping_cart);
        
$qoteid $this->PrepareOrder($params);
        
$this->createOrder($qoteid,'ccsave',true);

        function 
PrepareOrder($params{
            
//require_once '../app/Mage.php';
            
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 
-> addMessage('Auto Order Code');   //after separately
            
$quoteObj->collectTotals();
            
$quoteObj->save();
            
$quoteId=$quoteObj->getId();
            return 
$quoteId;
        
}

        
public function createOrder($quoteId$paymentMethod$paymentData
        
{
            $quoteObj 
Mage::getModel('sales/quote')->load($quoteId); // Mage_Sales_Model_Quote
            
$items $quoteObj->getAllItems();
            
$quoteObj->reserveOrderId();
              
// set payment method 
            
$quotePaymentObj $quoteObj->getPayment(); // Mage_Sales_Model_Quote_Payment
            
$quotePaymentObj->setMethod($paymentMethod);
            
$quoteObj->setPayment($quotePaymentObj);              
            
// convert quote to order
            
$convertQuoteObj Mage::getSingleton('sales/convert_quote');
            
$orderObj $convertQuoteObj->addressToOrder($quoteObj->getShippingAddress());
            
$orderPaymentObj $convertQuoteObj->paymentToOrderPayment($quotePaymentObj);            
            
// convert quote addresses
            
$orderObj->setBillingAddress($convertQuoteObj->addressToOrderAddress($quoteObj->getBillingAddress()));
            
$orderObj->setShippingAddress($convertQuoteObj->addressToOrderAddress($quoteObj->getShippingAddress()));
            
            
// set payment options
            
$orderObj->setPayment($convertQuoteObj->paymentToOrderPayment($quoteObj->getPayment()));
            if (
$paymentData{
                $orderObj
->getPayment()->setCcNumber('6011111111111117');
                
$orderObj->getPayment()->setCcOwner('ooooo');
                
$orderObj->getPayment()->setCcType('Discover');
                
$orderObj->getPayment()->setCcExpMonth('9');
                
$orderObj->getPayment()->setCcExpYear('2014');
                
$orderObj->getPayment()->setCcLast4(substr('6011111111111117',-4));
            
}
            
// convert quote items
            
foreach ($items as $item{
                
// @var $item Mage_Sales_Model_Quote_Item
                
$orderItem $convertQuoteObj->itemToOrderItem($item);
                
$options = array();
                if (
$productOptions $item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct())) {
                    $options 
$productOptions;
                
}
                
if ($addOptions $item->getOptionByCode('additional_options')) {
                    $options[
'additional_options'unserialize($addOptions->getValue());
                
}
                
if ($options{
                    $orderItem
->setProductOptions($options);
                
}
                
if ($item->getParentItem()) {
                    $orderItem
->setParentItem($orderObj->getItemByQuoteItemId($item->getParentItem()->getId()));
                
}
                $orderObj
->addItem($orderItem);
            
}            
            $orderObj
->setCanShipPartiallyItem(false);
          
            try 
{
                $orderObj
->place();
            
catch (Exception $e){        
                Mage
::log($e->getMessage());
                
Mage::log($e->getTraceAsString());
            
}            
            $orderObj
->save(); 
            
//$orderObj->sendNewOrderEmail(); 
            
return $orderObj->getId();            
        
}
I did not know the (paymentData) value therefore i passed true and change it then in the code. Would you like to tell where I am wrong and why credit card is getting empty in order detail page.
I am very much thankful to you for this.
 
Magento Community Magento Community
Magento Community
Magento Community
 
katherinbridges
Jr. Member
 
Total Posts:  29
Joined:  2009-08-27
 

@michael_g08

I have used your attached code, it works fine for simple product but there is idea how to set product options/attributes inside the script would you please discuss this.

Also there is any other way to create order progammatically for configurable products and how to set there attributes/options.

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
bestobdii
Jr. Member
 
Total Posts:  10
Joined:  2012-11-19
 

To attach more than one item click preview after choosing a file

http://www.shopobd2.com

 
Magento Community Magento Community
Magento Community
Magento Community
 
BhadreshShiroya
Jr. Member
 
Avatar
Total Posts:  9
Joined:  2012-05-25
Surat
 

not found file app/design/frontend/default/your_theme/template/payment/info/cc.phtml
change template sales order

 
Magento Community Magento Community
Magento Community
Magento Community
 
Pranay_Gondane
Jr. Member
 
Total Posts:  8
Joined:  2010-04-11
 

Please check this for custom shipping....
http://pranaydac08.blogspot.in/2013/12/how-to-add-custom-shipping-price-when.html

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 10 of 10