Jump to content
tuk66

[MODULE] M4 PDF Extensions (with online editor)

Recommended Posts

Bonjour à tous,

 

Sur les facture PDF,

 

Je souhaiterais afficher une mention spécifique selon si les produits sont en stock ou pas.

 

Exemple Pour chaque produit commandé :

 

{if $variable_pour_stock_de_ce_produit > 1 }

 

{ls='Ce produit est Livré sous 24 Heures'}

 

{else}

 

{ls='Ce produit sera livré dans 30 jours'}

 

{/if}

 

Quelqu'un aurai t'il une idée

 

Votre aide serais la bienvenue,

 

Merci

Pascal

Share this post


Link to post
Share on other sites

Bonjour,

 

Avec cette méthode : StockAvailable::getStockAvailableIdByProductId($id_product, $id_product_attribute = null, $id_shop = null)

 

Je peux récupérer uniquement ID du stock, mais pas la quantité de produit disponible en stock.

 

Il y aurait il, une autre solution pour récupérer la quantité en stock ?

 

Merci

Share this post


Link to post
Share on other sites

Yes, I'm sorry for that. The right method is:

Oui, je suis désolé pour ça. La bonne méthode est:

 

StockAvailable::getQuantityAvailableByProduct($id_product = null, $id_product_attribute = null, $id_shop = null)

Share this post


Link to post
Share on other sites

Hello again

 

Is it possible to add a columnn to an invoice template to include the text written by the customer in the customizable products?

 

thanks in advance

Edited by Ubicacion (see edit history)

Share this post


Link to post
Share on other sites

Information about customizable products is automatically shown under the product name - value and quantity.

Share this post


Link to post
Share on other sites

Hi,

 

After I update to 1.6.10, the invoice # became the default one.... it used to show my reference number,

 

i.e. reference number=invoice number....

 

any idea?

Share this post


Link to post
Share on other sites

Try one of these values:

 

$order[orders].invoice_number
$order[orders].id_order
$order[orders].reference

Share this post


Link to post
Share on other sites

In all invoice (order) templates exists the main order {section} loop. Within this loop, $order[orders] is one order. It is an array and you can show any array item using . (dot) notation.

  • Like 1

Share this post


Link to post
Share on other sites

thanks, that solved it. May I know what caused it to change? I did not upgrade the module since very long and template...just core prestashop version?

 

also, how can I change the file name to use order.reference? now it is using prefix# invoice.number

Share this post


Link to post
Share on other sites

The file name is created from its prefix and number. It is not possible to use another number, like order reference.

Share this post


Link to post
Share on other sites

Show current year on invoice

 

It is assumed you have enabled the "Add current year to invoice number" option at Orders > Invoices.

 

 

To show the year add this snippet to your template:

{if Configuration::get('PS_INVOICE_USE_YEAR')}
    {$order[orders].invoice_date|date_format:"%Y"}
{/if}

Date format options are described at http://www.smarty.net/docsv2/en/language.modifier.date.format.tpl

 

%y - year as a decimal number without a century (range 00 to 99)
%Y - year as a decimal number including the century

 

  • Like 1

Share this post


Link to post
Share on other sites

Hi - I have in my shop function grouped features. I create base features. If product don't have short descripition displayed are feeature from base group. This work ok.
My code in product tpl. or productlist.tpl look this:

{if $product.description_short|count_characters:true > 3}
						{$product.description_short}
					{else}
						{if count($product.features_base)}
						<ul class="features_baase">			
                            {foreach from=$product.features_base item=feature}
                                
                                    {if isset($feature.value)}			    
                                        <span class="label">{$feature.name|escape:'html':'UTF-8'}:</span>
                                        <span class="value">{$feature.value|escape:'html':'UTF-8'}</span>
                                    {/if}
                                </br>
                            {/foreach}
                        </ul>

						{/if}

					{/if} 

How I can put this code to products catalog, or how add sql query to display only selected features. 

 

In product controller i have added this function:

$product_features_by_group = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
				SELECT name, GROUP_CONCAT(value SEPARATOR \', \') AS value, pf.id_feature
				FROM '._DB_PREFIX_.'feature_product pf
				INNER JOIN '._DB_PREFIX_.'featurestogroups fg ON (fg.id_feature = pf.id_feature AND (fg.id_group = 30 OR fg.id_group = 31 OR fg.id_group = 32 OR fg.id_group = 33 OR fg.id_group = 43))
				LEFT JOIN '._DB_PREFIX_.'feature_lang fl ON (fl.id_feature = pf.id_feature AND fl.id_lang = 1)
				LEFT JOIN '._DB_PREFIX_.'feature_value_lang fvl ON (fvl.id_feature_value = pf.id_feature_value AND fvl.id_lang = 1)
				LEFT JOIN '._DB_PREFIX_.'feature f ON (f.id_feature = pf.id_feature AND fl.id_lang = 1)
				LEFT JOIN ps_features_groups_categ fgc ON (fg.id_group = fgc.id_group)
                LEFT JOIN ps_product p ON (pf.id_product = p.id_product)
				WHERE pf.id_product = '.(int)$id_product.' AND (p.id_category_default = fgc.id_categ) 
        GROUP BY pf.id_feature
				ORDER BY fg.position ASC')

Can You help me?

Share this post


Link to post
Share on other sites

You are using two new tables. I don't think you can easily use them to print a catalog.

Share this post


Link to post
Share on other sites

Thank you for your answer.

Modifying I did this, it was not that hard,

I added the desired function (SQL query) to M4Product.php and used it in the appropriate place in the file with the pattern of pdf.

It works exactly the way I wanted  :D

I like this module   :)

Edited by And63 (see edit history)

Share this post


Link to post
Share on other sites

Some of our product names have pack sizes at the end

 

For example:

M16 A4 Stainless Steel flat washer Pack Size : 8
 
Using other systems I can isolate the last number "8" and use it in calculations. So for example, the customer buys "2" of: 
M16 A4 Stainless Steel flat washer Pack Size : 8
 
 
So they need 2 *8 = 16 washers in total
 
