Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Iam beginner of php.

Could you tell me how can I create Order using magento v2_soap api?

thanks in advance.

share|improve this question
    
Welcome to Magento.SE! This question is too vague or the answer would be too long for the format of this site. I'm glad that you're here and you're interested but we typically ask for more specific questions or for you to show what you have tried up to this point. In general, be more specific. – philwinkle Aug 6 '13 at 20:16

You'll want to use the methods in the cart hierarchy to create a cart, add items to it, and then user the order method.

Here's the sample code the from API docs.

/**
 * Example of order creation
 * Preconditionsare as follows:
 * 1. Create a customer
 * 2. Сreate a simple product */

$user = 'apiUser';
$password = 'apiKey';
    $proxy = new SoapClient('http://magentohost/api/v2_soap/?wsdl');
    $sessionId = $proxy->login($user, $password);
    $cartId = $proxy->shoppingCartCreate($sessionId, 1);
    // load the customer list and select the first customer from the list
    $customerList = $proxy->customerCustomerList($sessionId, array());
    $customer = (array) $customerList[0];
    $customer['mode'] = 'customer';
    $proxy->shoppingCartCustomerSet($sessionId, $cartId, $customer);
    // load the product list and select the first product from the list
    $productList = $proxy->catalogProductList($sessionId);
    $product = (array) $productList[0];
    $product['qty'] = 1;
    $proxy->shoppingCartProductAdd($sessionId, $cartId, array($product));

    $address = array(
        array(
            'mode' => 'shipping',
            'firstname' => $customer['firstname'],
            'lastname' => $customer['lastname'],
            'street' => 'street address',
            'city' => 'city',
            'region' => 'region',
            'telephone' => 'phone number',
            'postcode' => 'postcode',
            'country_id' => 'country ID',
            'is_default_shipping' => 0,
            'is_default_billing' => 0
        ),
        array(
            'mode' => 'billing',
            'firstname' => $customer['firstname'],
            'lastname' => $customer['lastname'],
            'street' => 'street address',
            'city' => 'city',
            'region' => 'region',
            'telephone' => 'phone number',
            'postcode' => 'postcode',
            'country_id' => 'country ID',
            'is_default_shipping' => 0,
            'is_default_billing' => 0
        ),
    );
     // add customer address
    $proxy->shoppingCartCustomerAddresses($sessionId, $cartId, $address);
    // add shipping method
    $proxy->shoppingCartShippingMethod($sessionId, $cartId, 'flatrate_flatrate');

    $paymentMethod =  array(
        'po_number' => null,
        'method' => 'checkmo',
        'cc_cid' => null,
        'cc_owner' => null,
        'cc_number' => null,
        'cc_type' => null,
        'cc_exp_year' => null,
        'cc_exp_month' => null
    );
     // add payment method
    $proxy->shoppingCartPaymentMethod($sessionId, $cartId, $paymentMethod);
     // place the order
    $orderId = $proxy->shoppingCartOrder($sessionId, $cartId, null, null);
share|improve this answer

By default Magento does not allow you to create orders through the API.
Take a look in app/code/code/Mage/Sales/etc/wsdl.xml inside the tag <portType> and see what methods are supported for the Sales module.
In general you can only retrieve lists or individual objects, or add comments to them. For the an order you can change the status.
You are allowed to create shipments, invoices or credit memos, but not orders.
To be able to do it, you need to extend the wsdl and add your class with methods for creating an order.
No offense, but this might prove to be a big task for a beginner (even for someone with a little experience also).
If you want to give it a go read first how to extend the web service and how to override models in magento.
You can also take a look at this. It's a workaround on creating an order by going through the checkout process using the API. (I haven't tested it).
[EDIT]
I will leave this answer here as it serves as general knowledge, but I highly approve of Alan's answer. He really know what's his talking about. :)

share|improve this answer
    
This is good generate information, but the API supports (in newer Magento versions) creating orders by building up a cart object, adding items, and then using the cart's "order" method (maps to createOrder in the class) See Mage/Checkout/etc/api.xml for the definition. – Alan Storm Aug 12 '13 at 1:07
    
@AlanStorm Have you any idea of this error "Credit card number mismatch with credit card type." while creating an order with API – hardik Apr 7 '14 at 16:37
    
@hardik Sounds like your number is failing the validate method in app/code/core/Mage/Payment/Model/Method/Cc.php – Alan Storm Apr 7 '14 at 16:40
    
@AlanStorm I have tested with my 3 different VISA cards and it still shows that same error. – hardik Apr 7 '14 at 16:54
    
@AlanStorm magento.stackexchange.com/questions/17980/… here is my question. – hardik Apr 7 '14 at 17:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.