Manoj Kumar
Manoj Kumar

Reputation: 157

how to create Order using magento v2_soap api in php

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

Upvotes: 0

Views: 2643

Answers (2)

Avinash Borse
Avinash Borse

Reputation: 369

It's not possible with default single api you need to create you own custom api

OR

You need to call multiple api to place order as follows -

    $proxy = new SoapClient('http://mywebside.com/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[188];

    //Do not change this credentials
    $customer['customer_id'] = 199; // customer id
    $customer['created_at'] = '2016-02-03 19:24:41';
    $customer['updated_at'] = '2016-04-22 03:33:33';
    $customer['store_id'] = 1;
    $customer['website_id'] = 1;
    $customer['created_in'] = 'Default Store View';
    $customer['email'] = '[email protected]';
    $customer['firstname'] = 'test';
    $customer['lastname'] = 'test';
    $customer['group_id'] = 1;
    $customer['password_hash'] = 'assassaXXXXO';    
    $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= array(array(
        'product_id' => '43001',
        'sku' => 'SKU420',
        'qty' => '2',
        ),
        array(
        'product_id' => '43002',    
        'sku' => 'SKUZ42B2',
        'qty' => '1',
        ));   

    try{    
        $proxy->shoppingCartProductAdd($sessionId, $cartId, $product);
     } catch (SoapFault $e) {
        $error['product'] = $e->getMessage();
     }

    $address = array(
        array(
            'mode' => 'shipping',
            'firstname' => $customer['firstname'],
            'lastname' => $customer['lastname'],
            'street' => 'street address',
            'city' => 'city',
            'region' => 'region',
            'telephone' => 'phone number',
            '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' => '',
            'country_id' => 'country ID',
            'is_default_shipping' => 0,
            'is_default_billing' => 0
        ),
    );

    // add customer address
    try{    
        $proxy->shoppingCartCustomerAddresses($sessionId, $cartId, $address); 
    } catch (SoapFault $e) {
        $error['shipping'] = $e->getMessage();
    } 

    try{
    // add shipping method
        $proxy->shoppingCartShippingMethod($sessionId, $cartId, 'freeshipping_freeshipping');
    } catch (SoapFault $e) {
        $result = $e->getMessage();
    } 

    // add payment method   

    enter code here
    $paymentMethod =  array(
        'method' => 'cashondelivery'        
    );
    $proxy->shoppingCartPaymentMethod($sessionId, $cartId, $paymentMethod);

     // place the order
    $orderId = $proxy->shoppingCartOrder($sessionId, $cartId, null, null);

Upvotes: 1

balexandre
balexandre

Reputation: 75103

There is a cart object where you can attach a customer and products.

information on cart_product.add (SOAP v1) or shoppingCartProductAdd (SOAP v2) is in Magento API documenattion

http://www.magentocommerce.com/api/soap/checkout/cartProduct/cart_product.add.html

Upvotes: 0

Related Questions