In another system I can use:
TRIM(SUBSTRING_INDEX(T2.product_name,':',-1)) * T2.product_quantity
 
To isolate the last numbers in the product name and mulitply by the quantity
 
is there a way to do that with M4PDF coding?

Share this post


Link to post
Share on other sites

You can use almost all PHP commands in Smarty. To show it use

{trim(substr(strrchr($order[orders].order_detail[detail].product_name, ':'), 1)) * $order[orders].order_detail[detail].product_quantity}

and to assign it to a variable use

{$var = trim(substr(strrchr($order[orders].order_detail[detail].product_name, ':'), 1)) * $order[orders].order_detail[detail].product_quantity}

Share this post


Link to post
Share on other sites

 

You can use almost all PHP commands in Smarty. To show it use

{trim(substr(strrchr($order[orders].order_detail[detail].product_name, ':'), 1)) * $order[orders].order_detail[detail].product_quantity}

and to assign it to a variable use

{$var = trim(substr(strrchr($order[orders].order_detail[detail].product_name, ':'), 1)) * $order[orders].order_detail[detail].product_quantity}

Excellent, works a treat. Thank you

Edited by haylau (see edit history)

Share this post


Link to post
Share on other sites

Hi,

 

May I know how does the Products total calculated???

 

I have problem getting it correct on the pdf invoice... I think it is some rounding issue....

 

the subtotal is incorrect but the Grand total is correct, which is very weird...

Share this post


Link to post
Share on other sites

You should know that there are many PrestaShop versions, you can have many different settings in your shop and use different approaches to create orders. I mean it is not easy to find the reason of wrong amounts in the order and the invoice as well. There is no general answer for all.

Share this post


Link to post
Share on other sites

hello

First i whant to say good work with this module.
 

I have had the opportunity to try the module.
That's one thing I wonder about.
 
How to create a category list of the categories you have, in the contents.
 
Category 1
- sub
- sub
- sub
 
Category 2
- sub
- sub
- sub
 
And so on.

Share this post


Link to post
Share on other sites

See the "Catalog grouped by default categories, all data" template, m4_catalog_category_alldata.tpl.

 

Two important things are used:

 

1. foreach loop which allows to sort data

{foreach from=$product|@sortby:"parents_categories_level,name" item=products name=cycle}

 

2. temporary variable

$changed_default_category used at more places in the template to show the header only once (category 1, category 2 in your case).

Share this post


Link to post
Share on other sites

The new version of the module is available at www.presta-addons.com. All upgrades are FREE for life.

CHANGELOG

 

 v2.2.6 (2017-04-26)

- PrestaShop 1.7.0 and 1.7.1 compatible
- New template "Invoices enhanced with sortable items" (m4_invoice_5.tpl)
- New configuration values "invoice_use_year", "invoice_taxes_breakdown" and "pdf_img_invoice" for templates
- New option to choose the type of image used to save the memory needed to create the catalog (catalog templates)
- New custom page style for Table of Contents (catalog templates)
- Fixed amounts on the credit slip if the database contains an incorrect amount with tax (PrestaShop v1.6, an occasional issue)
- Fixed white page for the product page catalog in the Front Office (disabled module only)
- Fixed a bug in the "Catalog labels 32x57 mm, Dymo 11354" template - the attributes for the last item were incomplete for combinations
- Fixed display and filtering in the Displayed column (catalog, Multistore only)
- Fixed link to product page (some catalog templates)
- Fixed value $conf.currency_default (catalog, Multistore only)

Share this post


Link to post
Share on other sites

Hi,

 

I'm trying to do a custom catalog template.

I want every new category start in left page of the catalog.

I can do it counting every <pagebreak /> except for the TOC page.

 

How can i count the amount of pages used to build Table of contents?

 

Thanks

Share this post


Link to post
Share on other sites

The new version of the module is available at www.presta-addons.com. All upgrades are FREE for life.

CHANGELOG

 

v2.3.0 (2017-06-04)
! The module is needed to uninstall and reinstall the new version due to changes in the /override/classes/pdf/PDF.php file (only PrestaShop v1.6.0.12 and later)
- Support for sending delivery notes via email (PrestaShop v1.6.0.12 and later)
- Small changes of generated HTML code for better XHTML compatibility

Share this post


Link to post
Share on other sites

You should know that there are many PrestaShop versions, you can have many different settings in your shop and use different approaches to create orders. I mean it is not easy to find the reason of wrong amounts in the order and the invoice as well. There is no general answer for all.

 

Hi,

 

is there any way to pin point the problem??

 

perhaps I can simply delete the upper field??

post-778939-0-47725600-1496734686_thumb.png

Share this post


Link to post
Share on other sites

You shows "2 totals". What are these values? I would need to know some details about the template. Can you send me a private message?

Share this post


Link to post
Share on other sites

Yes, I did. Forgive me for being late.
 

Can you see the records for this order directly in the database, tables ps_orders and ps_order_detail? I think the problem could be in the data.

 

 

Regards,
Vladimir Turek

turek@presta-addons.com

Share this post


Link to post
Share on other sites

 

HOW TO show all product images in invoice

 

Insert the code below inside the order_detail loop ({section name=detail loop=$order[orders].order_detail}) to display product features. This example shows creating object instances inside a template (needs at least v2.1.0).

{factory assign="product" class="Product" id_product=$order[orders].order_detail[detail].product_id id_lang=$m4_actual_language}
{if is_object($product)}
    {assign var="images" value=$product->getImages($m4_actual_language)}
    {section name=image loop=$images}
        {if $images[image].id_image}
            {assign var="id_product_id_image" value="`$order[orders].order_detail[detail].product_id`-`$images[image].id_image`"}
            <img src="{imageLink name=$order[orders].order_detail[detail].product.link_rewrite ids=$id_product_id_image}" style="width:18mm; margin:1mm" />
        {/if}
    {/section}
{/if}

 

Hello,

 

How do I inlcude the BARCODE to the catalog template? we need to inlcude the QR of the link to each products' page the same as we did on the invoices.

 

Reagrds,

Share this post


Link to post
Share on other sites

Hi guys!

 

I bought your module yesterday and my intention is use it to show the Location column in Delivery Slips, but I need to sort all content of PDF by the location code.

 

This code has 3 characters, 1st numeric,2nd alphabetic and 3rd numeric (example: 1A3). 

 

Could you help me with the expression that I need to sort that location column by that kind of code?

 

Example of use:

Location (column)

1A2
1A4
1B3
2A1
..
..

A lot of thanks in advance!!  :)

Edited by markinhos3 (see edit history)

Share this post


Link to post
Share on other sites

Hi guys!

 

I bought your module yesterday and my intention is use it to show the Location column in Delivery Slips, but I need to sort all content of PDF by the location code.

 

This code has 3 characters, 1st numeric,2nd alphabetic and 3rd numeric (example: 1A3). 

 

Could you help me with the expression that I need to sort that location column by that kind of code?

 

Example of use:

Location (column)

1A2
1A4
1B3
2A1
..
..

A lot of thanks in advance!!  :)

 

PLEASE! I need your support in this question! 

 

My code from "Delivery slips with image and location" Template is:

<div class="clear zero">
    		<table class="w100 items">
    			<thead>
    			<tr>
    			    <th>{l s='Location' mod='m4pdf'}</th>
    				<th>{l s='Description' mod='m4pdf'}</th>
    				<th>{l s='Reference' mod='m4pdf'}</th>
    				<th>{l s='Qty' mod='m4pdf'}</th>
    			</tr>
    			</thead>
    	        {foreach from=$order[orders].order_detail|@sortby:"warehouse_product_location.location" item=order_detail}
            			<tr>
            				<td class="align-center" style="font-size: 15px"><strong>{$order[orders].order_detail[detail].warehouse_product_location.location|escape:'htmlall':'UTF-8'}</strong></td>
            				<td>{$order[orders].order_detail[detail].product_name|escape:'htmlall':'UTF-8'}</td>
            				<td>{if $order[orders].order_detail[detail].product_reference != ''}{$order[orders].order_detail[detail].product_reference|escape:'htmlall':'UTF-8'}{else}---{/if}</td>
            				<td class="align-center" style="font-size: 15px"><strong>{$order[orders].order_detail[detail].product_quantity}</strong></td>
            			</tr>
            	{foreachelse}
            			<tr>
            				<td colspan=3>{l s='no order details' mod='m4pdf'}</td>
            			</tr>
            	{/foreach}
    		</table>
		
	</div>
	
    <div class="cell align-right clear" style="left: 0mm; right: 0mm; bottom: 2mm; ">
		<barcode code="{$order[orders].invoice_number|string_format:"%06d"}" type="C128A" class="barcode" />
	</div>

But I don't get to sort the location column with that, help me please!

Share this post


Link to post
Share on other sites

It is almost perfect. Here is the sortable code snippet for the order items.

<div class="clear zero">
    <table class="w100 items">
        <thead>
        <tr>
            <th>{l s='Qty' mod='m4pdf'}</th>
            <th>{l s='Location' mod='m4pdf'}</th>
            <th>{l s='Description' mod='m4pdf'}</th>
            <th>{l s='Reference' mod='m4pdf'}</th>
        </tr>
        </thead>
        
    {foreach from=$order[orders].order_detail|@sortby:"warehouse_product_location.location" item=order_detail}
        <tr>
            <td class="align-right">{$order_detail.product_quantity}</td>
            <td>{$order_detail.warehouse_product_location.location|escape:'htmlall':'UTF-8'}</td>
            <td>{$order_detail.product_name|escape:'htmlall':'UTF-8'}</td>
            <td>{if $order_detail.product_reference != ''}{$order_detail.product_reference|escape:'htmlall':'UTF-8'}{else}---{/if}</td>
        </tr>
    {foreachelse}
        <tr>
            <td colspan=4>{l s='no order details' mod='m4pdf'}</td>
        </tr>
    {/foreach}
    </table>
</div>
Edited by tuk66 (see edit history)

Share this post


Link to post
Share on other sites

Yeah!! Now everything works perfect!

 

I did't realize I had to remove the order[orders] array in the <td> command and I was going crazy..

 

Thanks so much for your help and your fantastic work in this module! 

Share this post


Link to post
Share on other sites

Hello, i need some help please, i use the field EAN13 to other thing and i´ve this configured to acept more than 13 chars, but when i made the call with {$order_detail.product_ean13} this only show 13 chars.... i try to changue the file barcode.php but nothing.

Share this post


Link to post
Share on other sites

The reason is that EAN13 code can be printed only if it is valid EAN13 code. A number larger than 13 digits is not valid EAN13 code. You have to use other barcode type to print your code. See https://github.com/booktype/mpdf-manual/blob/master/mpdfmanual.pdf, page #154 what codes can be printed. Set the appropriate code in the <barcode> element.


The new version of the module is available at www.presta-addons.com. All upgrades are FREE for life.

CHANGELOG

 

v2.3.1 (2017-08-22)
- Added credit_slip_prefix and return_prefix constants for system credit slip and order return prefixes
- When printing on the Orders > Invoices and Delivery slips pages, the documents are selected based on the date of issue the document, not the data of issue the order

  • Like 1

Share this post


Link to post
Share on other sites

HOW TO print product names in two languages at once in invoice

 

In this example I am going to show you how to print the original product name in customer's language together with the name in one complementary language.

{* Language IDs in this example: 1 for English, 3 for Chinese *}

{* Product name in more languages *}
    {* Set Chinese language ID from Localization > Languages instead of 3 *}
    {assign var="product_name_chinese" value=Product::getProductName($order[orders].order_detail[detail].product_id, $order[orders].order_detail[detail].product_attribute_id, 3)}

    {* Set English language ID from Localization > Languages instead of 1 *}
    {assign var="product_name_english" value=Product::getProductName($order[orders].order_detail[detail].product_id, $order[orders].order_detail[detail].product_attribute_id, 1)}
{* /Product name in more languages *}

{* Show the original product name in customer's language together with the second one *}
{$order[orders].order_detail[detail].product_name|escape:'htmlall':'UTF-8'}

{* Set English language ID from Localization > Languages instead of 1 *}
{if $order[orders].id_lang == 1}
    {* English -> show Chinese name *}
    <br />{$product_name_chinese|escape:'htmlall':'UTF-8'}

{* Set Chinese language ID from Localization > Languages instead of 3 *}
{elseif $order[orders].id_lang == 3}
    {* Chinese -> show English name *}
    <br />{$product_name_english|escape:'htmlall':'UTF-8'}
{/if}

Share this post


Link to post
Share on other sites

The new version of the module is available at www.presta-addons.com. All upgrades are FREE for life.

CHANGELOG

 

 v2.3.2 (2018-01-18)

- Smarty function {factory} can create instances of all classes, not just classes extending from ObjectModel
- Fixed "PHP Notice: Undefined property: Customer::$id_customer in /modules/m4pdf/M4Object.php"

Share this post


Link to post
Share on other sites

Hi.

How can I print invoices only for customers with a VAT number ?
I am using the Invoice template.

Regards

Share this post


Link to post
Share on other sites

Where exactly? In the module administration, the orders page or in customer's account?

I mean you can silently skip the invoice in the Back Office but have to print "something" for the customer.

Share this post


Link to post
Share on other sites

I mean the collective printout of invoices of customers with a VAT number for the needs of the tax office.

Share this post


Link to post
Share on other sites

Change this row

{if $order[orders].invoice_number}

to

{if $order[orders].invoice_number && $order[orders].address_delivery.vat_number}

and remove lines

{else}
	<div {if !$smarty.section.orders.first}class="document{$smarty.section.orders.index}"{/if}>{l s='no invoice for order No.' mod='m4pdf'} {$order[orders].id_order|string_format:"%06d"}</div>

and then print only invoices where customers have their VAT number in the module administration.

Share this post


Link to post
Share on other sites

The new version of the module is available at www.presta-addons.com. All upgrades are FREE for life.

CHANGELOG

 v2.3.2 (2018-01-18)

- Smarty function {factory} can create instances of all classes, not just classes extending from ObjectModel
- Fixed "PHP Notice: Undefined property: Customer::$id_customer in /modules/m4pdf/M4Object.php"

Share this post


Link to post
Share on other sites

HOW TO create database query directly in template

 

This example shows how to create a SQL query from data available in the template and return one value. This value is then used in the template. It assumes you are using an invoice template.

Description:

$db is the database instance object
$sql is the SQL query concatenated from several text parts using Smarty 'cat' modifier
$result get one value using the getValue() function - in this case the invoice number for the current order

You can remove Smarty comments {* and *} to print the SQL query.

{assign var="db" value=Db::getInstance($smarty.const._PS_USE_SQL_SLAVE_)}
{assign var="sql" value="SELECT `number` FROM `"|cat:$smarty.const._DB_PREFIX_|cat:"order_invoice` WHERE id_order = "|cat:$order[orders].id_order}
{assign var="result" value=$db->getValue($sql)}
{* sql: {$sql|escape:'htmlall':'UTF-8'} *}
{if $result}
    {$result|escape:'htmlall':'UTF-8'}
{/if}

 

Use with caution.

Share this post


Link to post
Share on other sites

Hi,
in recent times I have the problem that seemingly random there is no tax on the shipping on the invoice.
I couldn't find a reason for that nor a commonality of the orders. In the debug template it also states carrier_tax_rate => "0.000"
It's a PS 1.6.1.10 with M4PDF v2.2.5 running with Advanced EU Compliance and PrestaPlus. Is it even a problem of M4PDF? where does it get the carrier tax rate from?

Share this post


Link to post
Share on other sites

carrier_tax_rate is a value stores in the ps_orders table. It should be filled in with tax rate, like 20, 21 or 0.

It looks like the Advanced EU Compliance module doesn't set this value in some cases due to its settings affecting carriers. Look into the ps_order_invoice_tax table for multiple shipping records associated with the order. In this case it is possible to get all tax rates using some approach described in How Tos (1st post).

https://www.prestashop.com/forums/topic/270613-module-m4-pdf-extensions-with-online-editor/

Share this post


Link to post
Share on other sites

ps_order_invoice_tax looks kind of strange, but you can see the correlation there: There is always a wrapping and a shipping entry for the orders where the tax is right and for those orders where the shipping tax is missing there is no entry for shipping or it's entirely missing both (but we don't even use wrapping at all). How can that happen? Is there a way to regenerate it?
Thanks for the help!

Share this post


Link to post
Share on other sites

Hello, I wonder if you can help me.

I'm setting up a new version of our website and using Prestashop 1.7.4.2. Installed M4PDF v. 2.4 which went well. However everytime I try to create a PDF it comes up saying error.

I enabled debug mode and it displays 403 Forbidden Error Access to this resource on this server is denied.

Also on the list of requirements that need to be installed, the only exception is the M4 Core Fonts, but I can't install these for the same reason.

Any ideas what I might need to do? I presume I need to contact the server company to enable something, but unsure what to ask for.

Thanks

Share this post


Link to post
Share on other sites

" 403 Forbidden Error Access " looks like a .htaccess issue. Try to load http://your_domain.co.uk/modules/m4pdf/pdf.php and then https://...

You should get something like

{"error":"1","msg":"Invalid call type","token":"f6bfeed6f803a5ebafe83cf46a2bc287","memory":"3M","time":"0s"}

 

Share this post


Link to post
Share on other sites

Hi, thanks for the reply. If i goto modules/m4pdf/pdf.php using my domain as suggested, I once again get 403 Forbidden Error.

Is this something to do with permissions?

Share this post


Link to post
Share on other sites

Does everything else in your shop work well? Is your hosting shared or VPS?

This issue can be caused by a restrictive .htaccess file somewhere in the path to the pdf.php file as well as by disabled mod_access_compat Apache module.

Share this post


Link to post
Share on other sites

The new version of the module is available at www.presta-addons.com. All upgrades are FREE for life.

CHANGELOG


 v2.4.1 (2018-10-24)
- Fixed list filtering in the module administration
- Fixed missing translated strings, formatted numbers and other Smarty function outputs (PrestaShop 1.7.4 only)

 v2.4.0 (2018-10-04)
