创建订单prestashop api php

时间:2015-04-21 11:30:18

标签: php api prestashop

我尝试使用Prestashop的REST API创建订单,但我总是收到此错误:

  

400 Bad Request。

我发现了很多关于这个问题的主题,但仍未找到解决方案。 我的手机应用程序需要这个。

这是我的PHP代码:

$psXML = <<<XML

<prestashop>

<order>
<id/>
<id_address_delivery>11</id_address_delivery>
<id_address_invoice>11</id_address_invoice>
<id_cart>29</id_cart>
<id_currency>1</id_currency>
<id_lang>1</id_lang>
<id_customer>4</id_customer>
<id_carrier>2</id_carrier>
<current_state>11</current_state>
<module>paypal</module>
<invoice_number/>
<invoice_date/>
<delivery_number/>
<delivery_date/>
<valid/>
<date_add/>
<date_upd/>
<shipping_number/>
<id_shop_group>1</id_shop_group>
<id_shop>1</id_shop>
<secure_key>5c42fc9716c397e39275f2f60e243f4d</secure_key>
<payment>PayPal</payment>
<recyclable/>
<gift/>
<gift_message/>
<mobile_theme/>
<total_discounts/>
<total_discounts_tax_incl/>
<total_discounts_tax_excl/>
<total_paid/>
<total_paid_tax_incl/>
<total_paid_tax_excl/>
<total_paid_real/>
<total_products/>
<total_products_wt/>
<total_shipping/>
<total_shipping_tax_incl/>
<total_shipping_tax_excl/>
<carrier_tax_rate/>
<total_wrapping/>
<total_wrapping_tax_incl/>
<total_wrapping_tax_excl/>
<conversion_rate/>
<reference></reference>
<associations>
<order_rows>
<order_rows>
<id/>
<product_id>7</product_id>
<product_attribute_id>34</product_attribute_id>
<product_quantity>1</product_quantity>
<product_name>Robe de soie imprimée - Couleur : Jaune, Taille : S</product_name>
<product_reference>demo_7</product_reference>
<product_ean13/>
<product_upc/>
<product_price>20.501236</product_price>
<unit_price_tax_incl/>
<unit_price_tax_excl/>
</order_rows>
</order_rows>
</associations>
</order>
</prestashop>

XML;



try {
$webService = new PrestaShopWebservice($serverUrl, $serverApiKey, true);
$xml = new SimpleXMLElement($psXML);

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

$xml = $webService->add( $opt );
}
catch (PrestaShopWebserviceException $ex)
{
    echo 'Other error: <br />' . $ex->getMessage();
}

1 个答案:

答案 0 :(得分:0)

我认为你的xml有问题,请填写下面给出的数据(所有都不是必需的),你可以通过访问http://ur-domain.com/api/orders?schema=synopsis来检查所需的字段

