Totti Posted June 7, 2012 Share Posted June 7, 2012 I activated the 'url rewriting and I'm doing an external program that I have to rebuild the image starting from his id, how can I do ? Link to comment Share on other sites More sharing options...
Broceliande Posted June 7, 2012 Share Posted June 7, 2012 I activated the 'url rewriting and I'm doing an external program that I have to rebuild the image starting from his id, how can I do ? The best way is to let prestashop doing it for U, using Link class. $link is a global php side , and always there in smarty as well : use it this way (just add global $link before if ur not using it in a tpl ) : $imglink = $link->getImageLink($link_rewrite,$id_image, $format); I assume you're able to get the link_rewrite fiel of the product object, so that its image id. $format represents the image format you want to use , can be 'home' 'medium' , etc ... Edit : Rebuilding the image link yourself won't work anymore as soon as you change image system in your BO and use the new one. Link is also allows you to get the right link regardless to this option Link to comment Share on other sites More sharing options...
Totti Posted June 8, 2012 Author Share Posted June 8, 2012 Unfortunately I do an external software with .Net Framework so I can not use inner classes. Having access to the database but I could reconstruct the exact link ? Link to comment Share on other sites More sharing options...
vynx Posted October 12, 2012 Share Posted October 12, 2012 The best way is to let prestashop doing it for U, using Link class. $link is a global php side , and always there in smarty as well : use it this way (just add global $link before if ur not using it in a tpl ) : $imglink = $link->getImageLink($link_rewrite,$id_image, $format); I assume you're able to get the link_rewrite fiel of the product object, so that its image id. $format represents the image format you want to use , can be 'home' 'medium' , etc ... Edit : Rebuilding the image link yourself won't work anymore as soon as you change image system in your BO and use the new one. Link is also allows you to get the right link regardless to this option Hi, how to do it completely? Link to comment Share on other sites More sharing options...
Broceliande Posted October 12, 2012 Share Posted October 12, 2012 Hi, how to do it completely? What do do exactly mean by doing it "completely" ? Link to comment Share on other sites More sharing options...
vynx Posted October 12, 2012 Share Posted October 12, 2012 i mean, i know $format, but i dont understand to define 2 another variables... would you please kindly help explain to me? Link to comment Share on other sites More sharing options...
Broceliande Posted October 12, 2012 Share Posted October 12, 2012 i mean, i know $format, but i dont understand to define 2 another variables... would you please kindly help explain to me? Well this strongly depends on the context you need to use this function. $id_image is the id of the image you wanna display... while link_rewrite is the corresponding field in (ps_)image_lang table. If you use it in a tpl file, you'll get theses vars in assigned lists like $products ... eg : in product-list.tpl , $product in the foreach loop contains them , then you'll get the link using: {$link->getImageLink($product.link_rewrite, $product.id_image, 'home')} In some cases , $product is not an array but an object so you'll have to use -> rather than . {$link->getImageLink($product->link_rewrite, $product->id_image, 'home')} Depending on the controller wich assigns smarty vars , these all var names can differ. You'd better put a {debug} tag in the tpl to get a full dump of available data. If you plan to assign the vars yourself in a self written php file (module or controller) , then you'll have to get those vars by yourself. However you should know that the most of native classes contain static methods (or obj ones) wich return full arrays of arrays or objects with any data you need. Just var_dump them to get the full structure. there are too many cases or samples to give ... :s Let's say you are using an instance of a Product object : $product = new Product($idproduct); You'll be able to get images data using : $images=$product->getImages($id_lang); wich will return an array of any images linked to the product, containing all needed data. Now if you only need the default image , you can use $result= Product::getCover($idproduct); But as this only returns an id of the cover image, you'll need to instanciate the image object to get other fields: $cover = new Image($result['id_image'], $idlang); notice that if you don't specify $idlang , then link_rewrite will be an array containing the rewrite for any language. Then you must use it this way : $rewrite=$cover->link_rewrite[$idlang] , to get the right field. As you see there are really too different way to proceed and too many cases depending on what you really want to do. So i heavily recommend you to have a look on existing classes (mainly Product , Image) , and existing controllers or modules wich use product data + images. Hope this helps a bit. 1 Link to comment Share on other sites More sharing options...
vynx Posted October 13, 2012 Share Posted October 13, 2012 Hi, would you please kindly advise how to check $product is not an array but an object? thanks for the explanation Link to comment Share on other sites More sharing options...
Recommended Posts