Prestashop 图片网址 [英] Prestashop image URL

查看:40
本文介绍了Prestashop 图片网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取 prestashop 产品的图片 URL,具体取决于它的 ID.我正在为 prestashop 提供的方法尝试此代码,但我什么也没得到

I am trying to get image URL for prestashop product depending on it's ID. I am trying this code for methods provided by prestashop, but I get 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');

此代码不起作用,我尝试添加所需的类,但它们也产生了问题.此外,如果我评论了最后两行,则 require 本身会产生错误.我计划手动构建图像 URL 表的其他工作代码正在运行

this code is not working, I tried to add the required classes but they also produce a problem. Also if I commented last two line the require itself produces an error. My other working code that I am planing to build a table of images URL manually is working

<?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);


 }

上面的代码是最后一个解决方案,但我尽量不要手动编写产品图片网址!

the above code is the last solution but i am trying not to write the product-image URLs manually!

推荐答案

这是经过测试的代码,我把这段代码放在我的 prestashop 安装根目录下的 test.php 中,效果很好.

Here is the tested code, I put this code in test.php under root directory of my prestashop installation and it works awesome.

<?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 未使用任何产品进行初始化.

From your code you should be aware that getImageLink is not static function and your first block of code snippet $product is not initialized with any product.

为了确认我已将此文件上传到我的服务器,您可以在此处查看:点击这里

For confirmation I have uploaded this file on my server you can check it here: Click here

这篇关于Prestashop 图片网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