获取图像路径prestashop 1.5
需要你的帮助!如何获取具有产品ID的图像的路径 Link::getImageLink()-$name的第一个参数,我不知道获取图像路径prestashop 1.5,prestashop,Prestashop,需要你的帮助!如何获取具有产品ID的图像的路径 Link::getImageLink()-$name的第一个参数,我不知道 $searchResults = Search::find((int)(Tools::getValue('id_lang')), $query, 1, 10, 'position', 'desc', true); foreach ($searchResults as &$product) { $product['product_link'] = $this-
$searchResults = Search::find((int)(Tools::getValue('id_lang')), $query, 1, 10, 'position', 'desc', true);
foreach ($searchResults as &$product)
{
$product['product_link'] = $this->context->link->getProductLink($product['id_product'], $product['prewrite'], $product['crewrite']);
$imageid = Product::getCover($product['id_product']);
// there i have image ID, how get image path $imagepath?
$product['image'] = $imagepath;
}
die(Tools::jsonEncode($searchResults));
看看
Link::getImageLink()
。这是您必须使用的方法来获取产品图像的url
$imagePath = Link::getImageLink($product['link_rewrite'], $product['id_product'], 'home_default'); // change the last parameters to get the size you need
如果您需要使用相同语法,该方法也可以在模板中使用
{$link->getImageLink($product.link_rewrite, $product.id_product, 'home_default')}`
编辑
我重读了你的问题,意识到你知道这一点。是的,第一个参数是
链接\u重写
。希望这有助于正确获取产品图像,请遵循下面的代码并正确传递参数(如果遵循此代码,则启用URL重写时不会出现问题)
参数的详细信息如下所示
@param string $name rewrite link of the image
@param string $ids id part of the image filename - can be "id_product-id_image" (legacy support, recommended) or "id_image" (new)
@param string $type
给你举个例子
<img src="{$link->getImageLink($product.link_rewrite, $image.id_image, 'large_default')}" />
getImageLink($product.link\u rewrite,$image.id\u image,'large\u default'))/>
第1步:如果您有id\u产品,请编写一个函数,以获得id\u图像属性,如下所示:
private static function getCover($product_id) {
$sql = 'SELECT id_image FROM '._DB_PREFIX_.'image WHERE cover = 1 AND id_product='.$product_id;
$result = Db::getInstance()->getRow($sql);
return $result['id_image'];
}
$id_image = self::getCover($product['id_product']);
$image_path = $id_image.'-home_default/'.$product['link_rewrite'].'.jpg';
步骤2:然后使用如下代码获取图像路径:
private static function getCover($product_id) {
$sql = 'SELECT id_image FROM '._DB_PREFIX_.'image WHERE cover = 1 AND id_product='.$product_id;
$result = Db::getInstance()->getRow($sql);
return $result['id_image'];
}
$id_image = self::getCover($product['id_product']);
$image_path = $id_image.'-home_default/'.$product['link_rewrite'].'.jpg';
注意:$product是从执行sql语句中获取的数组