By using this code you can easily create order through magento api.
[php]
<?php
$proxy = new SoapClient('http://yoursite.com/api/soap/?wsdl');
$sessionId = $proxy->login('pk_admin', 'pk1234567');
echo "<br />sessionId : ".$sessionId;
$store_id = 1;
$website_id = 1;
// Create a quote, get quote identifier
$shoppingCartId = $proxy->call($sessionId, 'cart.create', array($store_id));
echo "<br />shoppingCartId : ".$shoppingCartId;
// Set customer, for example guest
$customerAsGuest = array(
"firstname" => "Prashant",
"lastname" => "Kumar",
"email" => "test@test.com",
"website_id" => $website_id,
"store_id" => $store_id,
"mode" => "guest"
);
$resultCustomerSet = $proxy->call($sessionId, 'cart_customer.set', array($shoppingCartId, $customerAsGuest));
echo "<br />resultCustomerSet : ".$resultCustomerSet;
// Set customer addresses, for example guest's addresses
$arrAddresses = array(
array(
"mode" => "shipping",
"firstname" => "S Firstname",
"lastname" => "S Lastname",
"company" => "S Company",
"street" => "S Street",
"city" => "S City",
"region" => "S Region",
"postcode" => "testPostcode",
"country_id" => "IN",
"telephone" => "0123456789",
"fax" => "0123456789",
"is_default_shipping" => 0,
"is_default_billing" => 0
),
array(
"mode" => "billing",
"email" => "pk@pk.com",
"firstname" => "B Firstname",
"lastname" => "B Lastname",
"company" => "B Company",
"street" => "B Street",
"city" => "B City",
"region" => "B Region",
"postcode" => "B 400078",
"country_id" => "IN",
"telephone" => "0123456789",
"fax" => "0123456789",
"is_default_shipping" => 0,
"is_default_billing" => 0
)
);
$resultCustomerAddresses = $proxy->call($sessionId, "cart_customer.addresses", array($shoppingCartId, $arrAddresses));
echo "<br />resultCustomerAddresses : ".$resultCustomerAddresses;
// add products into shopping cart
$arrProducts = array(
array(
"product_id" => "1",
"qty" => 1
),
array(
"product_id" => "2",
"qty" => 1
)
);
$resultCartProductAdd = $proxy->call($sessionId, "cart_product.add", array($shoppingCartId, $arrProducts));
echo "<br />resultCartProductAdd : ".$resultCartProductAdd;
/*
Not required as of now
// update product in shopping cart
$arrProducts = array(
array(
"product_id" => "1",
"qty" => 5
),
);
$resultCartProductUpdate = $proxy->call($sessionId, "cart_product.update", array($shoppingCartId, $arrProducts));
// remove products from shopping cart, for example by SKU
$arrProducts = array(
array(
"sku" => "testSKU"
),
);
$resultCartProductRemove = $proxy->call($sessionId, "cart_product.remove", array($shoppingCartId, $arrProducts));
*/
// get list of products
$shoppingCartProducts = $proxy->call($sessionId, "cart_product.list", array($shoppingCartId));
echo "<br />shoppingCartProducts : <br />";
echo '<pre>';
print_r($shoppingCartProducts);
echo '</pre>';
$resultShippingMethods = $proxy->call($sessionId, "cart_shipping.list", array($shoppingCartId));
echo '<pre>';
print_r($resultShippingMethods);
echo '</pre>';
/*
// get list of shipping methods
$resultShippingMethods = $proxy->call($sessionId, "cart_shipping.list", array($shoppingCartId));
echo "<br />1 resultShippingMethods : <br />";
echo '<pre>';
print_r($resultShippingMethods);
echo '</pre>';
// set shipping method
$shippingMethod = array(
"method" => "flatrate_flatrate"
);
*/
$shippingMethod = $resultShippingMethods[0]["code"];
$resultShippingMethod = $proxy->call($sessionId, "cart_shipping.method", array($shoppingCartId, $shippingMethod));
/*
// get list of payment methods
$resultPaymentMethods = $proxy->call($sessionId, "cart_payment.list", array($shoppingCartId));
echo "<br />resultPaymentMethods : <br />";
echo '<pre>';
print_r($resultPaymentMethods);
echo '</pre>';
*/
// set payment method
$paymentMethod = array(
"method" => "purchaseorder",
"po_number" => "annet-pk 001"
);
$resultPaymentMethod = $proxy->call($sessionId, "cart_payment.method", array($shoppingCartId, $paymentMethod));
/*not required right now
// add coupon
$couponCode = "aCouponCode";
$resultCartCouponRemove = $proxy->call($sessionId, "cart_coupon.add", array($shoppingCartId, $couponCode));
// remove coupon
$resultCartCouponRemove = $proxy->call($sessionId, "cart_coupon.remove", array($shoppingCartId));
*/
// get total prices
$shoppingCartTotals = $proxy->call($sessionId, "cart.totals", array($shoppingCartId));
echo "<br />shoppingCartTotals : <br />";
echo '<pre>';
print_r($shoppingCartTotals);
echo '</pre>';
// get full information about shopping cart
$shoppingCartInfo = $proxy->call($sessionId, "cart.info", array($shoppingCartId));
echo "<br />shoppingCartInfo : <br />";
echo '<pre>';
print_r($shoppingCartInfo);
echo '</pre>';
/*
//not required right now
// get list of licenses
$shoppingCartLicenses = $proxy->call($sessionId, "cart.licenseAgreement", array($shoppingCartId));
echo "<br />shoppingCartLicences : <br />";
echo '<pre>';
print_r($shoppingCartLicences);
echo '</pre>';
// check if license is existed
$licenseForOrderCreation = null;
if (count($shoppingCartLicenses)) {
$licenseForOrderCreation = array();
foreach ($shoppingCartLicenses as $license) {
$licenseForOrderCreation[] = $license['agreement_id'];
}
}
echo "<br />licenseForOrderCreation : <br />";
echo '<pre>';
print_r($licenseForOrderCreation);
echo '</pre>';
*/
// create order
$resultOrderCreation = $proxy->call($sessionId, "cart.order", array($shoppingCartId, null));
echo "<br />resultOrderCreation : <br />";
echo '<pre>';
print_r($resultOrderCreation);
echo '</pre>';
?>
[/php]