2014-03-31 70 views
1

有没有办法通过API构建PrestaShop产品阵列,以便我可以在外部应用程序中使用它们?PrestaShop - 通过API检索产品

我只是想是这样的:

array(
    0 => array(
     'name' => 'Some product', 
     'image' => 'path/to/image.jpg', 
     'id' => 1, 
     'description' => 'Some description of the product here', 
     'path' => 'path/to/product' 
    ), 
    ... 
    999 => array(
     ... 
    ) 
); 

我知道Web服务调用其中array('resource' => 'products', 'display' => 'full'),但我真的不知道怎么去数组,我需要从内容从该Web服务调用返回的。我想要做的就是在外部网站上显示产品滚动条,其中每个图像链接到商店中的产品。

我正在使用Prestashop 1.5.6.2和CodeIgniter 2.1.4。产品滚动条必须显示在CI应用程序中。

编辑1 我来SOFAR最接近的是这样的:$product = new Product(1, false, 1);产品1号,但是不包含图像。

回答

5
require_once('PSWebServiceLibrary.php'); 

$url = 'http://example.com'; 
$webService = new PrestaShopWebservice($url, 'EXAMPLEAPIKEY', false); 

$opt['resource'] = 'products'; 
$opt['display'] = 'full'; 
$xml = $webService->get($opt); 
$productNodes = $xml->products->children(); 
$products = array(); 
foreach ($productNodes as $product) { 
    $nameLanguage = $product->xpath('name/language[@id=1]'); 
    $name = (string) $nameLanguage[0]; 
    $idImage = (string) $product->id_default_image; 
    $image = '/img/p/'; 
    for ($i = 0; $i < strlen($idImage); $i++) { 
    $image .= $idImage[$i] . '/'; 
    } 
    $image .= $idImage . '.jpg'; 
    $id = (int) $product->id; 
    $descriptionLanguage = $product->xpath('description/language[@id=1]'); 
    $description = (string) $descriptionLanguage[0]; 
    $path = '/index.php?controller=product&id_product=' . $product->id; 
    $products[] = array('name' => $name, 'image' => $image, 'id' => $id, 'description' => $description, 'path' => $path); 
} 
+0

一如既往的感谢,日元寿司!我会测试这个a.s.a.p.你是一个拯救生命的人! –