Notice: Undefined offset 0 when generating PDF invoice for order with customized data #15358
Labels
1.7.5.2
Affects versions
1.7.6.0
Affects versions
1.7.6.1
Affects versions
BO
Category: Back Office
Customized
Product type: issue about customized products
Duplicate
Resolution: issue closed because already reported
Invoices
Label: Which BO under menu is concerned
PR available
Solution: issue is being addressed
Describe the bug
When you try to generate PDF invoices by date, a PHP notice is displayed if an order contains a product with a text customization field, but no file customization field. (I assume it will also fail if product contains a file customization field but no text customization field).
The PHP notice is "Notice: Undefined offset: 0" (see screenshot below)
To Reproduce
Steps to reproduce the behavior: Install last prestashop version and enable debug mode. Then :
Additional information
PrestaShop version: 1.7.6.1
PHP version: 5.6.30
The problem comes from the file pdf/invoice.product-tab.tpl, line 121 :
{if isset($customization.datas[$smarty.const._CUSTOMIZE_FILE_]) && count($customization.datas[$smarty.const._CUSTOMIZE_FILE_]) > 0}
When compiled by smarty, it is translated to :
<?php if ((($_smarty_tpl->tpl_vars['customization']->value['datas'][@constant('_CUSTOMIZE_FILE_')] !== null )) && count($_smarty_tpl->tpl_vars['customization']->value['datas'][@constant('_CUSTOMIZE_FILE_')]) > 0) {?>
Instead of isset, smarty uses a check against null value (!==null). Contrary to isset, this check raise the above mentionned notice. I have tested this on a prestashop 1.6 install (version 1.6.1.18), and the problem is not present. The compiled template is using a proper isset test :
<?php if (isset($_smarty_tpl->tpl_vars['customization']->value['datas'][@constant('_CUSTOMIZE_FILE_')])&&count($_smarty_tpl->tpl_vars['customization']->value['datas'][@constant('_CUSTOMIZE_FILE_')])>0) {?>
The text was updated successfully, but these errors were encountered: