Hi,

I'm receiving the following errors when clicking the "Products" tab on a product display node:

Notice: Undefined index: nl in commerce_pdm_display_node_products_form() (line 106 of /Volumes/workspace/sandbox/drupal/commerce_kickstart/sites/all/modules/commerce_product_display_manager/commerce_pdm.module).
Warning: Invalid argument supplied for foreach() in commerce_pdm_display_node_products_form() (line 106 of /Volumes/workspace/sandbox/drupal/commerce_kickstart/sites/all/modules/commerce_product_display_manager/commerce_pdm.module).

Setup to reproduce:
Product entities without language assigned to them (und) that are being referenced by a product display node that does have a language assigned to it.
Screenshot of PDM setup to make it more clear: http://grab.by/ay8I

This actually results in *all* products being shown on the "Products" tab, as can be seen here: http://grab.by/ay8J

I had a quick look at the code to try to fix this myself, but I can't currently focus on it :) Might have a look at it later if noone picks it up.

On a totally unrelated note: perhaps commerce_pdm_display_node_products_form() should be in a dedicated .inc file, to avoid this page-specific code to be loaded at the time...

Sven

CommentFileSizeAuthor
#9 pdm_lang_fix-1220286-9.patch645 bytesdenes.szabo

Comments

Stalski’s picture

1/ the notice I can't reproduce and I have the same set-up
Strange I don't see this notice.
I must say that part is indeed something strange with that language check there. I'll investigate it.

- Edit - I don't see notices, but I do see my products twice , doubling the list. Guess issues are related, but don't see how yet.

2/ the form I will move to another file
This is already pushed.

greysun’s picture

Notice: Undefined index: de in commerce_pdm_display_node_products_form() (Zeile 107 von /mnt/webc/42/58/51167658/htdocs/d/sites/all/modules/commerce_product_display_manager/commerce_pdm.module).
Warning: Invalid argument supplied for foreach() in commerce_pdm_display_node_products_form() (Zeile 107 von /mnt/webc/42/58/51167658/htdocs/d/sites/all/modules/commerce_product_display_manager/commerce_pdm.module).

Occuring on alpha3 and dev version...

Stalski’s picture

We'll look into this asap. I have some other contribs that need to be released first and then my attention will go to the commerce project again.

amfis’s picture

Found the problem:

1. product reference field does not utilize correct language
2. need to check for correct language for current field not node prior iterating

Example:
- reference: $node->product_reference[und][product_id]
- language: $node->language = en

Might this issue be 'References' or 'i18n' module related.

Steps to reproduce:

- enable content translation
- enable i18n module
- create new content type and assign product reference field
- create a new product and assign referenced item to it
- use devel to see what's inside node

Quick fix: commerce_pdm.module (108 line)

    $ref_language = array_keys($node->{$reference_field_name});
    if ($ref_language[0] == $node_language) {
      foreach($node->{$reference_field_name}[$node_language] as $product_field_value) {
        $conditions->condition('cp.product_id', $product_field_value['product_id']);
      }
    } else {
      foreach($node->{$reference_field_name}['und'] as $product_field_value) {
        $conditions->condition('cp.product_id', $product_field_value['product_id']);
      }
    }
amfis’s picture

And yeas.. at line 320 (or so) you need another same fix, plus, there is a typo in variable name $node_language.

Babalu’s picture

subscribing. same error here. only when i view the product list at a node

stef.andries’s picture

Bump.

I have the same issue, but the quick patch works nicely.
Any idea on a timing for a permanent fix ?
Thanks for the nice work so far !

Stef

funana’s picture

Same issue here. Could you provide a patch for this?

denes.szabo’s picture

StatusFileSize
new645 bytes

I attached my fix for this issue.
As I see, we should never use this type of array access: $node->{$reference_field_name}['und'], because of what if I have other language than 'und' (which actually should be LANGUAGE_NONE constant).

My fix uses field_get_items() to solve this problem.

denes.szabo’s picture

Status: Active » Needs review

Sorry, I forgot set the status…

itamair’s picture

It still doesn't work for me. May be is my fault, but actually I don't think so.
I have a content type that is Magazine, that will be the Product Display Type.
When I create one, from scratch its language is specific (it, in my case).

When I try to attach a Product with the Product Display Manager UI to such a yet existing magazine, it doesn't work as it seems to expect und language content ... so no product is referenced to that display.
The Product Display Manager works well when I attach the product to a new Magazine (new node created on the fly). But in this case the new magazine is created with an 'und' language parameter, bypassing the locale settings of my site.

I think it is really a matter of language management, that #9 patch didn't fix for me ...

stan turyn’s picture

Patch #9 fixed it for me.

finex’s picture

Confirmed: patch #9 works fine

jax’s picture

Status: Needs review » Reviewed & tested by the community

Works.

atlea’s picture

Another vote for #9.

brunorios1’s picture

#9 works.

pityu73’s picture

#9 It works, thank you.

itamair’s picture

yes, #9 works for me too.
I had just a problem with the Display Manager, that seems won't work properly (just gives any result …) when I have more than one product type defined and referenced to some of my content types (product display).
I just opened another issue about this, here: Display Manager doesn't work with more then one Product Types

funana’s picture

#9 does the job.

Anonymous’s picture

Any chance we could get this committed @Stalski?

Cheers

dimitriseng’s picture

#9 works for me as well, would be great to get this commited... Thanks!

jawi’s picture

#9 solved problems for me!
Patch tested and working fine.

bogeyman’s picture

Hi, there is a module named Commerce Auto Product Display which does similar thing like this module. You might want to use it because this module is no longer maintained.

netsensei’s picture

Status: Reviewed & tested by the community » Fixed

Patch in #9 fixes this issue. Committed this to 7.x-1.x-dev. Thanks for contributing!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.