alexvs1980 Posted March 9, 2013 Share Posted March 9, 2013 (edited) Hi everyone, I'm able to create customers and addresses through web services but I'm having problems creating orders. Here the code: <?php define('DEBUG', true); define('_PS_DEBUG_SQL_', true); define('PS_SHOP_PATH', '...'); define('PS_WS_AUTH_KEY', '.....'); require_once('./PSWebServiceLibrary.php'); try { $webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG); $opt = array('resource' => 'orders'); $xml = $webService->get(array('url' => PS_SHOP_PATH.'/api/orders?schema=synopsis')); $resources = $xml->children()->children(); $resources->id_address_delivery = '5'; $resources->id_address_invoice = '5'; $resources->id_cart = '11'; $resources->id_currency = '1'; $resources->id_lang = '4'; $resources->id_costumer = '20'; $resources->id_carrier = '0'; $resources->total_paid = '3.99'; $resources->total_paid_real = '3.99'; $resources->total_paid_real = '3.99'; $resources->total_products = '3.99'; $resources->total_products_wt = '3.99'; $resources->conversion_rate = '1.0'; $resources->module = 'cheque'; $resources->Payment = 'Cheque'; $opt = array('resource' => 'orders'); $opt['postXml'] = $xml->asXML(); $xml = $webService->add($opt); } catch (PrestaShopWebserviceException $ex) { // Here we are dealing with errors $trace = $ex->getTrace(); if ($trace[0]['args'][0] == 404) echo 'Bad ID'; else if ($trace[0]['args'][0] == 401) echo 'Bad auth key'; else echo 'Other error<br />'.$ex->getMessage().'<br><br>'; } ?> Could you help me fixing it ? Thank you in advance !! Edited March 9, 2013 by alexvs1980 (see edit history) Link to comment Share on other sites More sharing options...
loreian Posted May 21, 2013 Share Posted May 21, 2013 i have the same problem. the error is: HTTP XML response is not parsable : array ( 0 => LibXMLError::__set_state(array( 'level' => 3, 'code' => 9, 'column' => 65, 'message' => 'Input is not proper UTF-8, indicate encoding ! Bytes: 0xBE 0x4C 0x6A 0x90 ', 'file' => '', 'line' => 754, )), 1 => LibXMLError::__set_state(array( 'level' => 3, 'code' => 64, 'column' => 51, 'message' => 'XML declaration allowed only at the start of the document ', 'file' => '', 'line' => 10421, )), 2 => LibXMLError::__set_state(array( 'level' => 3, 'code' => 64, 'column' => 51, 'message' => 'XML declaration allowed only at the start of the document ', 'file' => '', 'line' => 13161, )), 3 => LibXMLError::__set_state(array( 'level' => 3, 'code' => 64, 'column' => 51, 'message' => 'XML declaration allowed only at the start of the document ', 'file' => '', 'line' => 15900, )), 4 => LibXMLError::__set_state(array( 'level' => 3, 'code' => 64, 'column' => 33, 'message' => 'XML declaration allowed only at the start of the document ', 'file' => '', 'line' => 16485, )), ) help Link to comment Share on other sites More sharing options...
AbdullahBasit Posted December 31, 2015 Share Posted December 31, 2015 $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 More sharing options...
hakim Posted August 30, 2018 Share Posted August 30, 2018 $webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG); $xml = $webService->get(array('url' => PS_SHOP_PATH . '/api/orders?schema=blank')); $resources = $xml->children()->children(); $resources->id_address_delivery='11'; $resources->id_address_invoice='11'; $resources->id_cart='53'; $resources->id_currency='1'; $resources->id_lang='1'; $resources->id_customer='52'; $resources->id_carrier='1'; $resources->current_state='1'; $resources->module='cashondelivery'; $resources->invoice_number='3'; $resources->invoice_date='2018-08-27 10:48:12'; $resources->delivery_number='2'; $resources->delivery_date='2018-08-27 10:48:12'; $resources->valid='1'; $resources->date_add='2018-07-19 14:56:16'; $resources->date_upd='2018-08-27 10:48:14'; $resources->shipping_number ='true'; $resources->id_shop_group='1'; $resources->id_shop='1'; $resources->secure_key='b44a6d9efd7a0076a21bce6b19eaf3b1'; $resources->payment='Commande gratuite'; $resources->recyclable='0'; $resources->gift>=' '; $resources->gift_message=''; $resources->mobile_theme='0'; $resources->total_discounts='0.000000'; $resources->total_discounts_tax_incl='0.000000'; $resources->total_discounts_tax_excl='0.000000'; $resources->total_paid='55.000000'; $resources->total_paid_tax_incl='55.000000'; $resources->total_paid_tax_excl='55.000000'; $resources->total_paid_real='55.000000'; $resources->total_products='53.000000'; $resources->total_products_wt='53.000000'; $resources->total_shipping='2.000000'; $resources->total_shipping_tax_incl='2.000000'; $resources->total_shipping_tax_excl='2.000000'; $resources->carrier_tax_rate='0.000'; $resources->total_wrapping='0.000000'; $resources->total_wrapping_tax_incl='0.000000'; $resources->total_wrapping_tax_excl='0.000000'; $resources->round_mode='0'; $resources->round_type='0'; $resources->conversion_rate='1.000000'; $resources->reference='XKBKNACJl'; $resources->product_ean13='0'; $resources->product_upc='0'; $resources->product_attribute_id='0'; $resources->associations->order_rows->order_row->product_id ='106'; $resources->associations->order_rows->order_row->product_quantity ='2'; $resources->associations->order_rows->order_row->product_name ='MIRINDA 33cl'; $resources->associations->order_rows->order_row->product_price ='00'; $resources->associations->order_rows->order_row->unit_price_tax_incl ='00'; $resources->associations->order_rows->order_row->unit_price_tax_excl ='00'; try { $opt = array('resource' => 'orders'); $opt['postXml'] = $xml->asXML(); $xml = $webService->add($opt); } catch(PrestaShopWebserviceException $ex) { $trace = $ex->getTrace(); $errorCode = $trace[0]['args'][0]; if ($errorCode==401) { echo 'Mauvaise cle authentification curl'; } else { echo 'Autre erreur : <br />'; echo $ex->getMessage().'<br />'; echo 'Code : '.$ex->getCode().'<br />'; echo 'Trace : '.print_r($ex->getTrace()).'<br />'; echo $ex->getFile().'<br />'; echo $ex->getLine().'<br />'; } } problem for adding order help me plz Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now