Jump to content

Using the webservice to get image urls


Recommended Posts

Check http://doc.prestashop.com/display/PS15/Using+the+PrestaShop+Web+Service

there is detailed example.

 

For images you can see http://doc.prestashop.com/display/PS15/Chapter+9+-+Image+management

 

But also you can get products

$opt = array(
   'resource' => 'products',
   'display'  => 'full'
);

 

and then get image link from "id_default_image".

Share this post


Link to post
Share on other sites

  • 2 months later...

For external application I use additional file to get the image, let say api-img.php contain 

<?php
IMAGE_API_KEY = 'ajshsuashah7ahs7asha7h'; // webservice key with permission get image only
$url = PS_SHOP_PATH .'/api/images/products/'. $_GET['imgurl'];

header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
​
header('Content-type:'); // not sure why this work 

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, IMAGE_API_KEY.':');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_exec($ch);
curl_close($ch); 

and then call the image within external app/website like

<img src="api-img.php?imgurl=<?php echo $resources->id .'/'. $resources->id_default_image; ?>" />

  • Like 1

Share this post


Link to post
Share on other sites

  • 1 year later...

 

For external application I use additional file to get the image, let say api-img.php contain 

<?php
IMAGE_API_KEY = 'ajshsuashah7ahs7asha7h'; // webservice key with permission get image only
$url = PS_SHOP_PATH .'/api/images/products/'. $_GET['imgurl'];

header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
​
header('Content-type:'); // not sure why this work 

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, IMAGE_API_KEY.':');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_exec($ch);
curl_close($ch); 

and then call the image within external app/website like

<img src="api-img.php?imgurl=<?php echo $resources->id .'/'. $resources->id_default_image; ?>" />

I will try this one

Share this post


Link to post
Share on other sites

  • 1 year later...
  • 1 month later...

Hello in the root of your project create a file called get-image.php

 

 

in get-image.php put this code

<?php
header("Content-Type: image/jpeg");
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
$url = $_GET['img-url'];


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, 'hereYourPrestashopUserToUseWS' . ':');
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.1 Safari/537.11');
$res = curl_exec($ch);
$rescode = curl_getinfo($ch, CURLINFO_HTTP_CODE); 
curl_close($ch) ;
echo $res;
?>

 

in your another php file use the next code, downloading the library from here https://github.com/PrestaShop/PrestaShop-webservice-lib
 
<?php 
$separator=DIRECTORY_SEPARATOR;
require_once(ABSPATH . $separator. 'prestashop' .$separator.'PSWebServiceLibrary.php');

 $ws = new PrestaShopWebservice("http:www.web.com", "hereYourPrestashopUserToUseWS", FALSE);


                       /**
                         * products data
                         */
                        $opt = array(
                            'resource' => 'products',
                            'display' => '[id, id_default_image, name,link_rewrite]',
                            'limit' => '30'
                        );
                        $xml = $ws->get($opt);
                        $products = $xml->products->product;

  foreach ($products as $value):
                            $imageObject = $value->id_default_image;
                            $productId = $value->id;
                            $productImage = $imageObject->attributes('xlink', true)->href;
                                                   
                            ?> 
                  
                                <a href="<?php echo $url; ?>" target="_blank" > <img src="/get-image.php?img-url=<?php echo $productImage ?>" /></a>
                           
                            <?php
                        endforeach;
                        ?>  
 
 
 

 

Edited by wladimiravila (see edit history)

Share this post


Link to post
Share on other sites

 

Hello in the root of your project create a file called get-image.php

 

 

in get-image.php put this code

 

 

hello, thank you for your valuable reply, but  i already done all of my web services working which require to run android apps likewise any other eCommerce. 

 

Thanks

Hardy

Share this post


Link to post
Share on other sites

 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More