Jump to content

[HELP] Step-by-step to create order via webservice


An'im Fahmy

Recommended Posts

Hello,

I was read and reply all related topic about creating order via webservice, but not found the solution.

 

I was succeed 

1. creating customer;

2. creating address, and;

3. creating cart

 

All can accessed in www.mystore.com/api/

 

But, when I am create order, I have error status: Bad Parameter Given.

 

Must I do task after create cart and before create order?

 

I am sorry for bad english

 

 

Thank you,

 

Regards,

Edited by An'im Fahmy (see edit history)
Link to comment
Share on other sites

  • 3 weeks later...

Hello,

I was looking at the resource description for orders ie yourdomain/orders?schema=synopsis" and it seems that you need to create the association with the products in new nodes named order_row.

 

I hope it helps.

 

Best regards,

Link to comment
Share on other sites

  • 2 months later...
$webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);

            $xml = $webService->get(array('url' => PS_SHOP_PATH.'/api/customers/?schema=synopsis'));

 

            $customer = array();

            $product = array();

 

            if (!empty(Tools::getValue('c_email')))

                $customer['email'] = Tools::getValue('c_email');

            else

                $customer['email'] = '[email protected]';

 

            $customer['firstname'] = Tools::getValue('fname');

            $customer['lastname'] = Tools::getValue('lname');

            $customer['address1'] = Tools::getValue('c_address');

            $customer['city'] = Tools::getValue('c_city');

            $customer['phone'] = Tools::getValue('c_phone');

 

            $id['country'] = '165';

            $id['lang'] = '1';

            $id['currency'] = '1';

            $id['carrier'] = '3';

 

            $product['quantity'] = Tools::getValue('c_qty');

            $product['id'] = $id_product;

            $product['price'] = Product::getPriceStatic($product['id']);

            $product['name'] = Product::getProductName($product['id']);

 

            $product['total'] = $product['price'] * $product['quantity'];

 

            $xml->customer->firstname = $customer['firstname'];

            $xml->customer->lastname = $customer['lastname'];

            $xml->customer->email = $customer['email'];

            $xml->customer->newsletter = '1';

            $xml->customer->optin = '1';

            $xml->customer->active = '1';

 

 

            $opt = array('resource' => 'customers');

            $opt['postXml'] = $xml->asXML();

            $xml = $webService->add($opt);

 

            // ID of created customer

 

            $id['customer'] = $xml->customer->id;

 

            // CREATE Address

 

            $xml = $webService->get(array('url' => PS_SHOP_PATH.'/api/addresses?schema=synopsis'));

 

            $xml->address->id_customer = $id['customer'];

            $xml->address->firstname = $customer['firstname'];

            $xml->address->lastname = $customer['lastname'];

            $xml->address->address1 = $customer['address1'];

            $xml->address->city = $customer['city'];

            $xml->address->phone_mobile = $customer['phone'];

            $xml->address->id_country = $id['country'];

            $xml->address->alias = '-';

 

            $opt = array('resource' => 'addresses');

            $opt['postXml'] = $xml->asXML();

            $xml = $webService->add($opt);

 

            // ID of created address

 

            $id['address'] = $xml->address->id;

 

            // CREATE Cart

 

            $xml = $webService->get(array('url' => PS_SHOP_PATH.'/api/carts?schema=blank'));

 

            $xml->cart->id_customer = $id['customer'];

            $xml->cart->id_address_delivery = $id['address'];

            $xml->cart->id_address_invoice = $id['address'];

            $xml->cart->id_currency = $id['currency'];

            $xml->cart->id_lang = $id['lang'];

            $xml->cart->id_carrier = $id['carrier'];

 

            $xml->cart->associations->cart_rows->cart_row->id_product = $product['id'];

            $xml->cart->associations->cart_rows->cart_row->quantity = $product['quantity'];

            if(!empty(Tools::getValue('product_attr')))

                $xml->cart->associations->cart_rows->cart_row->id_product_attribute = Tools::getValue('product_attr');

 

            $opt = array('resource' => 'carts');

            $opt['postXml'] = $xml->asXML();

            $xml = $webService->add($opt);

 

            // ID of created cart

 

            $id['cart'] = $xml->cart->id;

 

            // CREATE Order

 

            $xml = $webService->get(array('url' => PS_SHOP_PATH.'/api/orders?schema=blank'));

 

            $xml->order->id_customer = $id['customer'];

            $xml->order->id_address_delivery = $id['address'];

            $xml->order->id_address_invoice = $id['address'];

            $xml->order->id_cart = $id['cart'];

            $xml->order->id_currency = $id['currency'];

            $xml->order->id_lang = $id['lang'];

            $xml->order->id_carrier = 3;

            $xml->order->current_state = 3;

            $xml->order->valid = 0;

            $xml->order->payment = 'Cash on delivery';

            $xml->order->module = 'cashondelivery';

            $xml->order->total_paid = $product['total'];

            $xml->order->total_paid_tax_incl = $product['total'];

            $xml->order->total_paid_tax_excl = $product['total'];

            $xml->order->total_paid_real = '0';

            $xml->order->total_products = $product['total'];

            $xml->order->total_products_wt = $product['total'];

            $xml->order->conversion_rate = '1';

 

 

            $xml->order->associations->order_rows->order_row->product_id = $product['id'];

            $xml->order->associations->order_rows->order_row->product_quantity = $product['quantity'];

 

 

            $opt = array('resource' => 'orders');

            $opt['postXml'] = $xml->asXML();

            $xml = $webService->add($opt);

 

            $id['order'] = $xml->order->id;

            $id['secure_key'] = $xml->order->secure_key;

 

            $xml = $webService->get(array('url' => PS_SHOP_PATH.'/api/order_histories?schema=blank'));

 

            $xml->order_history->id_order = $id['order'];

            $xml->order_history->id_order_state = '3';

 

            $opt = array('resource' => 'order_histories');

            $opt['postXml'] = $xml->asXML();

            $xml = $webService->add($opt);

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...

You can create customer as follows:

 

            $xml->customer->firstname = $customer['firstname'];
            $xml->customer->lastname = $customer['lastname'];
            $xml->customer->email = $customer['email'];
            $xml->customer->newsletter = '1';
            $xml->customer->optin = '1';
            $xml->customer->active = '1';
 
 
            $opt = array('resource' => 'customers');
            $opt['postXml'] = $xml->asXML();
            $xml = $webService->add($opt);
Link to comment
Share on other sites

  • 3 months later...

Hi,

 

My current_state is always 12, even when I insert 3.

 

$xml->order->current_state = 3;

 

 

Can you help me?

 

Thanks

 

 

$webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);
            $xml = $webService->get(array('url' => PS_SHOP_PATH.'/api/customers/?schema=synopsis'));
 
            $customer = array();
            $product = array();
 
            if (!empty(Tools::getValue('c_email')))
                $customer['email'] = Tools::getValue('c_email');
            else
                $customer['email'] = '[email protected]';
 
            $customer['firstname'] = Tools::getValue('fname');
            $customer['lastname'] = Tools::getValue('lname');
            $customer['address1'] = Tools::getValue('c_address');
            $customer['city'] = Tools::getValue('c_city');
            $customer['phone'] = Tools::getValue('c_phone');
 
            $id['country'] = '165';
            $id['lang'] = '1';
            $id['currency'] = '1';
            $id['carrier'] = '3';
 
            $product['quantity'] = Tools::getValue('c_qty');
            $product['id'] = $id_product;
            $product['price'] = Product::getPriceStatic($product['id']);
            $product['name'] = Product::getProductName($product['id']);
 
            $product['total'] = $product['price'] * $product['quantity'];
 
            $xml->customer->firstname = $customer['firstname'];
            $xml->customer->lastname = $customer['lastname'];
            $xml->customer->email = $customer['email'];
            $xml->customer->newsletter = '1';
            $xml->customer->optin = '1';
            $xml->customer->active = '1';
 
 
            $opt = array('resource' => 'customers');
            $opt['postXml'] = $xml->asXML();
            $xml = $webService->add($opt);
 
            // ID of created customer
 
            $id['customer'] = $xml->customer->id;
 
            // CREATE Address
 
            $xml = $webService->get(array('url' => PS_SHOP_PATH.'/api/addresses?schema=synopsis'));
 
            $xml->address->id_customer = $id['customer'];
            $xml->address->firstname = $customer['firstname'];
            $xml->address->lastname = $customer['lastname'];
            $xml->address->address1 = $customer['address1'];
            $xml->address->city = $customer['city'];
            $xml->address->phone_mobile = $customer['phone'];
            $xml->address->id_country = $id['country'];
            $xml->address->alias = '-';
 
            $opt = array('resource' => 'addresses');
            $opt['postXml'] = $xml->asXML();
            $xml = $webService->add($opt);
 
            // ID of created address
 
            $id['address'] = $xml->address->id;
 
            // CREATE Cart
 
            $xml = $webService->get(array('url' => PS_SHOP_PATH.'/api/carts?schema=blank'));
 
            $xml->cart->id_customer = $id['customer'];
            $xml->cart->id_address_delivery = $id['address'];
            $xml->cart->id_address_invoice = $id['address'];
            $xml->cart->id_currency = $id['currency'];
            $xml->cart->id_lang = $id['lang'];
            $xml->cart->id_carrier = $id['carrier'];
 
            $xml->cart->associations->cart_rows->cart_row->id_product = $product['id'];
            $xml->cart->associations->cart_rows->cart_row->quantity = $product['quantity'];
            if(!empty(Tools::getValue('product_attr')))
                $xml->cart->associations->cart_rows->cart_row->id_product_attribute = Tools::getValue('product_attr');
 
            $opt = array('resource' => 'carts');
            $opt['postXml'] = $xml->asXML();
            $xml = $webService->add($opt);
 
            // ID of created cart
 
            $id['cart'] = $xml->cart->id;
 
            // CREATE Order
 
            $xml = $webService->get(array('url' => PS_SHOP_PATH.'/api/orders?schema=blank'));
 
            $xml->order->id_customer = $id['customer'];
            $xml->order->id_address_delivery = $id['address'];
            $xml->order->id_address_invoice = $id['address'];
            $xml->order->id_cart = $id['cart'];
            $xml->order->id_currency = $id['currency'];
            $xml->order->id_lang = $id['lang'];
            $xml->order->id_carrier = 3;
            $xml->order->current_state = 3;
            $xml->order->valid = 0;
            $xml->order->payment = 'Cash on delivery';
            $xml->order->module = 'cashondelivery';
            $xml->order->total_paid = $product['total'];
            $xml->order->total_paid_tax_incl = $product['total'];
            $xml->order->total_paid_tax_excl = $product['total'];
            $xml->order->total_paid_real = '0';
            $xml->order->total_products = $product['total'];
            $xml->order->total_products_wt = $product['total'];
            $xml->order->conversion_rate = '1';
 
 
            $xml->order->associations->order_rows->order_row->product_id = $product['id'];
            $xml->order->associations->order_rows->order_row->product_quantity = $product['quantity'];
 
 
            $opt = array('resource' => 'orders');
            $opt['postXml'] = $xml->asXML();
            $xml = $webService->add($opt);
 
            $id['order'] = $xml->order->id;
            $id['secure_key'] = $xml->order->secure_key;
 
            $xml = $webService->get(array('url' => PS_SHOP_PATH.'/api/order_histories?schema=blank'));
 
            $xml->order_history->id_order = $id['order'];
            $xml->order_history->id_order_state = '3';
 
            $opt = array('resource' => 'order_histories');
            $opt['postXml'] = $xml->asXML();
            $xml = $webService->add($opt);

 

Link to comment
Share on other sites

  • 2 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...