webservicesを使用してprestashopで注文を追加しようとしています。しかし、私の注文は毎回支払いエラーになっています。問題は私の割引で、配送は管理ダッシュボードのオーダーパネルに反映されていません。プレーストップでwebserviceを使用して注文を完了
は、ここに私のコードです:
$webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);
$customer = array();
$product = array();
$id['country'] = '165';
$id['lang'] = $raw_data['id_lang'];
$id['currency'] = $raw_data['id_currency'];
$id['carrier'] = $raw_data['id_carrier'];
$product['order_rows'] = $raw_data['order_rows'];
// $product['id'] = $id_product;
// $product['price'] = Product::getPriceStatic($product['id']);
// $product['name'] = Product::getProductName($product['id']);
//$product['total'] = $product['price'] * $product['quantity'];
$customerid = $raw_data['id_customer'];
// ID of created customer
$id['customer'] = $customerid;
// CREATE Address
$addresid = $raw_data['id_address_delivery'];
// ID of created address
$id['address'] = $addresid;
// CREATE Cart
$cartid = $raw_data['id_cart'];
// ID of created cart
$id['cart'] = $cartid;
//$sql = "select id_order from ps_orders order by id_order desc limit 0,1";
//$r = mysql_query($sql, $conn)or die(mysql_error($conn));
//$row = mysql_fetch_assoc($r);
//// CREATE Order
//$id['order'] = $row['id_order'] + 1;
$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 = $id['carrier'];
$xml->order->current_state = "3";
$xml->order->valid = 0;
$xml->order->total_shipping = $raw_data['total_shipping'];
$xml->order->total_shipping_tax_incl = $raw_data['total_shipping'];
$xml->order->total_shipping_tax_excl = $raw_data['total_shipping'];
$xml->order->total_discounts = $raw_data['total_discounts'];
$xml->order->total_discounts_tax_incl = $raw_data['total_discounts'];
$xml->order->total_discounts_tax_excl = $raw_data['total_discounts'];
$xml->order->payment = 'Cash on delivery';
$xml->order->module = 'cashondelivery';
$xml->order->total_products = $raw_data['total_products'];
$xml->order->total_products_wt = $raw_data['total_products'];
$xml->order->total_paid = "0";
$xml->order->total_paid_tax_incl = "0";
$xml->order->total_paid_tax_excl ="0";
$xml->order->total_paid_real = "0";
$xml->order->conversion_rate = '1';
// foreach ($products as $product){
// $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);
//$xml=$webService->parseXML($xml);
$id['order'] = $xml->order->id;
//var_dump($xml->order);
$id['secure_key'] = $xml->order->secure_key;
$xml = $webService->get(array('url' => PS_SHOP_PATH . '/api/order_carriers?schema=blank'));
$xml->order_carrier->id_carrier = $id['carrier'];
$xml->order_carrier->id_order = $id['order'];
$xml->order_carrier->shipping_cost_tax_excl = $raw_data['total_shipping'];
$xml->order_carrier->shipping_cost_tax_incl = $raw_data['total_shipping'];
$opt = array('resource' => 'order_carriers');
$opt['postXml'] = $xml->asXML();
$xml = $webService->add($opt);
foreach ($raw_data['discounts'] as $discount) {
$xml = $webService->get(array('url' => PS_SHOP_PATH . '/api/order_discounts?schema=blank'));
$xml->order_cart_rule->id_cart_rule = $discount['id_cart_rule'];
$xml->order_cart_rule->id_order = $id['order'];
$xml->order_cart_rule->value = $discount['value'];
$xml->order_cart_rule->name = $discount['name'];
$xml->order_cart_rule->value_tax_excl = $discount['value'];
$opt = array('resource' => 'order_discounts');
$opt['postXml'] = $xml->asXML();
$xml = $webService->add($opt);
}
$sql = "update ps_order_history set id_order_state=3 where id_order=" . $id['order'];
$r = mysql_query($sql, $conn)or die(mysql_error($conn));
$xml = $webService->get(array('url' => PS_SHOP_PATH . '/api/orders/'.$id['order']));
$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 = $id['carrier'];
$xml->order->current_state = "3";
$xml->order->valid = 0;
$xml->order->total_shipping = $raw_data['total_shipping'];
$xml->order->total_shipping_tax_incl = $raw_data['total_shipping'];
$xml->order->total_shipping_tax_excl = $raw_data['total_shipping'];
$xml->order->total_discounts = $raw_data['total_discounts'];
$xml->order->total_discounts_tax_incl = $raw_data['total_discounts'];
$xml->order->total_discounts_tax_excl = $raw_data['total_discounts'];
$xml->order->payment = 'Cash on delivery';
$xml->order->module = 'cashondelivery';
$xml->order->total_products = $raw_data['total_products'];
$xml->order->total_products_wt = $raw_data['total_products'];
$xml->order->total_paid = $raw_data['total_paid'];
$xml->order->total_paid_tax_incl = $raw_data['total_paid'];
$xml->order->total_paid_tax_excl =$raw_data['total_paid'];
$xml->order->total_paid_real = "0";
$xml->order->conversion_rate = '1';
$opt = array('resource' => 'orders',"id"=>$id['order']);
$opt['putXml'] = $xml->asXML();
$xml = $webService->edit($opt);
$id['orderrefer'] = $xml->order->reference;
私は、出荷と割引のためのテーブルをDBへの直接のエントリで私の問題を解決した
あなたはエラーを報告することができますか?どのprestashopのバージョンを使用していますか? – sarcom
hello sarcom、私は何の誤りもありません。管理ダッシュボードに問題があります。もし私が割引と送料を使用しているなら、それは支払いエラーです。管理ダッシュボードのスクリーンショットを追加しました。私のprestashopバージョンは1.6.0.14です –
webservicesで注文するときに送料、割引などの正しい計算をする必要があります。なぜなら、Webから注文すると、この計算を行うためのprestashopなので、間違った数字を入力するとwebservicesによってエラーが発生します。 – sarcom