2013-07-08 32 views
0

我试图做一个WP插件,它将从整个数据库和一个指定的类别中随机显示PrestaShop产品。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

欢迎任何建议。谢谢。

+0

是很困难的,你要么必须添加的Prestashop URL重写使用Web服务来做到这一点的系统链路控制器。由于有两个图像路径生成,当seo链接禁用另一个是soe链接启用时。所以最好在prestashop中创建一个模块,并使用wp插件的查询字符串进行引发,并显示该产品。 –

+0

@arifurrahman感谢您的信息。我想过这种方法,但对我来说看起来并不可靠。用户设置太多。在下一个WP插件版本中,我将连接到PS DB,并让用户将所需产品导入为自定义帖子类型,并从WP DB进行随机显示。它也会减少加载时间。 –

回答

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; 
} 

它看起来更像是一个临时的解决方案,以我的问题,但现在做的工作。

+0

这意味着你将检查图像文件夹的名称,而不是build.If语言和seo网址启用了你如何管理它。您可以使用Web服务或通过rss获取产品信息。 –

0

我认为最好的方式找到的Prestashop图像文件夹路径

$oImage = new Image($iImg_id); 
$sPath = _PS_PROD_IMG_DIR_.$oImage->getExistingImgPath().'.'.$oImage->image_format; 
相关问题