Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notice: Undefined offset 0 when generating PDF invoice for order with customized data #15358

Closed
rvalery opened this issue Sep 2, 2019 · 6 comments
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

Comments

@rvalery
Copy link

rvalery commented Sep 2, 2019

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 :

  1. In front-office : select the customizable mug example product, customize the text, add it to the cart

Capture d’écran 2019-09-02 à 13 52 34

  1. Proceed with order.

Capture d’écran 2019-09-02 à 13 48 02

  1. In Back-office : go to order page, and set the newly created order as delivered.

Capture d’écran 2019-09-02 à 13 48 38

  1. Go to invoice page, generate invoices by date.

Capture d’écran 2019-09-02 à 13 49 06

  1. Notice is displayed if in debug mode (if not in debug mode, invoice is generated properly, and notice is only logged into php error log).

Capture d’écran 2019-09-02 à 13 43 53

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) {?>

@khouloudbelguith
Copy link
Contributor

khouloudbelguith commented Sep 2, 2019

Hi @rvalery,

Thanks for your report.
I manage to reproduce the issue with PS1.7.5.2 / PS1.7.6.0 & PS1.7.6.1.
image
Mode debug should be enabled
I’ll add this to the debug roadmap so that it’s fixed. If you have already fixed it on your end or if you think you can do it, please do send us a pull request!
Thanks!

@khouloudbelguith khouloudbelguith added 1.7.5.2 Affects versions 1.7.6.0 Affects versions 1.7.6.1 Affects versions Customized Product type: issue about customized products Invoices Label: Which BO under menu is concerned Ready Status: Issue is ready to be worked on BO Category: Back Office labels Sep 2, 2019
@rvalery
Copy link
Author

rvalery commented Sep 2, 2019

Thanks for your reply.
Unfortunately I have not yet found a way to correct this. I don't know if the problem is from Smarty itself (changing the isset into "!==null" check), or if it comes from a Prestashop configuration, or something in the way Prestashop uses smarty to compile templates. I will try to dig further in the code if I can find the time this week.

@wxiaoguang
Copy link

It is a smarty bug, please upgrade the smarty to the latest one:

https://github.com/smarty-php/smarty/blob/master/CHANGELOG.md

[3.1.35] - 2020-04-14

@khouloudbelguith
Copy link
Contributor

Hi @rvalery,

It is fixed in the 1.7.7.x branch.
I attached a screen record
https://drive.google.com/file/d/1EYXmI4-AMWXEzU02LQamVqJIn6AVuBMi/view?usp=sharing
Your ticket is a duplicate of #18837
So, I close it.
Thanks !

@prestashop-issue-bot prestashop-issue-bot bot removed the Ready Status: Issue is ready to be worked on label Aug 12, 2020
@khouloudbelguith
Copy link
Contributor

Duplicate of #18837

@khouloudbelguith khouloudbelguith marked this as a duplicate of #18837 Aug 12, 2020
@khouloudbelguith khouloudbelguith added the Duplicate Resolution: issue closed because already reported label Aug 12, 2020
@rvalery
Copy link
Author

rvalery commented Aug 12, 2020

That is a good news, I will update to 1.7.7.x to test it.
Thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

3 participants