Prestashop Webservice在一个请求中获得功能

时间:2018-09-20 22:36:41

标签: php xml prestashop product

我正在使用Prestashop的网络服务,并且试图在一个请求中获得产品和product_feature_value的名称。

在另一个任务中获取product_feature_value的名称是没有问题的,但是每个产品的总和为2-3秒。

我试图通过使用以下代码来实现它,并选择display => full:

$webService = new \PrestaShopWebservice($this->path, $this->auth, $this->debug);
$xml = $webService->get(array(
'resource' => 'products',
'display' => 'full',
'filter[id_category_default]' => '[12|19|24|26]',
'filter[active]' => '[1]',
// 'limit' => 5,
'active' => '1'
));
$resource = $xml->children()->children();
return $resource;

但是,它不返回product_feature_value的名称,仅返回ID的名称。

1 个答案:

答案 0 :(得分:0)

您可以处理在$xml = $webService->get(array( 'resource' => 'products', 'display' => 'full', 'filter[id_category_default]' => '[12|19|24|26]', 'filter[active]' => '[1]', // 'limit' => 5, 'active' => '1' )); foreach ($xml->products->product as $product) { foreach ($product->associations->product_features->product_feature as $feature) { $featureName = $webService->get(array( 'resource' => 'product_features', 'id' => $feature->id, )); $featrueValue = $webService->get(array( 'resource' => 'product_feature_values', 'id' => $feature->id_feature_value )); $feature->feature_name = $featureName->product_feature->name->language->__toString(); $feature->feature_value = $featrueValue->product_feature_value->value->language->__toString(); } } $resource = $xml->children()->children(); return $resource; 资源Web服务中获得的数据,并相应地附加产品功能名称和值。

您可以执行以下操作;

feature_name

添加了feature_valueproducts;请参见下面的结果作为参考,这些结果已添加到[product_features] => SimpleXMLElement Object ( [@attributes] => Array ( [nodeType] => product_feature [api] => product_features ) [product_feature] => Array ( [0] => SimpleXMLElement Object ( [id] => 5 [id_feature_value] => 5 [feature_name] => Compositions [feature_value] => Cotton ) [1] => SimpleXMLElement Object ( [id] => 6 [id_feature_value] => 11 [feature_name] => Styles [feature_value] => Casual ) [2] => SimpleXMLElement Object ( [id] => 7 [id_feature_value] => 17 [feature_name] => Properties [feature_value] => Short Sleeve ) ) ) 数据中。

[embed width="756" height="420"]...[/embed]

希望这对您有帮助!