<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<order>
    <id><![CDATA[1]]></id>
    <id_address_delivery xlink:href="http://localhost/demo-ps/api/addresses/4"><![CDATA[4]]></id_address_delivery>
    <id_address_invoice xlink:href="http://localhost/demo-ps/api/addresses/4"><![CDATA[4]]></id_address_invoice>
    <id_cart xlink:href="http://localhost/demo-ps/api/carts/1"><![CDATA[1]]></id_cart>
    <id_currency xlink:href="http://localhost/demo-ps/api/currencies/1"><![CDATA[1]]></id_currency>
    <id_lang xlink:href="http://localhost/demo-ps/api/languages/1"><![CDATA[1]]></id_lang>
    <id_customer xlink:href="http://localhost/demo-ps/api/customers/1"><![CDATA[1]]></id_customer>
    <id_carrier xlink:href="http://localhost/demo-ps/api/carriers/2"><![CDATA[2]]></id_carrier>
    <current_state xlink:href="http://localhost/demo-ps/api/order_states/6" notFilterable="true"><![CDATA[6]]></current_state>
    <module><![CDATA[cheque]]></module>
    <invoice_number><![CDATA[0]]></invoice_number>
    <invoice_date><![CDATA[0000-00-00 00:00:00]]></invoice_date>
    <delivery_number><![CDATA[0]]></delivery_number>
    <delivery_date><![CDATA[0000-00-00 00:00:00]]></delivery_date>
    <valid><![CDATA[0]]></valid>
    <date_add><![CDATA[2015-01-21 07:15:07]]></date_add>
    <date_upd><![CDATA[2015-01-21 07:15:18]]></date_upd>
    <shipping_number notFilterable="true"></shipping_number>
    <id_shop_group><![CDATA[1]]></id_shop_group>
    <id_shop><![CDATA[1]]></id_shop>
    <secure_key><![CDATA[b44a6d9efd7a0076a0fbce6b15eaf3b1]]></secure_key>
    <payment><![CDATA[Payment by check]]></payment>
    <recyclable><![CDATA[0]]></recyclable>
    <gift><![CDATA[0]]></gift>
    <gift_message></gift_message>
    <mobile_theme><![CDATA[0]]></mobile_theme>
    <total_discounts><![CDATA[0.000000]]></total_discounts>
    <total_discounts_tax_incl><![CDATA[0.000000]]></total_discounts_tax_incl>
    <total_discounts_tax_excl><![CDATA[0.000000]]></total_discounts_tax_excl>
    <total_paid><![CDATA[55.000000]]></total_paid>
    <total_paid_tax_incl><![CDATA[55.000000]]></total_paid_tax_incl>
    <total_paid_tax_excl><![CDATA[55.000000]]></total_paid_tax_excl>
    <total_paid_real><![CDATA[0.000000]]></total_paid_real>
    <total_products><![CDATA[53.000000]]></total_products>
    <total_products_wt><![CDATA[53.000000]]></total_products_wt>
    <total_shipping><![CDATA[2.000000]]></total_shipping>
    <total_shipping_tax_incl><![CDATA[2.000000]]></total_shipping_tax_incl>
    <total_shipping_tax_excl><![CDATA[2.000000]]></total_shipping_tax_excl>
    <carrier_tax_rate><![CDATA[0.000]]></carrier_tax_rate>
    <total_wrapping><![CDATA[0.000000]]></total_wrapping>
    <total_wrapping_tax_incl><![CDATA[0.000000]]></total_wrapping_tax_incl>
    <total_wrapping_tax_excl><![CDATA[0.000000]]></total_wrapping_tax_excl>
    <round_mode><![CDATA[0]]></round_mode>
    <conversion_rate><![CDATA[1.000000]]></conversion_rate>
    <reference><![CDATA[XKBKNABJK]]></reference>
<associations>
<order_rows nodeType="order_row" virtualEntity="true">
    <order_row>
    <id><![CDATA[1]]></id>
    <product_id><![CDATA[2]]></product_id>
    <product_attribute_id><![CDATA[10]]></product_attribute_id>
    <product_quantity><![CDATA[1]]></product_quantity>
    <product_name><![CDATA[Blouse - Color : White, Size : M]]></product_name>
    <product_reference><![CDATA[demo_2]]></product_reference>
    <product_ean13></product_ean13>
    <product_upc></product_upc>
    <product_price><![CDATA[26.999852]]></product_price>
    <unit_price_tax_incl><![CDATA[27.000000]]></unit_price_tax_incl>
    <unit_price_tax_excl><![CDATA[27.000000]]></unit_price_tax_excl>
    </order_row>
    <order_row>
    <id><![CDATA[2]]></id>
    <product_id><![CDATA[3]]></product_id>
    <product_attribute_id><![CDATA[13]]></product_attribute_id>
    <product_quantity><![CDATA[1]]></product_quantity>
    <product_name><![CDATA[Printed Dress - Color : Orange, Size : S]]></product_name>
    <product_reference><![CDATA[demo_3]]></product_reference>
    <product_ean13></product_ean13>
    <product_upc></product_upc>
    <product_price><![CDATA[25.999852]]></product_price>
    <unit_price_tax_incl><![CDATA[26.000000]]></unit_price_tax_incl>
    <unit_price_tax_excl><![CDATA[26.000000]]></unit_price_tax_excl>
    </order_row>
</order_rows>
</associations>
</order>
</prestashop>
相关问题