- Added the ability to select records to create a bulk PDF in the module administration
- Fixed Debug template output (PrestaShop 1.7)
- Fixed Features data (catalog, only Multistore)

  • Like 1

Share this post


Link to post
Share on other sites
On 23/10/2018 at 3:01 PM, tuk66 said:

Does everything else in your shop work well? Is your hosting shared or VPS?

This issue can be caused by a restrictive .htaccess file somewhere in the path to the pdf.php file as well as by disabled mod_access_compat Apache module.

Hi, yes everything else in the shop is working well. I am on a shared hosting. Is this something I need to raise with the hosting company do you reckon?

Share this post


Link to post
Share on other sites

It's hard to say what it does without knowing the technical details of your hosting and shop installation.

Share this post


Link to post
Share on other sites
On 26/10/2018 at 11:18 AM, tuk66 said:

It's hard to say what it does without knowing the technical details of your hosting and shop installation.

Hi, i've asked my host to have a look and they couldn't work out the issue.

If I PM'ed login details, if you have a spare moment, could you take a look?

Share this post


Link to post
Share on other sites

Hi, quick question

I'm trying to add the customers email address onto the invoice. I've added

{$order[orders].customer.email|escape:'htmlall':'UTF-8'}

which worked on the 1.6 version. However it doesn't seem to be working on the 1.7 version Prestashop. Just doesn't display any email address at all.
Any ideas?

Thanks

Share this post


Link to post
Share on other sites
22 minutes ago, tuk66 said:

It perfectly works. Where have you put this snippet?

ignore me.. i was being dense! all sorted

Share this post


Link to post
Share on other sites

The new version of the module is available at www.presta-addons.com. All upgrades are FREE for life.

CHANGELOG


 v2.5.0 (2019-01-24)

- Added ability to generate a PDF document based on the selected template on the order details page (Extra Options must be enabled)
- Fixed invoice creation on the Invoices page (PrestaShop 1.7.5)
- Fixed the PDF languge (extra options) block on some pages (PrestaShop 1.7)

  • Like 1

Share this post


Link to post
Share on other sites

Hi.
I'm looking for a module that can add a barcode to my delivery-slip (Prestashop 1.7.5)
The value of the barcode, should be the orderreference (numeric)

Can this module to the trick, or does someone know of a module that can do that.

Share this post


Link to post
Share on other sites

This module already has several templates with a barcode.

Share this post


Link to post
Share on other sites

The new version of the module is available at www.presta-addons.com. All upgrades are FREE for life.

CHANGELOG


 v3.0.0 (2019-02-04)

- Compatible with PrestaShop versions 1.6 and higher
- Compatible with PHP versions from 5.6 to 7.3
- The mPDF library has been updated to version 7.1.8
- Core fonts are automatically installed
- QR code fonts and SWOP 2006 ICC profiles are already part of the module
- Using {foreach} instead of {section} in all templates for clearer code and sorting of items directly in the template
- Added mPDF system error displaying
- Image links are file-only to reduce HTTPS related issues
- Directory links (* _dir) have file:// protocol instead of http://
- Fixed sending of blank invoices and delivery strips by email (only on the Orders page with the Order Status filter)
- Removed code for older versions of PrestaShop
- Changed directory structure as recommended for PrestaShop 1.6 - 1.7

Edited by tuk66 (see edit history)
  • Like 1

Share this post


Link to post
Share on other sites

HOW have the templates changed in v3.0.0

 

Important is that the data for the templates remains the same. They are only used differently. You can still use current templates.

All loops are changed from {section} to {foreach}. It has two benefits. The variables in the templates are less chatty. The code is clearer. Secondly, you can sort records straight in the template.

 

Here are the changes in the loops. The first line is the old version and the second line is the new version.

Catalog
---------

from
{section name=attributes loop=$product[products].product_attribute}
to
{foreach from=$r_product.product_attribute item=product_attribute name=product_attribute}

{section name=features loop=$products.product_feature}
{foreach from=$r_product.product_feature item=product_feature name=product_feature}

{section name=prices loop=$product[products].specific_price}
{foreach from=$r_product.specific_price item=specific_price name=specific_price}

{section name=pack_items loop=$products.pack}
{foreach from=$r_product.pack item=pack name=pack}

{section name=products loop=$product}
{foreach from=$product item=r_product name=r_product}

{foreach from=$product|@sortby:"parents_categories_level,name" item=products name=cycle}
{foreach from=$product|@sortby:"parents_categories_level,name" item=r_product name=r_product}

{foreach from=$product|@sortby:"parents_categories_level" item=products name=cycle}
{foreach from=$product|@sortby:"parents_categories_level" item=r_product name=r_product}

{foreach from=$product|@sortby:"parents_categories_reversed,name" item=products name=cycle}
{foreach from=$product|@sortby:"parents_categories_reversed,name" item=r_product name=r_product}


Categories
------------

{section name=categories loop=$category}
{foreach from=$category item=r_category name=r_category}

{section name=subcats loop=$category}
{foreach from=$category item=subcategory name=subcategory}


Customers
----------

{section name=customers loop=$customer}
{foreach from=$customer item=r_customer name=r_customer}

{section name=addresses loop=$customer[customers].address}
{foreach from=$r_customer.address item=address name=address}


Orders with details, Invoices
------------------------------

{section name=detail loop=$order[orders].order_detail}
{foreach from=$r_order.order_detail item=order_detail name=order_detail}

{section name=discount loop=$order[orders].order_discount}
{foreach from=$r_order.order_cart_rule item=order_cart_rule name=order_cart_rule}

{section name=custom_test loop=$order[orders].customization}
{foreach from=$r_order.customization item=customization name=customization}

{section name=custom loop=$order[orders].customization}
{foreach from=$r_order.customization item=customization name=customization}

{section name=private_message loop=$order[orders].order_private_message}
{foreach from=$r_order.order_private_message item=order_private_message name=order_private_message}

{section name=orders loop=$order}
{foreach from=$order item=r_order name=r_order}


Orders
-------

{section name=orders loop=$order}
{foreach from=$order item=r_order name=r_order}

