Prestashop 图片 URL
Prestashop image URL
我正在尝试根据 prestashop 产品的 ID 获取图像 URL。
我正在为 prestashop 提供的方法尝试此代码,但我什么也没得到
<?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');
此代码无效,我尝试添加所需的 类 但它们也产生了问题。另外,如果我评论了最后两行,则 require 本身会产生错误。
我计划手动构建 table 图像 URL 的其他工作代码正在工作
<?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,'') as imageURL
FROM 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 where
id_lang=1 and 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 to 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);
}
上面的代码是最后一个解决方案,但我尽量不手动编写产品图像 URLs!
这是经过测试的代码,我将这段代码放在我的 prestashop 安装根目录下的 test.php 中,效果非常好。
<?php
require_once dirname(__FILE__).'/config/config.inc.php';
require_once dirname(__FILE__).'/init.php';
$id_product = 1;//set your product ID here
$image = Image::getCover($id_product);
$product = new Product($id_product, false, Context::getContext()->language->id);
$link = new Link;//because getImageLInk is not static function
$imagePath = $link->getImageLink($product->link_rewrite, $image['id_image'], 'home_default');
echo $imagePath;
根据您的代码,您应该知道 getImageLink 不是静态函数,并且您的第一段代码片段 $product 未使用任何产品进行初始化。
为了确认我已将此文件上传到我的服务器上,您可以在此处查看:
Click here
这是另一个有效的代码
$link = new Link();
$product_url = $link->getProductLink((int)id_product);
$image = Product::getCover((int)id_product);
$image = new Image($image['id_image']);
$product_photo = _PS_BASE_URL_._THEME_PROD_DIR_.$image->getExistingImgPath().".jpg";
<?php
require_once dirname(__FILE__).'/config/config.inc.php';
require_once dirname(__FILE__).'/init.php';
$id_product = 1;//set your product ID here
$image = Image::getCover($id_product);
$product = new Product($id_product, false, Context::getContext()->language->id);
$link = new Link;//because getImageLInk is not static function
$imagePath = $link->getImageLink($product->link_rewrite[Context::getContext()->language->id], $image['id_image'], 'home_default');
echo $imagePath;
我正在尝试根据 prestashop 产品的 ID 获取图像 URL。 我正在为 prestashop 提供的方法尝试此代码,但我什么也没得到
<?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');
此代码无效,我尝试添加所需的 类 但它们也产生了问题。另外,如果我评论了最后两行,则 require 本身会产生错误。 我计划手动构建 table 图像 URL 的其他工作代码正在工作
<?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,'') as imageURL
FROM 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 where
id_lang=1 and 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 to 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);
}
上面的代码是最后一个解决方案,但我尽量不手动编写产品图像 URLs!
这是经过测试的代码,我将这段代码放在我的 prestashop 安装根目录下的 test.php 中,效果非常好。
<?php
require_once dirname(__FILE__).'/config/config.inc.php';
require_once dirname(__FILE__).'/init.php';
$id_product = 1;//set your product ID here
$image = Image::getCover($id_product);
$product = new Product($id_product, false, Context::getContext()->language->id);
$link = new Link;//because getImageLInk is not static function
$imagePath = $link->getImageLink($product->link_rewrite, $image['id_image'], 'home_default');
echo $imagePath;
根据您的代码,您应该知道 getImageLink 不是静态函数,并且您的第一段代码片段 $product 未使用任何产品进行初始化。
为了确认我已将此文件上传到我的服务器上,您可以在此处查看: Click here
这是另一个有效的代码
$link = new Link();
$product_url = $link->getProductLink((int)id_product);
$image = Product::getCover((int)id_product);
$image = new Image($image['id_image']);
$product_photo = _PS_BASE_URL_._THEME_PROD_DIR_.$image->getExistingImgPath().".jpg";
<?php
require_once dirname(__FILE__).'/config/config.inc.php';
require_once dirname(__FILE__).'/init.php';
$id_product = 1;//set your product ID here
$image = Image::getCover($id_product);
$product = new Product($id_product, false, Context::getContext()->language->id);
$link = new Link;//because getImageLInk is not static function
$imagePath = $link->getImageLink($product->link_rewrite[Context::getContext()->language->id], $image['id_image'], 'home_default');
echo $imagePath;