Elasticsuite: Notice: Trying to access array offset on value of type int - Layer Navigation - Swatches

Created on 27 Aug 2020  路  10Comments  路  Source: Smile-SA/elasticsuite

Preconditions


PHP7.4 & Mysql 8


Magento Version : 2.4.0


ElasticSuite Version: 2.10.0


Environment: Production mode

Steps to reproduce

  1. Configure a product attribute of type "Visual Swatch"
  2. Add labels, one label should start with a space
  3. Make the attribute filterable and set it to show up in layer navigation
  4. Create products with the values setup on the created attribute
  5. Navigate to Catalog Product Listing page

Expected result

1.The layer navigation should be shown and work properly

Actual result

  1. In production mode the layer navigation block is not rendered at all
  2. In production mode the following row is written in logs:

==> var/log/system.log <==
[2020-08-27 10:19:01] main.CRITICAL: Notice: Trying to access array offset on value of type int in /var/www/html/releases/62/vendor/smile/elasticsuite/src/module-elasticsuite-swatches/Block/Navigation/Renderer/Swatches/RenderLayered.php on line 70 [] []

  1. In developer mode, the execution is stoped with the following error trace
    image
bug

Most helpful comment

I have the same issue. I solved it by adding this check for now

        foreach (array_merge(array_flip($sortingArr), $attributeOptions) as $item) {
           if(is_array($item)) {
            $attributeOptionsSort[$item['id']] = $item;
           }
        }

But i don't think this is the most clean solution.

I tested it with the following specs:

  • php 7.4
  • elasticsearch 6.8.0
  • M2.4
  • environment production

This is what $item returns:

2020-09-24T08:09:11+00:00 INFO (6): array (
  'label' => 'XS',
  'link' => 'https://*********************/dames/kleding.html?clothing_size=XS',
  'custom_style' => '',
  'id' => '40',
)
2020-09-24T08:09:11+00:00 INFO (6): array (
  'label' => 'M',
  'link' => 'https://*********************dames/kleding.html?clothing_size=M',
  'custom_style' => '',
  'id' => '42',
)
2020-09-24T08:09:11+00:00 INFO (6): 5
2020-09-24T08:09:11+00:00 INFO (6): 6
2020-09-24T08:09:11+00:00 INFO (6): 7
2020-09-24T08:09:11+00:00 INFO (6): 8
2020-09-24T08:09:11+00:00 INFO (6): 9
2020-09-24T08:09:11+00:00 INFO (6): 10
2020-09-24T08:09:11+00:00 INFO (6): 11
2020-09-24T08:09:11+00:00 INFO (6): array (
  'label' => '32',
  'link' => 'https://*********************/dames/kleding.html?clothing_size=32',
  'custom_style' => '',
  'id' => '45',
)
2020-09-24T08:09:11+00:00 INFO (6): array (
  'label' => '34',
  'link' => 'https://*********************/dames/kleding.html?clothing_size=34',
  'custom_style' => '',
  'id' => '46',
)

All 10 comments

I have the same issue. I solved it by adding this check for now

        foreach (array_merge(array_flip($sortingArr), $attributeOptions) as $item) {
           if(is_array($item)) {
            $attributeOptionsSort[$item['id']] = $item;
           }
        }

But i don't think this is the most clean solution.

I tested it with the following specs:

  • php 7.4
  • elasticsearch 6.8.0
  • M2.4
  • environment production

This is what $item returns:

2020-09-24T08:09:11+00:00 INFO (6): array (
  'label' => 'XS',
  'link' => 'https://*********************/dames/kleding.html?clothing_size=XS',
  'custom_style' => '',
  'id' => '40',
)
2020-09-24T08:09:11+00:00 INFO (6): array (
  'label' => 'M',
  'link' => 'https://*********************dames/kleding.html?clothing_size=M',
  'custom_style' => '',
  'id' => '42',
)
2020-09-24T08:09:11+00:00 INFO (6): 5
2020-09-24T08:09:11+00:00 INFO (6): 6
2020-09-24T08:09:11+00:00 INFO (6): 7
2020-09-24T08:09:11+00:00 INFO (6): 8
2020-09-24T08:09:11+00:00 INFO (6): 9
2020-09-24T08:09:11+00:00 INFO (6): 10
2020-09-24T08:09:11+00:00 INFO (6): 11
2020-09-24T08:09:11+00:00 INFO (6): array (
  'label' => '32',
  'link' => 'https://*********************/dames/kleding.html?clothing_size=32',
  'custom_style' => '',
  'id' => '45',
)
2020-09-24T08:09:11+00:00 INFO (6): array (
  'label' => '34',
  'link' => 'https://*********************/dames/kleding.html?clothing_size=34',
  'custom_style' => '',
  'id' => '46',
)

Hi @leonhelmus
Thanks for your help, I'll check it out.

Best regards

Hi @leonhelmus

I had the same issue and with your check it was working.

Hi @leonhelmus
Thanks for your help, I'll check it out.

Best regards

Hi @vahonc , do you have any update for this bug, I'm facing this issue and hope that we will have update for it soon.

Thanks

Hello @justin-spotire,

Unfortunately, so far I haven't been able to reproduce this test case. Seems previous versions of PHP may have been less strict on such mistakes and silently swallowed the error / notice while 7.4 does not do this anymore. But you can try the solution that was suggested by @leonhelmus and which I a little bit updated on my own, and give us your feedback if it helped you.

foreach (array_merge(array_flip($sortingArr), $attributeOptions) as $item) {
     if(isset($item) && is_array($item)) {
         $attributeOptionsSort[$item['id']] = $item;
     }
 }

I will add the official MR a little bit later.

Best regards,

@vahonc yes, it probably has something to do with strict typing. I have seen those issues a lot in 2.4.1.

I've the same problem with Magento 2.4.1 and Php 7.4

Hello @sedax90,

Have you tried the solution from my last comment?

Best regards,

@vahonc your solution is working fine, I think we need a patch with this code

@rbayet do you have some estimate when this fix will be released? Is there something we may help you with?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

emirajbbd picture emirajbbd  路  3Comments

sdasun picture sdasun  路  4Comments

shamoon picture shamoon  路  3Comments

wouter-toppy picture wouter-toppy  路  4Comments

JonathanBBD picture JonathanBBD  路  3Comments