Barama Posted January 13, 2014 Share Posted January 13, 2014 The invoices prestashop generates do not show images or the sku of the products sold. It only show the title of the products. How can I add images and the sku to the pdf invoice? Link to comment Share on other sites More sharing options...
limon994 Posted January 13, 2014 Share Posted January 13, 2014 Hello, Which version of prestashop do you use? It is important to know because PDF system is different in 1.4.x to 1.5.x Thanks Link to comment Share on other sites More sharing options...
Barama Posted January 13, 2014 Author Share Posted January 13, 2014 Many thanks for your fast reply. I am using version 1.5.5.0. Link to comment Share on other sites More sharing options...
limon994 Posted January 13, 2014 Share Posted January 13, 2014 Hello, To do this we have to override a class named OrderInvoice which you will get in YOUR_ROOT_DIR/classes/order/OrderInvoice.php Open it in a text editor. Now replace the following method to put the product image path public function getProducts($products = false, $selectedProducts = false, $selectedQty = false) { if (!$products) $products = $this->getProductsDetail(); $order = new Order($this->id_order); $customized_datas = Product::getAllCustomizedDatas($order->id_cart); $resultArray = array(); foreach ($products as $row) { // Change qty if selected if ($selectedQty) { $row['product_quantity'] = 0; foreach ($selectedProducts as $key => $id_product) if ($row['id_order_detail'] == $id_product) $row['product_quantity'] = (int)($selectedQty[$key]); if (!$row['product_quantity']) continue; } $this->setProductImageInformations($row); $this->setProductCurrentStock($row); $this->setProductCustomizedDatas($row, $customized_datas); // Add information for virtual product if ($row['download_hash'] && !empty($row['download_hash'])) { $row['filename'] = ProductDownload::getFilenameFromIdProduct((int)$row['product_id']); // Get the display filename $row['display_filename'] = ProductDownload::getFilenameFromFilename($row['filename']); } $row['id_address_delivery'] = $order->id_address_delivery; /* Stock product */ $resultArray[(int)$row['id_order_detail']] = $row; } if ($customized_datas) Product::addCustomizationPrice($resultArray, $customized_datas); return $resultArray; } with public function getProducts($products = false, $selectedProducts = false, $selectedQty = false) { if (!$products) $products = $this->getProductsDetail(); $order = new Order($this->id_order); $customized_datas = Product::getAllCustomizedDatas($order->id_cart); /*ICode*/ global $cookie; $link=new Link(); /*ICode*/ $resultArray = array(); foreach ($products as $row) { // Change qty if selected if ($selectedQty) { $row['product_quantity'] = 0; foreach ($selectedProducts as $key => $id_product) if ($row['id_order_detail'] == $id_product) $row['product_quantity'] = (int)($selectedQty[$key]); if (!$row['product_quantity']) continue; } $this->setProductImageInformations($row); $this->setProductCurrentStock($row); $this->setProductCustomizedDatas($row, $customized_datas); //ICode $product = new Product($row['id_product']); //echo "<pre>";print_r($row);echo "</pre>"; $imageUrl= $link->getImageLink($product->link_rewrite[$cookie->id_lang], $row['image']->id, 'small_default'); $tempArray=explode("/img/",$imageUrl); $row['image_path']=_PS_ROOT_DIR_."/img/".$tempArray[1]; //ICdoe // Add information for virtual product if ($row['download_hash'] && !empty($row['download_hash'])) { $row['filename'] = ProductDownload::getFilenameFromIdProduct((int)$row['product_id']); // Get the display filename $row['display_filename'] = ProductDownload::getFilenameFromFilename($row['filename']); } $row['id_address_delivery'] = $order->id_address_delivery; /* Stock product */ $resultArray[(int)$row['id_order_detail']] = $row; } if ($customized_datas) Product::addCustomizationPrice($resultArray, $customized_datas); //echo "<pre>";print_r($resultArray);echo "</pre>"; return $resultArray; } Now you need to show it in the pdf. To do this open the invoice tpl file which you will find in YOUR_ROOT_DIR/pdf/invoice.tpl if you not change your default settings. Now replace the following code <td style="text-align: left; background-color: #4D4D4D; color: #FFF; padding-left: 10px; font-weight: bold; width: {if !$tax_excluded_display}35%{else}45%{/if}">{l s='Product / Reference' pdf='true'}</td> with <td style="text-align: left; background-color: #4D4D4D; color: #FFF; padding-left: 10px; font-weight: bold; width: {if !$tax_excluded_display}25%{else}35%{/if}">{l s='Product / Reference' pdf='true'}</td><td style="background-color: #4D4D4D; color: #FFF; text-align: right; font-weight: bold; width: 10%">{l s='Image' pdf='true'}</td> and <td style="text-align: left; width: {if !$tax_excluded_display}35%{else}45%{/if}">{$order_detail.product_name}</td> with <td style="text-align: left; width: {if !$tax_excluded_display}25%{else}35%{/if}">{$order_detail.product_name}</td><td style="text-align: left; width:10%"><img src="{$order_detail.image_path}" /></td> Now if you download an invoice you will see the product image. You will get the total tutorial here http://www.learnprestashop.com/?p=391 Thanks, 1 Link to comment Share on other sites More sharing options...
limon994 Posted January 13, 2014 Share Posted January 13, 2014 Hello, Here only I show the image. I hope you can add sku by yourself. Link to comment Share on other sites More sharing options...
Barama Posted January 13, 2014 Author Share Posted January 13, 2014 Thanks. But it does not work. I only checked quickly. But for example $imageUrl has the value: "http://bestbuy-china.com/pr/1458-small_default/High-Quality-Leather-Bracelet.jpg". So $tempArray[1] is empty, since the '/img' string does not appear in $imageUrl. Could that be part of the problem? I did everything like you suggested. Everything works, just no images. Link to comment Share on other sites More sharing options...
tuk66 Posted January 14, 2014 Share Posted January 14, 2014 The M4 PDF Extensions module has already templates displaying product images as well as an option to display every product data. Link to comment Share on other sites More sharing options...
hollandtextiles Posted January 25, 2014 Share Posted January 25, 2014 Thanks, it's working for me 1.5.6.2 When there is no image it give an error that image not found. How I can make that it is showing the standard no imgage image? Where \i have to put it? Thanks Link to comment Share on other sites More sharing options...
limon994 Posted January 26, 2014 Share Posted January 26, 2014 Hello, Hmm I know that might cause problem. Actually You need to work with the following code. $row['image_path']=_PS_ROOT_DIR_."/img/".$tempArray[1]; Here if you know the image path, you need to put the path, $row['image_path']=YOUR_PRODUCT_IMAGE_PATH; In my system I can get the product image by the way which I have shown in the code. If you wish you can send me your url Then I may told you what to do. Thanks, Link to comment Share on other sites More sharing options...
hollandtextiles Posted January 26, 2014 Share Posted January 26, 2014 Put /img/p/-small_default.jpg in the dir and all working fine! Thanks Link to comment Share on other sites More sharing options...
houin Posted March 4, 2014 Share Posted March 4, 2014 Put /img/p/-small_default.jpg in the dir and all working fine! Thanks Hello, I read well this comment and it works trés well on 1.5.6.2 On the other hand I do not see or making your transformations :/img/p/-small_default.jpg ???? I do not understand either transformation(processing) of the comment 085 :$row['image_path']=_PS_ROOT_DIR_."/img/".$tempArray[1]; Can you tell me how to make. Thank you Link to comment Share on other sites More sharing options...
troyanderson Posted March 14, 2014 Share Posted March 14, 2014 The invoices prestashop generates do not show images or the sku of the products sold. It only show the title of the products. How can I add images to pdf and the sku to the pdf invoice? Does the image has its original resolution after it is inserted into pdf invoice? Link to comment Share on other sites More sharing options...
tuk66 Posted March 14, 2014 Share Posted March 14, 2014 Look at http://www.presta-addons.com/pdf/Invoice - with images.pdf and try to zoom to 600%. 1 Link to comment Share on other sites More sharing options...
mjpl Posted May 15, 2014 Share Posted May 15, 2014 Hi, The image printed in PDF, is the cover image. Is any possibility to get the second image, instead of the cover image ? Regards, Mario Link to comment Share on other sites More sharing options...
mjpl Posted May 15, 2014 Share Posted May 15, 2014 Hello, To do this we have to override a class named OrderInvoice which you will get in YOUR_ROOT_DIR/classes/order/OrderInvoice.php Open it in a text editor. Now replace the following method to put the product image path public function getProducts($products = false, $selectedProducts = false, $selectedQty = false) { if (!$products) $products = $this->getProductsDetail(); $order = new Order($this->id_order); $customized_datas = Product::getAllCustomizedDatas($order->id_cart); $resultArray = array(); foreach ($products as $row) { // Change qty if selected if ($selectedQty) { $row['product_quantity'] = 0; foreach ($selectedProducts as $key => $id_product) if ($row['id_order_detail'] == $id_product) $row['product_quantity'] = (int)($selectedQty[$key]); if (!$row['product_quantity']) continue; } $this->setProductImageInformations($row); $this->setProductCurrentStock($row); $this->setProductCustomizedDatas($row, $customized_datas); // Add information for virtual product if ($row['download_hash'] && !empty($row['download_hash'])) { $row['filename'] = ProductDownload::getFilenameFromIdProduct((int)$row['product_id']); // Get the display filename $row['display_filename'] = ProductDownload::getFilenameFromFilename($row['filename']); } $row['id_address_delivery'] = $order->id_address_delivery; /* Stock product */ $resultArray[(int)$row['id_order_detail']] = $row; } if ($customized_datas) Product::addCustomizationPrice($resultArray, $customized_datas); return $resultArray; } with public function getProducts($products = false, $selectedProducts = false, $selectedQty = false) { if (!$products) $products = $this->getProductsDetail(); $order = new Order($this->id_order); $customized_datas = Product::getAllCustomizedDatas($order->id_cart); /*ICode*/ global $cookie; $link=new Link(); /*ICode*/ $resultArray = array(); foreach ($products as $row) { // Change qty if selected if ($selectedQty) { $row['product_quantity'] = 0; foreach ($selectedProducts as $key => $id_product) if ($row['id_order_detail'] == $id_product) $row['product_quantity'] = (int)($selectedQty[$key]); if (!$row['product_quantity']) continue; } $this->setProductImageInformations($row); $this->setProductCurrentStock($row); $this->setProductCustomizedDatas($row, $customized_datas); //ICode $product = new Product($row['id_product']); //echo "<pre>";print_r($row);echo "</pre>"; $imageUrl= $link->getImageLink($product->link_rewrite[$cookie->id_lang], $row['image']->id, 'small_default'); $tempArray=explode("/img/",$imageUrl); $row['image_path']=_PS_ROOT_DIR_."/img/".$tempArray[1]; //ICdoe // Add information for virtual product if ($row['download_hash'] && !empty($row['download_hash'])) { $row['filename'] = ProductDownload::getFilenameFromIdProduct((int)$row['product_id']); // Get the display filename $row['display_filename'] = ProductDownload::getFilenameFromFilename($row['filename']); } $row['id_address_delivery'] = $order->id_address_delivery; /* Stock product */ $resultArray[(int)$row['id_order_detail']] = $row; } if ($customized_datas) Product::addCustomizationPrice($resultArray, $customized_datas); //echo "<pre>";print_r($resultArray);echo "</pre>"; return $resultArray; } Now you need to show it in the pdf. To do this open the invoice tpl file which you will find in YOUR_ROOT_DIR/pdf/invoice.tpl if you not change your default settings. Now replace the following code <td style="text-align: left; background-color: #4D4D4D; color: #FFF; padding-left: 10px; font-weight: bold; width: {if !$tax_excluded_display}35%{else}45%{/if}">{l s='Product / Reference' pdf='true'}</td> with <td style="text-align: left; background-color: #4D4D4D; color: #FFF; padding-left: 10px; font-weight: bold; width: {if !$tax_excluded_display}25%{else}35%{/if}">{l s='Product / Reference' pdf='true'}</td> <td style="background-color: #4D4D4D; color: #FFF; text-align: right; font-weight: bold; width: 10%">{l s='Image' pdf='true'}</td> and <td style="text-align: left; width: {if !$tax_excluded_display}35%{else}45%{/if}">{$order_detail.product_name}</td> with <td style="text-align: left; width: {if !$tax_excluded_display}25%{else}35%{/if}">{$order_detail.product_name}</td> <td style="text-align: left; width:10%"><img src="{$order_detail.image_path}" /></td> Now if you download an invoice you will see the product image. You will get the total tutorial here http://www.learnprestashop.com/?p=391 Thanks, Hi, The image printed in PDF, is the cover image. Is any possibility to get the second image, instead of the cover image ? Regards, Mario Link to comment Share on other sites More sharing options...
giuliopowa Posted June 12, 2014 Share Posted June 12, 2014 hello i have this error :TCPDF ERROR: [image] Unable to get image: /home/etkslo/public_html/img/i use ps 1.5.6.1 I followed this tutorial Link to comment Share on other sites More sharing options...
ZenGraph Posted August 8, 2014 Share Posted August 8, 2014 (edited) hello i have this error : TCPDF ERROR: [image] Unable to get image: /home/etkslo/public_html/img/ i use ps 1.5.6.1 I followed this tutorial On a 1.5.4.1 version i got the same error, try to do this, it should work : //ICode $product = new Product($row['id_product']); //echo "<pre>";print_r($row);echo "</pre>"; $imageUrl= $link->getImageLink($product->link_rewrite[$cookie->id_lang], $row['image']->id, 'medium_default'); $tempArray=explode("/img/",$imageUrl); $row['image_path']=$tempArray[0]; //ICdoe As you can see, the $tempArray[1] is modified to $tempArray[0] i also changed "small-default" image type to "medium-default", because the small image has a really too low definition to be printed nicely. Enjoy ! Edited August 8, 2014 by ZenGraph (see edit history) Link to comment Share on other sites More sharing options...
zeki893 Posted September 5, 2014 Share Posted September 5, 2014 Damn I wish I scrolled to the bottom of this and read zengraph's post. spent like an hour debugging the code at the top to end up with the same thing you have.... anyways also notice in zengraph's code it removes the _PS_ROOT_DIR_ from $row['image_path'] 1 Link to comment Share on other sites More sharing options...
tuk66 Posted September 8, 2014 Share Posted September 8, 2014 It depends. Try the right image size: *-home_default.jpg *-large_default.jpg *-medium_default.jpg *-small_default.jpg *-thickbox_default.jpg Link to comment Share on other sites More sharing options...
dalekos Posted October 2, 2014 Share Posted October 2, 2014 In Prestashop 1.6, in order to add product image to invoice, i used $row['image_path']=$imageUrl; instead of $row['image_path']=_PS_ROOT_DIR_."/img/".$tempArray[1]; and it worked fine! 1 Link to comment Share on other sites More sharing options...
TiaNex Shopping Posted February 20, 2015 Share Posted February 20, 2015 In Prestashop 1.6, in order to add product image to invoice, i used $row['image_path']=$imageUrl; instead of $row['image_path']=_PS_ROOT_DIR_."/img/".$tempArray[1]; and it worked fine! yes,thank you , //add product image 2/ $product = new Product($row['id_product']); $imageUrl= $link->getImageLink($product->link_rewrite[$cookie->id_lang], $row['image']->id, 'small_default'); Link to comment Share on other sites More sharing options...
Tung at RockPOS.com Posted February 27, 2015 Share Posted February 27, 2015 If you are still interested in, just so you know, since 1.6.0.13, product images are displayed in invoices by default. Read more at: https://www.prestashop.com/forums/topic/418728-prestashop-16013-is-available-for-download/ Cheers, 1 Link to comment Share on other sites More sharing options...
SahinSOLMAZ Posted June 25, 2015 Share Posted June 25, 2015 (edited) Hi All, You can use the order options for order image and other features. (http://doc.prestashop.com/display/PS16/Invoices) PS Admin -> Preferences -> Order options:PDF Settings Enable product image on Invoice Enable Edited June 25, 2015 by shnslmz (see edit history) Link to comment Share on other sites More sharing options...
mjpl Posted September 25, 2015 Share Posted September 25, 2015 Hi, After follow the code posted here by limon994, I not get the second image to my PDF. PrestaShop version: 1.5.6.2 when I play with array position, only the cover image appear. I have 2 images associated with product. $row['image_path']=_PS_ROOT_DIR_."/img/".$tempArray[0]; gives an error: CBVFNWVZXTCPDF ERROR: [image] Unable to get image: /home/agriloja/public_html/agricor.es/procurement/img/agricor.es/procurement $row['image_path']=_PS_ROOT_DIR_."/img/".$tempArray[1]; gives me the cover image $row['image_path']=_PS_ROOT_DIR_."/img/".$tempArray[2]; gives an error: GZOJBSSMBTCPDF ERROR: [image] Unable to get image: /home/agriloja/public_html/agricor.es/procurement/img/ Anyone help me? regards, Mario Link to comment Share on other sites More sharing options...
SahinSOLMAZ Posted September 29, 2015 Share Posted September 29, 2015 Hi, After follow the code posted here by limon994, I not get the second image to my PDF. PrestaShop version: 1.5.6.2 when I play with array position, only the cover image appear. I have 2 images associated with product. $row['image_path']=_PS_ROOT_DIR_."/img/".$tempArray[0]; gives an error: CBVFNWVZXTCPDF ERROR: [image] Unable to get image: /home/agriloja/public_html/agricor.es/procurement/img/agricor.es/procurement $row['image_path']=_PS_ROOT_DIR_."/img/".$tempArray[1]; gives me the cover image $row['image_path']=_PS_ROOT_DIR_."/img/".$tempArray[2]; gives an error: GZOJBSSMBTCPDF ERROR: [image] Unable to get image: /home/agriloja/public_html/agricor.es/procurement/img/ Anyone help me? regards, Mario Hi, Did you look here? Link to comment Share on other sites More sharing options...
Recommended Posts