Jump to content

Changing *Product* Image Size on PDF (PS 1.7.2.2)


Recommended Posts

Hi guys.

I have had a little store for a while now and we have moved from a custom tool to Shopify and now I'm trying to move to Prestashop due to some limitations/issues with that plataform. I am currently using PS 1.7.2.2.

since the beginning i created a special kind fo invoice that helps me:
1) make order preparation less painful
2) clean way to show the customer the items she bought.

(attached are some samples, first is the old custom invoice, second is the shopify version, both ugly as fuck, but hey, they get the job done, for now)

I am now trying to implement something similar to that on Prestashop PDF but I find myself having issues with the Images.

I got the layout more or less how I want it but the images I need them at a minimum of 100x100px so that when printed the image can be visible

The problem is that I noticed that in HTMLTemplateInvoice.php you can find this:
 

if (Configuration::get('PS_PDF_IMG_INVOICE')) {
            foreach ($order_details as &$order_detail) {
                if ($order_detail['image'] != null) {
                    /* Here is the issue with the variable $name, where it says 'product_mini_' */
                    $name = 'product_mini_'.(int)$order_detail['product_id'].(isset($order_detail['product_attribute_id']) ? '_'.(int)$order_detail['product_attribute_id'] : '').'.jpg';
                    $path = _PS_PROD_IMG_DIR_.$order_detail['image']->getExistingImgPath().'.jpg';

                    $order_detail['image_tag'] = preg_replace(
                        '/\.*'.preg_quote(__PS_BASE_URI__, '/').'/',
                        _PS_ROOT_DIR_.DIRECTORY_SEPARATOR,
                        ImageManager::thumbnail($path, $name, 100, 'jpg', false),
                        1
                    );

                    if (file_exists(_PS_TMP_IMG_DIR_.$name)) {
                        $order_detail['image_size'] = getimagesize(_PS_TMP_IMG_DIR_.$name);
                    } else {
                        $order_detail['image_size'] = false;
                    }
                }
            }
            unset($order_detail); // don't overwrite the last order_detail later
        }

So after tinkering a bit I found that changing 'product_mini_' to any other name causes the image size to be reset
due to the if statement at line 214 but I cant control the size at which the image is going to be shown.

So my question is, what is the best way to change the size of that image to 100x100px?

Thanks in advance for your help!

post-803105-0-19339500-1506565253_thumb.jpg

post-803105-0-43281000-1506565291_thumb.jpg

Edited by RaptorX (see edit history)
Link to comment
Share on other sites

Hello.

I'm not sure if this is the answer you're looking for but I use to get product images on different sizes like this (though I'm not using them for pdf invoice)

$productID = 123; // your product id
$product = new Product($productID);
$cover=Product::getCover($productID);
if($cover["id_image"]){
   $link_rewrite=is_array($product->link_rewrite)?$product->link_rewrite[1]:$product->link_rewrite;
   $link=new Link();
   $image_link=Tools::getShopProtocol().$link->getImageLink($link_rewrite, $cover["id_image"], 'small_default');
}


'small_default' is the size of the thumbnail and you can change that size from admin http://doc.prestashop.com/display/PS17/Image+Settings

 

By default there are many sizes that comes with prestashop: small_default, medium_default, you can built your own size like 'my_size' and make it 100x100px, then you'll replace  'small_default' parameter from the code above with 'my_size' .

Link to comment
Share on other sites

  • 1 month later...
17 hours ago, ndiaga said:

Hi,

You can use   "cart_default"  in the corresponding template. 

Check in mailalert module.

 

Sorry i can't understand ,

the is the extract of the invoice.product-tab.tpl

what do i need to replace to have a bigger image ?

{if $display_product_images}
                    <table width="100%">
                        <tr>
                            <td width="15%">
                                {if isset($order_detail.image) && $order_detail.image->id}
                                    {$order_detail.image_tag}
                                {/if}
                            </td>
                            <td width="5%">&nbsp;</td>
                            <td width="80%">
                                {$order_detail.product_name}
                            </td>
                        </tr>
                    </table>
                {else}

 

Link to comment
Share on other sites

  • 1 year later...

If someone still struggle with this on PS 1.6:

classes / pdf / HTMLTemplates.php

Around line 190:

 if (Configuration::get('PS_PDF_IMG_INVOICE')) {
            foreach ($order_details as &$order_detail) {
                if ($order_detail['image'] != null) {
                    $name = 'product_mini_'.(int)$order_detail['product_id'].(isset($order_detail['product_attribute_id']) ? '_'.(int)$order_detail['product_attribute_id'] : '').'.jpg';
                    $path = _PS_PROD_IMG_DIR_.$order_detail['image']->getExistingImgPath().'.jpg';

                    $order_detail['image_tag'] = preg_replace(
                        '/\.*'.preg_quote(__PS_BASE_URI__, '/').'/',
                        _PS_ROOT_DIR_.DIRECTORY_SEPARATOR,
                        ImageManager::thumbnail($path, $name, 45, 'jpg', false),
                        1
                    );

 Just change 'product_mini_' to 'whatever' and the number 45 at the bottom of the code to whatever PX size you want from the picture. My works perfectly at 250, but the .TPL for the invoices is % based. Clear your shop cache after you upload modified file, and allways backup the original file if something goes wrong :)

 

  • Thanks 1
Link to comment
Share on other sites

  • 10 months later...

For the ones struggling with this, the solution is to create bigger sizes of product_mini images as @mantobani suggests in this post:

 

Once you change the size from AdminOrdersController and regenerate such images by deleting product_mini_* images to see the changes, you will have this size as well in PDF since they take from the same source.

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...