{section name=payment loop=$payments}
{foreach from=$payments item=payment name=payment}

{section name=shipping loop=$shippings}
{foreach from=$shippings item=shipping name=shipping}


Order returns with details
---------------------------

{section name=detail loop=$orderreturn[orderreturns].order_return_detail}
{foreach from=$r_orderreturn.order_return_detail item=order_return_detail name=order_return_detail}

{section name=orderreturns loop=$orderreturn}
{foreach from=$orderreturn item=r_orderreturn name=r_orderreturn}


Credit slips with details
--------------------------

{section name=detail loop=$orderslip[orderslips].order_slip_detail}
{foreach from=$r_orderslip.order_slip_detail item=order_slip_detail name=order_slip_detail}

{section name=discount loop=$orderslip[orderslips].order.order_cart_rule}
{foreach from=$r_orderslip.order.order_cart_rule item=order_cart_rule name=order_cart_rule}

{section name=orderslips loop=$orderslip}
{foreach from=$orderslip item=r_orderslip name=r_orderslip}


Supply orders with details
---------------------------

{section name=detail loop=$supplyorder[supplyorders].supply_order_detail}
{foreach from=$r_supplyorder.supply_order_detail item=supply_order_detail name=supply_order_detail}

{section name=detail loop=$supplyorder[supplyorders].tax_order_summary}
{foreach from=$r_supplyorder.tax_order_summary item=tax_order_summary name=tax_order_summary}

{section name=supplyorders loop=$supplyorder}
{foreach from=$supplyorder item=r_supplyorder name=r_supplyorder}

.

.
Here are the changes in the variables. Again, the first line is the old version and the second line is the new version. All root data begins with the prefix r_ followed by the passed variable. Other data has the name exactly according to the index in the passed variable. No longer long names of variables in the templates.

Catalog
---------

from
$product[products].
to
$r_product.

$product[products].product_attribute[attributes].
$product_attribute.

$product[products].product_feature[features].
$product_feature.

$product[products].specific_price[prices].
$specific_price.

$products.pack[pack_items].
$pack.


Categories
------------

$category[categories].
$r_category.

$category[subcats].
$subcategory.


Customers
----------

$customer[customers].
$r_customer.

$address[addresses].
$address.


Orders with details, Invoices
------------------------------

$order[orders].
$r_order.

$order[orders].order_detail[detail].
$order_detail.

$order[orders].order_discount[discount].
$order_cart_rule.

$order[orders].customization[custom_test].
$customization.

$order[orders].customization[custom].
$customization.

$order[orders].order_private_message[private_message].
$order_private_message.


Orders
-------

$order[orders].
$r_order.

$payments[payment]
$payment

$shippings[shipping].
$shipping.


Order returns with details
---------------------------

$orderreturn[orderreturns].
$r_orderreturn.

$orderreturn[orderreturns].order_return_detail[detail].
$order_return_detail.


Credit slips with details
--------------------------

$orderslip[orderslips].
$r_orderslip.

$orderslip[orderslips].order_slip_detail[detail].
$order_slip_detail.

$orderslip[orderslips].order.order_cart_rule[discount].
$order_cart_rule.


Supply orders with details
---------------------------

$supplyorder[supplyorders].
$r_supplyorder.

$supplyorder[supplyorders].supply_order_detail[detail].
$supply_order_detail.

$supplyorder[supplyorders].tax_order_summary[detail].
$tax_order_summary.

 

Share this post


Link to post
Share on other sites
Posted (edited)

Hi recently I have quite a lot of this messages in the phperrors.log

