0

我正在尝试做一个 WP 插件,它将从整个数据库和一个指定的类别中随机显示 PrestaShop 产品。

我需要为仅具有产品 ID 的产品重新构建图像路径。

我尝试了一个 SQL 查询,但没有帮助我为正确的产品构建正确的图像的正确路径。

SELECT p.*,  pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, i.`id_image`, il.`legend` FROM [DB_PREFIX]product p
LEFT JOIN `[DB_PREFIX]product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = [ID_LANG])
LEFT JOIN `[DB_PREFIX]image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
LEFT JOIN `[DB_PREFIX]image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = [ID_LANG])

图片的绝对路径为:website.com/img/p/

然后 url 中的数字给出图片的路径。

所以使用website.com/5-medium_atch/product-name.jpg图片的路径是

website.com/img/p/5/5-medium_atch.jpg

对于website.com/145-home_atch/product-name.jpg 路径是

website.com/img/p/1/4/5/145-home_atch.jpg

我正在使用 prestashop 版本 1.5.4.1 和 WP 3.5.2

欢迎任何建议。谢谢。

4

2 回答 2

0

我终于这样做了:

从插件设置中获取这些:

$product_name = $PrestaShopdb->get_var('SQL here');
$store_url
$image_folder

$id_image = $PrestaShopdb->get_var('
        SELECT i.`position` FROM ps_product p
        LEFT JOIN `ps_product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.$language.')
        LEFT JOIN `ps_image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
        LEFT JOIN `ps_image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.$language.')
        WHERE p.`active` = 1
        AND p.`id_product` = '.$product_id.''           
        );          

$image_path = $image_folder . "/". $product_id . "/".$id_image."/" . $product_id.$id_image."-" . $image_size."_default.jpg";

if(!url_exists($image_path)){ //check if file exist? Function is below
    $image_path = $image_folder . "/". $product_id ."/" . $product_id."-" . $image_size."_default.jpg";
}else{
    $image_path = $image_path;
}


function url_exists($url) {
    // Version 4.x supported
    $handle   = curl_init($url);
    if (false === $handle)
    {
        return false;
    }
    curl_setopt($handle, CURLOPT_HEADER, false);
    curl_setopt($handle, CURLOPT_FAILONERROR, true);  // this works
    curl_setopt($handle, CURLOPT_NOBODY, true);
    curl_setopt($handle, CURLOPT_RETURNTRANSFER, false);
    $connectable = curl_exec($handle);
    curl_close($handle);    
    return $connectable;
}

它看起来更像是我问题的临时解决方案,但现在就完成这项工作。

于 2013-07-11T23:28:06.790 回答
0

我认为在 prestashop 中查找图像文件夹路径的最佳方法

$oImage = new Image($iImg_id);
$sPath = _PS_PROD_IMG_DIR_.$oImage->getExistingImgPath().'.'.$oImage->image_format;
于 2013-07-30T08:31:23.883 回答