保存订单prestashop Web服务

时间:2017-07-11 17:19:59

标签: web-services prestashop-1.6

我是prestashop webservice的新手,我试图在prestashop中保存订单 数据库,但我收到此错误:表ps_orders不存在,这是正常的,因为我的表的前缀不同于ps_:

这是我的代码:

define('DEBUG', true); define('PS_SHOP_PATH', 'http://localhost/prestashop'); define('PS_WS_AUTH_KEY', 'CQP84L4R3GB6IV99E5WSP4JPSWXDYE1R'); require_once('./PSWebServiceLibrary.php'); try{ $webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG); $xml = $webService->get( array('url' => PS_SHOP_PATH.'/api/carts?schema=blank') ); $resources = $xml->children()->children(); $id_currency = 3; $id_lang = 2; $id_product = 2571; // $attribute_product = $id_address = 8; $qte_product = 1; $id_customer = 3; $id_carrier = 3; $date_now = date('Y-m-d H:i:s'); $name_product = 'produit 111 '; // $reference_product = ; $price_product = 320; $tax_inclu_product = 320; $tax_excl_product = 320; $order_module = 'cashondelivery'; $order_payment = 'Cash on delivery (COD)'; $total_paid = 355; $total_paid_real = 355; $total_products = $price_product; $total_products_wt = $price_product; $id_status = 5; // status de la commande : livré, en cours $total_discounts =0; $total_discounts_tax_incl = $total_discounts; $total_discounts_tax_excl = $total_discounts; $total_paid_tax_incl = 355; $total_paid_tax_excl = 355; $total_shipping = 35 ; //frais selon la ville de livraison $total_shipping_tax_incl = $total_shipping; $total_shipping_tax_excl = $total_shipping; $xml->cart->id_currency = $id_currency; $xml->cart->id_lang = $id_lang; $xml->cart->associations->cart_rows->cart_row[0]->id_product = $id_product; // $xml->cart->associations->cart_rows->cart_row[0]->id_product_attribute = $attribute_product; $xml->cart->associations->cart_rows->cart_row[0]->id_address_delivery = $id_address; $xml->cart->associations->cart_rows->cart_row[0]->quantity = $qte_product; // Others $xml->cart->id_address_delivery = $id_address; $xml->cart->id_address_invoice = $id_address; $xml->cart->id_customer = $id_customer; $xml->cart->id_carrier = $id_carrier; $xml->cart->date_add = $date_now; $xml->cart->date_upd = $date_now; // Adding the new customer's cart $opt = array( 'resource' => 'carts' ); $opt['postXml'] = $xml->asXML(); $xml = $webService->add( $opt ); $id_cart = $xml->cart->id; // ORDER $xml = $webService->get(array('url' => PS_SHOP_PATH .'/api/orders/?schema=blank')); // Adding dinamic and required fields // Required $xml->order->id_address_delivery = $id_address; // Customer 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_customer = $id_customer; $xml->order->id_carrier = $id_carrier; $xml->order->module = $order_module; $xml->order->payment = $order_payment; $xml->order->total_paid = $total_paid; $xml->order->total_paid_real = $total_paid_real; $xml->order->total_products = $total_products; $xml->order->total_products_wt = $total_products_wt; $xml->order->conversion_rate = 1; // Others $xml->order->valid = 1; $xml->order->current_state = 1; $xml->order->total_discounts = $total_discounts; $xml->order->total_discounts_tax_incl = $total_discounts_tax_incl; $xml->order->total_discounts_tax_excl = $total_discounts_tax_excl; $xml->order->total_paid_tax_incl = $total_paid_tax_incl; $xml->order->total_paid_tax_excl = $total_paid_tax_excl; $xml->order->total_shipping = $total_shipping; $xml->order->total_shipping_tax_incl = $total_shipping_tax_incl; $xml->order->total_shipping_tax_excl = $total_shipping_tax_excl; // Order Row. Required $xml->order->associations->order_rows->order_row[0]->product_id = $id_product; //$xml->order->associations->order_rows->order_row[0]->product_attribute_id = $attribute_product; $xml->order->associations->order_rows->order_row[0]->product_quantity = $qte_product; // Order Row. Others $xml->order->associations->order_rows->order_row[0]->product_name = $name_product; // $xml->order->associations->order_rows->order_row[0]->product_reference = $reference_produc; $xml->order->associations->order_rows->order_row[0]->product_price = $price_product; $xml->order->associations->order_rows->order_row[0]->unit_price_tax_incl = $tax_inclu_product; $xml->order->associations->order_rows->order_row[0]->unit_price_tax_excl = $tax_excl_product; // Creating the order $opt = array( 'resource' => 'orders' ); $opt['postXml'] = $xml->asXML(); $xml = $webService->add( $opt ); $id_order = $xml->order->id; echo "Customer 1 : ".$id_customer." address: ".$id_address." cart: ".$id_cart." Order: .".$id_order; } catch (PrestaShopWebserviceException $e) { // Here we are dealing with errors $trace = $e->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 />'.$e->getMessage(); }

enter image description here

0 个答案:

没有答案