[07-Mar-2019 09:37:43 Europe/Berlin] PHP Warning:  include(/shop/modules//m4pdf/translations/.php): failed to open stream: No such file or directory in /shop/modules/m4pdf/classes/M4Object.php on line 2370
[07-Mar-2019 09:37:43 Europe/Berlin] PHP Warning:  include(): Failed opening '/shop/modules//m4pdf/translations/.php' for inclusion (include_path='.:/usr/lib/php7.0') in /shop/modules/m4pdf/classes/M4Object.php on line 2370
[07-Mar-2019 09:37:43 Europe/Berlin] PHP Notice:  Trying to get property of non-object in /shop/modules/m4pdf/classes/M4Object.php on line 2363

They appear in hundreds in just a minute at some points.
I recently updated to the current version because I had seen the errors before aswell, but still they come. Any suggestion on that?
PS 1.6.1.10 , PHP 7.0.33

Edited by RabbitZzZ (see edit history)

Share this post


Link to post
Share on other sites

It seems Language::getIsoById() function returns empty string. So the iso_code value for the language is probably empty or something similar.

Share this post


Link to post
Share on other sites
Posted (edited)
On 3/7/2019 at 12:51 PM, RabbitZzZ said:

Any idea where this could come from?

Sorry, I have to bring this up again.

It also seems strange with the double slash in there. Does _PS_MODULE_DIR_ return with a slash in the end?

Edited by RabbitZzZ
additional question (see edit history)

Share this post


Link to post
Share on other sites

Double slashes are fine. They can't cause anything wrong.

Share this post


Link to post
Share on other sites

It is only in your shop. I have no idea why.

Share this post


Link to post
Share on other sites
On 2/17/2019 at 11:29 AM, tuk66 said:

The new version of the module is available at www.presta-addons.com. All upgrades are FREE for life.
 v3.0.0 (2019-02-04)

Do I understand it is fully backwards compatible?

What is the upgrade process? (The included UPGRADE.TXT only goes up to 2.2.5).

Your continued development is much appreciated - I look forward to upgrading when the above is clarified.

Share this post


Link to post
Share on other sites

Yes, this version is fully compatible. You can use your old templates and you can also use new and old templates together. The new templates look the same, just their code is clearer. The fonts are also the same.

The upgrade process is straitforward so there are no special instructions needed. Just upload the module as a new one. Of course, the original templates are overriden so backup them if you have altered them.

Share this post


Link to post
Share on other sites

The new version of the module is available at www.presta-addons.com. All upgrades are FREE for life.

CHANGELOG


 v3.0.1 (2019-02-25)

- Fixed PDF Button faulty error on the Category page (PrestaShop 1.7)
- Fixed an occasional error Warning: file(.../modules/m4pdf/override/controllers/front/listing/CategoryController.php): No such file or directory (PrestaShop 1.7 in Debug mode)
- Fixed an error using the ~Debug template (PrestaShop 1.7.4 and later in Debug mode)

 v3.0.2 (2019-05-06)

- Added configuration values shop_main_domain and shop_main_domain_ssl in template data, usable in Multistore
- Fixed image width in catalog templates (PrestaShop 1.7)
- Fixed the number of pieces in the catalog templates (Multistore, sharing of stock)

Share this post


Link to post
Share on other sites

Hello Tuk66

Thank your for this amazing module.

Im trying to add a column with the available stock for each product. The datas are in the PS_stock_available. table.

What i tried

- <td>{$order_detail.stock_available.quantity|escape:'htmlall':'UTF-8'}</td>

- <td>{$stock_available.quantity|escape:'htmlall':'UTF-8'}</td>

 

Is it possible to use datas wich are not related to orders ?

Thanks for your help !

 

Share this post


Link to post
Share on other sites

Sure. You can use any static method in the template. See

 

Try this code:

{assign var="stock" value=StockAvailable::getStockAvailableIdByProductId( $order_detail.product_id,  $order_detail.product_attribute_id)}
{if is_int($stock)}
    $stock
{/if}



 

 

  • Like 1

Share this post


Link to post
Share on other sites

Thank you for your quick answer

I forgot to mention that I'm using a delivery slip , so i dont find what is the "order loop".

The template im using is sorting products regarding warehouse location.

Here is my code , i posted your code on line 128 and added a  <td>{$stock}</td> on line 249

<!-- 
	name="{l s='Bon de livraison TEST KRIS' mod='m4pdf'}" 
	data="order+detail"
-->

{assign var='sort' value='warehouse_product_location.location'}
<head>
{literal}
	<style>
		@page {
			sheet-size: A4;
			margin: 10mm;
			margin-bottom: 35mm;
			margin-header: 0; 
			margin-footer: 6mm;
			odd-footer-name: html_footer0;
			even-footer-name: html_footer0;
		}
{/literal}
{foreach from=$order item=r_order name=r_order}
	{if !$smarty.foreach.r_order.first}
		@page document{$smarty.foreach.r_order.index} {literal}{{/literal}
			odd-footer-name: html_footer{$smarty.foreach.r_order.index};
			even-footer-name: html_footer{$smarty.foreach.r_order.index};
		{literal}}{/literal}
		@page document{$smarty.foreach.r_order.index} :first {literal}{{/literal}
			resetpagenum: 1;
		{literal}}{/literal}
		div.document{$smarty.foreach.r_order.index} {literal}{{/literal}
			page: document{$smarty.foreach.r_order.index};
		{literal}}{/literal}
	{/if}
{/foreach}
{literal}
		body {
			font-size: 11px; 
			font-family: sans; 
			font-weight: normal; 
			color: black;
			background-color: white;
		}
		h1, h2, h3, h4, h5, h6, p, div, th, td {
			vertical-align: top;
			padding: 1mm;
		}
		h1 {
			font-size: 20px; 
			text-align: center;
			clear: both;
			margin-bottom: 4mm;
		}
		table {
			border-collapse: collapse;
		}
		.items th {
			border: 0.2mm solid black;
			background-color: #DDDDDD;
		}
		.items td {
			border: 0.2mm solid black;
		}
		.tbl th {
			margin: 0; 
			padding: 0;
		}
		.tbl td {
			margin: 0; 
			padding: 0;
		}
		.header {
			width: 100%;
			vertical-align: top; 
			font-family: sans; 
			font-size: 11px; 
			color: #656565;
		}
		.footer {
			width: 100%;
			vertical-align: top; 
			font-family: sans; 
			font-size: 11px; 
			color: #656565;
		}
		.left {float: left;}
		.right {float: right;}
		.align-left {text-align: left;}
		.align-center {text-align: center;}
		.align-right {text-align: right;}
		.clear {clear: both;}
		.zero {margin: 0; padding: 0;}
		.bold {font-weight: bold;}
		.italic {font-style: italic;}
		.smaller {font-size: 80%;}
		.bigger {font-size: 120%;}
		.w5 {width: 5%;}
		.w10 {width: 10%;}
		.w20 {width: 20%;}
		.w30 {width: 30%;}
		.w40 {width: 40%;}
		.w50 {width: 50%;}
		.w60 {width: 60%;}
		.w70 {width: 70%;}
		.w80 {width: 80%;}
		.w90 {width: 90%;}
		.w100 {width: 100%;}
		.border {border: 1px solid black;}
	</style>
{/literal}
</head>
<body>

{if $conf.cloud}
	{assign var="force_protocol" value="http"}
{else}
	{assign var="force_protocol" value=""}
{/if}

{foreach from=$order item=r_order name=r_order}
{if $r_order.delivery_number}
	{if $conf.customers_lang}
		{assign var="m4_actual_language" value=$r_order.id_lang}
	{else}
		{assign var="m4_actual_language" value=$conf.pdf_id_lang}
	{/if}

	{if empty($r_order.id_shop)}{assign var="shop_id" value="0"}{else}{assign var="shop_id" value=$r_order.id_shop}{/if}

	{assign var="stock" value=StockAvailable::getStockAvailableIdByProductId( $order_detail.product_id,  $order_detail.product_attribute_id)}
{if is_int($stock)}
    $stock
{/if}
	
<!--mpdf
	<htmlpagefooter name="footer{$smarty.foreach.r_order.index}">
	<hr class="w100 zero" />
	<div class="align-center">
		{$r_order.shop.shop_name|escape:'htmlall':'UTF-8'}
		- 
		{if $r_order.shop.shop_addr1}{$r_order.shop.shop_addr1|escape:'htmlall':'UTF-8'}{/if} 
		{if $r_order.shop.shop_code}{$r_order.shop.shop_code|escape:'htmlall':'UTF-8'}{/if} 
		{if $r_order.shop.shop_city}{$r_order.shop.shop_city|escape:'htmlall':'UTF-8'}{/if}
		{if $r_order.shop.shop_country}{$r_order.shop.shop_country|escape:'htmlall':'UTF-8'}{/if}
		{if !empty($r_order.shop.shop_state)}{$r_order.shop.shop_state|escape:'htmlall':'UTF-8'}{/if}
	</div>
	</htmlpagefooter>
mpdf-->

	<div class="left w50 zero {if !$smarty.foreach.r_order.first}document{$smarty.foreach.r_order.index}{/if}"><img src="file://{if $r_order.shop.logo_invoice}{$r_order.shop.logo_invoice}{else}{$r_order.shop.logo}{/if}" /></div>
	<div class="right zero">
		<h1 class="align-right bold">{l s='DELIVERY SLIP #' mod='m4pdf'} {$r_order.shop.delivery_prefix}{$r_order.delivery_number|string_format:"%06d"}</h1>
		<table class="w100 tbl">
			<tr>
				<td class="w50"><strong>{l s='Invoice Number' mod='m4pdf'}</strong></td>
				<td class="w50">{$r_order.shop.invoice_prefix}{$r_order.invoice_number|string_format:"%06d"}</td>
			</tr>
			<tr>
				<td><strong>{l s='Delivery Date' mod='m4pdf'}</strong></td>
				<td>{dateFormatLanguage date=$r_order.delivery_date full=0}</td>
			</tr>
			<tr>
				<td><strong>{l s='Order No.' mod='m4pdf'}</strong></td>
				<td>{$r_order.id_order|string_format:"%06d"}</td>
			</tr>
		</table>
	</div>
		
	<br /><br />
	<div class="left clear w50 zero bigger">
		<strong>{l s='Ship To' mod='m4pdf'}</strong><br />
		{if $r_order.formatted_address_delivery}
			{$r_order.formatted_address_delivery|escape:'htmlall':'UTF-8'|nl2br nofilter}
		{else}
			{if $r_order.address_delivery.company}{$r_order.address_delivery.company|escape:'htmlall':'UTF-8'}<br />{/if}
			{$r_order.address_delivery.firstname|escape:'htmlall':'UTF-8'} {$r_order.address_delivery.lastname|escape:'htmlall':'UTF-8'}<br />
			{$r_order.address_delivery.address1|escape:'htmlall':'UTF-8'}<br />
			{if $r_order.address_delivery.address2}{$r_order.address_delivery.address2|escape:'htmlall':'UTF-8'}<br />{/if}
			{$r_order.address_delivery.postcode|escape:'htmlall':'UTF-8'} {$r_order.address_delivery.city|escape:'htmlall':'UTF-8'}
			{if $r_order.shop.country_default != $r_order.address_delivery.country.id_country}<br />{$r_order.address_delivery.country.name|escape:'htmlall':'UTF-8'}{/if} 
			{if $r_order.address_delivery.state.name && $r_order.shop.country_default != $r_order.address_delivery.country.id_country} - {/if} 
			{if $r_order.address_delivery.state.name}{$r_order.address_delivery.state.name|escape:'htmlall':'UTF-8'}{/if}
			<br />{$r_order.address_delivery.phone|escape:'htmlall':'UTF-8'}<br />
			{if $r_order.address_delivery.phone_mobile}{$r_order.address_delivery.phone_mobile|escape:'htmlall':'UTF-8'}{/if}
		{/if}
	</div>
	<div class="right zero bigger">
		<strong>{l s='Invoice To' mod='m4pdf'}</strong><br />
		<div class="border" style="padding: 3mm; ">
		{if $r_order.formatted_address_invoice}
			{$r_order.formatted_address_invoice|escape:'htmlall':'UTF-8'|nl2br nofilter}
		{else}
			{if $r_order.address_invoice.company}{$r_order.address_invoice.company|escape:'htmlall':'UTF-8'}<br />{/if}
			{$r_order.address_invoice.firstname|escape:'htmlall':'UTF-8'} {$r_order.address_invoice.lastname|escape:'htmlall':'UTF-8'}<br />
			{$r_order.address_invoice.address1|escape:'htmlall':'UTF-8'}<br />
			{if $r_order.address_invoice.address2}{$r_order.address_invoice.address2|escape:'htmlall':'UTF-8'}<br />{/if}
			{$r_order.address_invoice.postcode|escape:'htmlall':'UTF-8'} {$r_order.address_invoice.city|escape:'htmlall':'UTF-8'}
			{if $r_order.shop.country_default != $r_order.address_invoice.country.id_country}<br />{$r_order.address_invoice.country.name|escape:'htmlall':'UTF-8'}{/if} 
			{if $r_order.address_invoice.state.name && $r_order.shop.country_default != $r_order.address_invoice.country.id_country} - {/if} 
			{if $r_order.address_invoice.state.name}{$r_order.address_invoice.state.name|escape:'htmlall':'UTF-8'}{/if}
			{if !empty($r_order.customer.dni)}<br />{l s='Tax ID number:' mod='m4pdf'} {$r_order.customer.dni|escape:'htmlall':'UTF-8'}{/if}
			{if $r_order.address_invoice.vat_number}<br />{l s='Tax ID number:' mod='m4pdf'} {$r_order.address_invoice.vat_number|escape:'htmlall':'UTF-8'}{/if}
		{/if}
		</div>
	</div>
	
	<br /><br />
	<div class="left clear w50 zero">
		<table class="w100 tbl">
			<tr>
				<td class="w40"><strong>{l s='Carrier' mod='m4pdf'}</strong></td>
				<td>{$r_order.carrier.name}{if $r_order.gift} - {l s='Gift-wrapped order' mod='m4pdf'}{/if}</td>
			</tr>
		{if $r_order.shipping_date}
			<tr>
				<td><strong>{l s='Shipping Date' mod='m4pdf'}</strong></td>
				<td>{dateFormatLanguage date=$r_order.shipping_date full=0}</td>
			</tr>
		{/if}
			<tr>
				<td><strong>{l s='Payment Method' mod='m4pdf'}</strong></td>
				<td>{$r_order.payment}</td>