Read XML from Prestashop API (SimpleXMLElement)



我试图通过Prestashop的网络服务阅读在线商店的订单。连接和读取正常,但问题是当我尝试使用数据时

//CONNECTION
$webService = new PrestaShopWebservice('http://example.com/', 'N1285LRSTHSRTHRTHRTUI5Q9X6', true);
// ORDERS
$xml = $webService->get(['resource' => 'orders','display'=>'full']);
foreach ($xml->order as $order) {
echo $test = $order->order->payment;
}

这是 XML

<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<orders>
<order>
<id><![CDATA[1]]></id>
<module><![CDATA[redsys]]></module>
<invoice_number><![CDATA[6]]></invoice_number>
<invoice_date><![CDATA[2020-04-13 15:36:28]]></invoice_date>
<delivery_number><![CDATA[1]]></delivery_number>
<delivery_date><![CDATA[2020-04-16 12:19:31]]></delivery_date>
<valid><![CDATA[1]]></valid>
<date_add><![CDATA[2020-04-13 15:36:27]]></date_add>
<date_upd><![CDATA[2020-04-16 12:19:31]]></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[bf1bbed22e8b94bad540cc1f88e69360]]></secure_key>
<payment><![CDATA[Pago con tarjeta Redsys]]></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[169.000000]]></total_paid>
<total_paid_tax_incl><![CDATA[169.000000]]></total_paid_tax_incl>
<total_paid_tax_excl><![CDATA[140.000000]]></total_paid_tax_excl>
<total_paid_real><![CDATA[169.000000]]></total_paid_real>
<total_products><![CDATA[140.000000]]></total_products>
<total_products_wt><![CDATA[169.000000]]></total_products_wt>
<total_shipping><![CDATA[0.000000]]></total_shipping>
<total_shipping_tax_incl><![CDATA[0.000000]]></total_shipping_tax_incl>
<total_shipping_tax_excl><![CDATA[0.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[2]]></round_mode>
<round_type><![CDATA[2]]></round_type>
<conversion_rate><![CDATA[1.000000]]></conversion_rate>
<reference><![CDATA[ZEIPWMWWL]]></reference>
</order>
<order>
<id><![CDATA[2]]></id>
</current_state>
<module><![CDATA[redsys]]></module>
<invoice_number><![CDATA[7]]></invoice_number>
<invoice_date><![CDATA[2020-04-13 16:18:18]]></invoice_date>
<delivery_number><![CDATA[2]]></delivery_number>
<delivery_date><![CDATA[2020-04-15 18:34:15]]></delivery_date>
<valid><![CDATA[1]]></valid>
<date_add><![CDATA[2020-04-13 16:18:18]]></date_add>
<date_upd><![CDATA[2020-04-15 18:34:15]]></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[9a2da2a2dd2808e9c276e877fc4cc387]]></secure_key>
<payment><![CDATA[Pago con tarjeta Redsys]]></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[139.000000]]></total_paid>
<total_paid_tax_incl><![CDATA[139.000000]]></total_paid_tax_incl>
<total_paid_tax_excl><![CDATA[115.000000]]></total_paid_tax_excl>
<total_paid_real><![CDATA[139.000000]]></total_paid_real>
<total_products><![CDATA[115.000000]]></total_products>
<total_products_wt><![CDATA[139.000000]]></total_products_wt>
<total_shipping><![CDATA[0.000000]]></total_shipping>
<total_shipping_tax_incl><![CDATA[0.000000]]></total_shipping_tax_incl>
<total_shipping_tax_excl><![CDATA[0.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[2]]></round_mode>
<round_type><![CDATA[2]]></round_type>
<conversion_rate><![CDATA[1.000000]]></conversion_rate>
<reference><![CDATA[VNXLLJTGV]]></reference>
</order>
</orders>
</prestashop>

如果我尝试使用$order->订单->付款的付款方式;foreach 只读取第一个订单,但我在 XML 上有 320 个订单。

我已经处理这个问题好几个小时了,我认为这是一个愚蠢的错误......

我不会对所有节点都这样做,但这里有 3 个随机节点,您可以在实际的 xml 上尝试:

$my_doc = new DOMDocument();
$my_doc->loadXML($xml);
$xpath = new DOMXPath($my_doc);
$result = $xpath->query("//payment  | //total_products_wt | //total_products");
foreach($result as $value){
echo $value->nodeValue . "<br>";
}

输出:

Pago con tarjeta Redsys
140.000000
169.000000
Pago con tarjeta Redsys
115.000000
139.000000

您可以使用 JSON 而不是 XML 作为输出格式:

https://Your-Site-Domain/api/orders?output_format=JSON

对于订单详细信息 (id=1(:

https://Your-Site-Domain/api/orders/1?output_format=JSON

最新更新