您好,我正在prestashop上启动一个CRUD应用程序,我想使用Web服务通过管理存储的程序启动的php应用程序更新、创建或删除产品、用户和订单。
我看过prestashop指南:http://doc.prestashop.com/display/PS15/Using++PrestaShop+Web+服务
现在我正努力把事情办好。
我实际上收到了一个xml,它表示产品的结构:
<?php
// Here we define constants /!' You need to replace this parameters
define('DEBUG', true);
define('PS_SHOP_PATH', 'http://www.server.com/prestashop/');
define('PS_WS_AUTH_KEY', 'blahblahbla');
require_once('./PSWebServiceLibrary.php');
$webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);
$opt = array('resource' => 'products');
$opt['id'] =1;
$xml = $webService->get($opt);
$resources = $xml->children()->children();
foreach ($resources as $nodeKey => $node)
{
echo $nodeKey . " : ". $resources->$nodeKey ."<br>";
}
/*$opt = array('resource' => 'products');
$opt['putXml'] = $xml->asXML();
$opt['id'] = 1;
$xml = $webService->edit($opt);*/
?>
我遇到的第一个问题:
字段"name"在xml中有一些子项,它们是不同的语言,因此,在我浏览节点的循环中,我想"进入"那些有子项的。。。因为实际上我尝试的名称"echo
"是空的,但如果我看到xml,我可以看到<name>
下的两个节点,其中包含两种不同长度的名称。这就是目前的全部内容,我稍后会发布越来越多的问题:D
提前感谢!
您引用的是具有子级的SimpleXMLElement(http://php.net/manual/en/class.simplexmlelement.php)。在这种情况下,它具有命名语言的子级。
Array
(
[name] => SimpleXMLElement Object
(
[language] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => 1
)
)
)
)
因此,您可以访问下面的like。
if($resources->$nodeKey->children()){
$children = false;
foreach($resources->$nodeKey->children() as $child){
$children[] = $child;
}
echo $nodeKey . " : [" . @implode(", ", $children) . "]<br>";
}
else
echo $nodeKey . " : ". $resources->$nodeKey ."<br>";
结果:
Array
(
[name] => SimpleXMLElement Object
(
[language] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => 1
)
)
)
)
name : [iPod Nano]