Prestashop image URL -
i trying image url prestashop product depending on it's id trying code methods provided prestashop, nothing
<?php //require('config/settings.inc.php'); //require('classes/image.php'); require('classes/link.php'); $itemid=$_get["catid"]; $db=mysql_connect(constant('_db_server_'),constant('_db_user_'), constant $image = image::getcover($itemid); $imagepath = link::getimagelink($product->link_rewrite, $image['id_image'], 'home_default');
block quote
this code not working tried add required classes produce problem if commented last 2 line require produce error other working code planing build table of images url manually wroking
<?php require('config/settings.inc.php'); $itemid=$_get["catid"]; $db=mysql_connect(constant('_db_server_'),constant('_db_user_'), constant ('_db_passwd_')) or die('could not connect'); mysql_select_db(constant('_db_user_'), $db) or die(''); if (is_numeric($itemid)) { $result = mysql_query("select name,date_add,price , ifnull(imageurl,'') imageurl product inner join product_lang on product_lang.id_product=product.id_product left join app_product_image on product.id_product=app_product_image.id_product id_lang=1 , product.id_product='$itemid'") or die('could not query'); $json = array(); if(mysql_num_rows($result)){ // $row=mysql_fetch_assoc($result); while($row=mysql_fetch_row($result)){ // cast results specific data types //$test_data[]=$row; $json['name']=$row[0]; $json['date']=$row[1]; $json['price']=$row[2]; $json['imgurl']=$row[3]; } // $json['products']=$test_data; } echo json_encode($json); mysql_close($db); }
the above code last solution trying not write products images url manually!
here tested code, put code in test.php under root directory of prestahsop installation , works awesome.
<?php require_once dirname(__file__).'/config/config.inc.php'; require_once dirname(__file__).'/init.php'; $id_product = 1;//set product id here $image = image::getcover($id_product); $product = new product($id_product, false, context::getcontext()->language->id); $link = new link;//because getimagelink not static function $imagepath = $link->getimagelink($product->link_rewrite, $image['id_image'], 'home_default'); echo $imagepath;
from code should aware getimagelink not static function , first block of code snippet $product not initialized product.
for confirmation have uploaded file on server can check here: click here
Comments
Post a Comment