php - 使用网络服务在 prestashop 下完整订单

标签 php android web-services prestashop

我正在尝试通过网络服务在 prestashop 中添加订单。但我的订单每次都出现付款错误。问题是我的折扣和运费没有反射(reflect)在管理仪表板的订单面板中。

这是我的代码:

$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;

The problem is with admin dashboard. Coupons and shipping is not getting applied. so it is changing my payment status to payment error

最佳答案

要通过网络服务下订单,您需要直接向数据库添加一些与购物车表中的购物车交付选项有关的条目,并且对于折扣,请在 ps_cart_cart_rule 表中添加条目,然后按照您的下订单进行下单。

foreach ($raw_data['discounts'] as $discount) {
foreach ($raw_data['discounts'] as $discount) {
    $sql = "insert into ps_cart_cart_rule values('" . $id['cart'] . "','" . $discount['id_cart_rule'] . "')";
    $r = mysql_query($sql, $conn)or die(mysql_error($conn));
}

$sql = "update ps_cart set `delivery_option`='a:1:{i:" . $id['address'] . ";s:3:\"" . $id['carrier'] . ",\";}', `id_carrier`='" . $id['carrier'] . "' where id_cart='" . $id['cart'] . "'";
$r = mysql_query($sql, $conn)or die(mysql_error($conn));


$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 = $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');
$opt['postXml'] = $xml->asXML();
$xml = $webService->add($opt);
$id['order'] = $xml->order->id;
$id['secure_key'] = $xml->order->secure_key;

关于php - 使用网络服务在 prestashop 下完整订单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38982393/

相关文章:

java - 如何使用php将mysql中的多行编码为json

c# - 如何更改 WSDL 客户端的预期内容类型?

php - 错误地在sql中显示产品

java - 在 Android 中搜索从 XML 解析的数组

android - 摩托罗拉 Defy 上的 ImageView 是黑色的

Android 解析主机

web-services - 将 Web 服务输入到 Azure ML 中的 R 中的 SQL 查询中

php - WordPress 中的 JQuery Masonry 和无限滚动

php - 在准备好的语句的 where 子句中使用计数值

php - Google Maps API 3 从当前位置从 MySQL 加载标记