Jump to content

Short description on the invoice


KolfKord

Recommended Posts

Hello guys,

I need a big help. How do I put a short description of a product on the invoice? I did several searches on the web and I saw the form M4 PDF Extensions but it costs € 99 and I can not afford ... Is there a way to do this via code? ...

 

Help Please ...

Link to comment
Share on other sites

You may define a new function in OrderInvoice class to retrieve product short description. See function getProducts - you have order detail information as $row => you may call your function using $row['id_product'] (and product_attribute_id) and retrieve it's short description using SQL. Then it might be assigned to $row['product_short_desc'].

You will use this information in invoice.tpl somewhere in {foreach $order_details as $order_detail}, it will be {$order_detail.product_short_desc}

 

Honestly, I didn't test it but it should work like that. PDF variables are collected in HTMLTemplateInvoice.php, 'order_details' => $this->order_invoice->getProducts()

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

You may define a new function in OrderInvoice class to retrieve product short description. See function getProducts - you have order detail information as $row => you may call your function using $row['id_product'] (and product_attribute_id) and retrieve it's short description using SQL. Then it might be assigned to $row['product_short_desc'].

You will use this information in invoice.tpl somewhere in {foreach $order_details as $order_detail}, it will be {$order_detail.product_short_desc}

 

Honestly, I didn't test it but it should work like that. PDF variables are collected in HTMLTemplateInvoice.php, 'order_details' => $this->order_invoice->getProducts()

 

I did not understand which file I need to change! I have prestashop 1.4.8.2

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

1. OrderInvoice class is located in /classes/order/OrderInvoice.php

Add some code to extract product short description to getProducts result.

 

Example: put this code in function getProducts after $row['id_address_delivery'] = $order->id_address_delivery;

$sql = SELECT `description_short`
FROM `'._DB_PREFIX_.'product`
WHERE `id_product` = '.(int)$row['id_product'];
$row['product_desc_short'] = Db::getInstance()->getValue($sql);

 

2. Invoice template is located in /pdf/invoice.tpl

Add some code to display product short description.

 

Example: modify the product name display: <td style="text-align: left; width: 45%">{$order_detail.product_name}</td>

Add product short description in the same cell of the table, under the name

<td style="text-align: left; width: 45%">{$order_detail.product_name}</br>{$order_detail.product_desc_short}</td>

  • Like 1
Link to comment
Share on other sites

  • 3 months later...
  • 1 month later...

1. OrderInvoice class is located in /classes/order/OrderInvoice.php

Add some code to extract product short description to getProducts result.

 

Example: put this code in function getProducts after $row['id_address_delivery'] = $order->id_address_delivery;

$sql = SELECT `description_short`
FROM `'._DB_PREFIX_.'product`
WHERE `id_product` = '.(int)$row['id_product'];
$row['product_desc_short'] = Db::getInstance()->getValue($sql);
2. Invoice template is located in /pdf/invoice.tpl

Add some code to display product short description.

 

Example: modify the product name display: <td style="text-align: left; width: 45%">{$order_detail.product_name}</td>

Add product short description in the same cell of the table, under the name

<td style="text-align: left; width: 45%">{$order_detail.product_name}</br>{$order_detail.product_desc_short}</td>

it doesnt work at all, it crashes the whole site 

Link to comment
Share on other sites

  • 1 month later...
  • 2 weeks later...

I made some changes that worked for me in pretaShop 1.5.4.1  :

Keep in mind that I am not a presta shop expert !

 

 

pdf/invoice.tpl:
change :
<td style="text-align: left; width: 45%">{$order_detail.product_name}</td>
to
<td style="text-align: left; width: 45%">{$order_detail.product_name}  - {$order_detail.description_short}</td>
 
 
classes/order/OrderInvoice.php:
change:
        public function getProductsDetail()
        {
                return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
                SELECT *
                FROM `'._DB_PREFIX_.'order_detail` od
                LEFT JOIN `'._DB_PREFIX_.'product` p
                ON p.id_product = od.product_id
                LEFT JOIN `'._DB_PREFIX_.'product_shop` ps ON (ps.id_product = p.id_product AND ps.id_shop = od.id_shop)
                WHERE od.`id_order` = '.(int)$this->id_order.'
                AND od.`id_order_invoice` = '.(int)$this->id);
        }
 
to:
 
        public function getProductsDetail()
        {
                return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
                SELECT *
                FROM `'._DB_PREFIX_.'order_detail` od
                LEFT JOIN `'._DB_PREFIX_.'product` p
                ON p.id_product = od.product_id
                LEFT JOIN `'._DB_PREFIX_.'product_lang` pl
                ON pl.id_product = od.product_id
                LEFT JOIN `'._DB_PREFIX_.'product_shop` ps ON (ps.id_product = p.id_product AND ps.id_shop = od.id_shop)
                WHERE od.`id_order` = '.(int)$this->id_order.'
                AND od.`id_order_invoice` = '.(int)$this->id);
        }
 

That should do the trick !

 

MODIFIED on nov 11 2013: 

Original there were also some changes in file: classes/order/OrderDetail.php

This was wrong and not needed ! (if it was changed, the application crashed on new orders)

Edited by avdleun (see edit history)
  • Like 1
Link to comment
Share on other sites

  • 2 years later...
  • 2 months later...

I tried your suggestion on Prestashop 1.6.1.6

-I changed the code of the function getProductsDetail() exactly as you did

-I added this code to invoice.product-tab.tpl 

<td class="product center">

{$order_detail.description_short}
</td> 
- I let the invoice.tpl as it is:
<td colspan="12">
{$product_tab}
</td>
 
But I get the "demo" short description of the template product (which is about a T-Shirt) and not my own short description.
Any idea? thanks a lot in advance!
Link to comment
Share on other sites

  • 2 months later...
  • 2 weeks later...

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...