german Posted October 29, 2018 Share Posted October 29, 2018 I've been searching but found nothing about 1.7 and how to retrieve the url of a specific product. I (finally after some research and work) made my query and I'm able to get the price and name of a product, but I also need the image (actually both images, the small one that appear on previews or thumbnails and the actual size image). Could you please help me find a solution and also, create a place for people to check for the same question? Link to comment Share on other sites More sharing options...
joseantgv Posted October 29, 2018 Share Posted October 29, 2018 1 hour ago, german said: I've been searching but found nothing about 1.7 and how to retrieve the url of a specific product. I (finally after some research and work) made my query and I'm able to get the price and name of a product, but I also need the image (actually both images, the small one that appear on previews or thumbnails and the actual size image). Could you please help me find a solution and also, create a place for people to check for the same question? Check if you have all the information that you need when you instantiate a Product object: $product = new Product($id); You can get URL calling: Context::getContext()->link->getProductLink($id); 1 Link to comment Share on other sites More sharing options...
Rolige Posted October 29, 2018 Share Posted October 29, 2018 Hello: This is what you need: $product = new Product((int)$prod['id_product'], false, $id_lang); $img = $product->getCover($product->id); $img_url = $link->getImageLink(isset($product->link_rewrite) ? $product->link_rewrite : $product->name, (int)$img['id_image'], $image_type); This just get the cover image but you can get all images in the same way. $image_type param give you the specified product image size. Regards 2 Link to comment Share on other sites More sharing options...
german Posted October 30, 2018 Author Share Posted October 30, 2018 (edited) 21 hours ago, Rolige said: Hello: This is what you need: $product = new Product((int)$prod['id_product'], false, $id_lang); $img = $product->getCover($product->id); $img_url = $link->getImageLink(isset($product->link_rewrite) ? $product->link_rewrite : $product->name, (int)$img['id_image'], $image_type); This just get the cover image but you can get all images in the same way. $image_type param give you the specified product image size. Regards I replaced 'id_product' and 'id_image' by 500 as sample and the result was this: http://myweb.es/img/p/.jpg I'm probably doing something wrong, so I hope you could help me with it. I'm trying to create a json (any mean of data reading is valid for me) to get name, price and picture, Taking into account that I have not big idea of php and js, this is all quite new for me. I want to show specific products in a gallery. My idea is to get the reference of the products, send it via js to php, and there retrieve the name, picture and price. So far I have this: $sql = mysqli_query($conn,"SELECT p.price, l.name FROM ps_product p, ps_product_lang l where l.id_product = p.id_product and p.reference=40107"); $rows = array(); while($r = mysqli_fetch_assoc($sql)){ $rows[] = $r; } print json_encode($rows); I have to find the way to add the URL to $rows[] so it can be parsed correctly for the json. However, I think there is a better way to do this using the php created methods. If you could help me getting closer to want I would like to have, that would be great Aside of that, where can I find the documentation for the php prestashop methods? (I refer to "Product->getCover", in example). I thought that prestashop used queries to retrieve the data of the products, but it seems easier* than that. I just need you guys to help me understand it. *Nothing it easy when the experience is short. Sigh. Edit: By the way, shouldn't be the url 'https' by default? Edited October 30, 2018 by german (see edit history) Link to comment Share on other sites More sharing options...
german Posted October 30, 2018 Author Share Posted October 30, 2018 (edited) 21 hours ago, Rolige said: Hello: This is what you need: $product = new Product((int)$prod['id_product'], false, $id_lang); $img = $product->getCover($product->id); $img_url = $link->getImageLink(isset($product->link_rewrite) ? $product->link_rewrite : $product->name, (int)$img['id_image'], $image_type); This just get the cover image but you can get all images in the same way. $image_type param give you the specified product image size. Regards Update: I'm using your code now: $id_a_usar = 37913; $product = new Product($id_a_usar, false, $id_lang); $img = $product->getCover($product->id); $image_type = 'small_default'; print $link->getImageLink(isset($product->link_rewrite) ? $product->link_rewrite : $product->name, (int)$img['id_image'], $image_type); It returns: https://myweb.es/921-small_default/Array.jpg Why is it returning Array? Edited October 30, 2018 by german (see edit history) Link to comment Share on other sites More sharing options...
Rolige Posted October 30, 2018 Share Posted October 30, 2018 1 hour ago, german said: Update: I'm using your code now: $id_a_usar = 37913; $product = new Product($id_a_usar, false, $id_lang); $img = $product->getCover($product->id); $image_type = 'small_default'; print $link->getImageLink(isset($product->link_rewrite) ? $product->link_rewrite : $product->name, (int)$img['id_image'], $image_type); It returns: https://myweb.es/921-small_default/Array.jpg Why is it returning Array? I assume that you are using and specific $id_lang at: $product = new Product($id_a_usar, false, $id_lang); Right? Link to comment Share on other sites More sharing options...
german Posted October 31, 2018 Author Share Posted October 31, 2018 16 hours ago, Rolige said: I assume that you are using and specific $id_lang at: $product = new Product($id_a_usar, false, $id_lang); Right? I wasn't. I have only one language, so I thought I wouldn't need one, but I make it work just like follows: $id_a_usar = $id_got[$n]; $id_lang = Context::getContext()->language->id; $product = new Product($id_a_usar, false, $id_lang); $img = $product->getCover($product->id); $image_type = 'small_default'; //Mirar el ftp para ver otros tipos $nombre = strtoupper($product->name); $precio = $product->price; $imagen = $link->getImageLink(isset($product->link_rewrite) ? $product->link_rewrite : $product->name, (int)$img['id_image'], $image_type); $url_producto = Context::getContext()->link->getProductLink($id_a_usar); The only thing that can improve my code (because I'm using a query for it) is to be able to find the ID of a product by the reference. I want to send the references to the php and it should be able to find the product id to operate with them. Is there any way to do this? Link to comment Share on other sites More sharing options...
Rolige Posted October 31, 2018 Share Posted October 31, 2018 7 hours ago, german said: I wasn't. I have only one language, so I thought I wouldn't need one, but I make it work just like follows: $id_a_usar = $id_got[$n]; $id_lang = Context::getContext()->language->id; $product = new Product($id_a_usar, false, $id_lang); $img = $product->getCover($product->id); $image_type = 'small_default'; //Mirar el ftp para ver otros tipos $nombre = strtoupper($product->name); $precio = $product->price; $imagen = $link->getImageLink(isset($product->link_rewrite) ? $product->link_rewrite : $product->name, (int)$img['id_image'], $image_type); $url_producto = Context::getContext()->link->getProductLink($id_a_usar); The only thing that can improve my code (because I'm using a query for it) is to be able to find the ID of a product by the reference. I want to send the references to the php and it should be able to find the product id to operate with them. Is there any way to do this? You clould do a function similar to Product::getIdByEan13() but searching by reference. Regards Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now