Since the update to 1.13, all my product reference fields are empty on the edit form, although the product display has assigned products.

Comments

handkerchief created an issue. See original summary.

handkerchief’s picture

Title: can't see the products » All product reference fields are empty
Related issues: +#2704341: Limit to 10 choices of products (select list)
StatusFileSize
new13.35 KB

Ok the problem is this: https://www.drupal.org/node/2704341

I use the chose module (https://www.drupal.org/project/chosen) so a huge number of items is not a problem for me. So i set this field settings:

List Limit

But this doesn't work. Now i must hack the commerce module.

This code does not work correctly in the file sites/all/modules/commerce/modules/product_reference/commerce_product_reference.module:

  if (!empty($field['settings']['options_list_limit'])) {
    $limit = (int) $field['settings']['options_list_limit'];
  }
  else {
    $limit = 10;
  }

It should be:

  if (isset($field['settings']['options_list_limit'])) {
    if (!empty($field['settings']['options_list_limit'])) {
      $limit = (int) $field['settings']['options_list_limit'];
    }
    else {
      $limit = NULL;
    }
  }
  else {
    $limit = 10;
  }
blasthaus’s picture

Priority: Minor » Normal

Same issue, however in our case, product_reference fields were defined in code (not UI) and therefore 'options_list_limit' was actually NULL, so to catch this case as well, use array_key_exists() instead:

  // Look for an options list limit in the field settings.
  if (array_key_exists('options_list_limit', $field['settings'])) {
    $limit = !empty($field['settings']['options_list_limit']) ? (int) $field['settings']['options_list_limit'] : NULL;
  }
  else {
    $limit = 10;
  }
blasthaus’s picture

Here's a patch to that effect.

blasthaus’s picture

Status: Active » Needs review
jkellendonk’s picture

I had the same issue. Instead of modifying code, my solution was to set the option list limit set for the product reference on my display nodes to 99999999. All products are showing up again.

Note: I had to go back and fix a few product display nodes because when I intended to edit only another part of the node, saving the node caused the wrong product because the existing product was not in the option list from this issue. (It changed to the first product in the select list.)

friera’s picture

#4 works for me. Thank you

hansfn’s picture

Status: Needs review » Reviewed & tested by the community

#4 works for me too. Thx!

andyg5000’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new924 bytes

Based on the form label and the fact that we can simplify this, here's a new patch.

andyg5000’s picture

Related #2096361: Move Product Match functions from db_select to EntityFieldQuery

Need to make sure we don't go backwards. However, that issue introduced a bug in my opinion because existing sites are expecting the full list to be loaded. When it's not, people get angry :D

blasthaus’s picture

#9: So what's the logic behind removing the default of 10 products?

tzt20’s picture

StatusFileSize
new48.36 KB

I can confirm that the solution in #6 works without the need to apply a patch.

Steps to solve this:
-Select edit on your Product Reference field

If you're using "Unlimited" as your "Number of Values" option, you'll need to update the "Options list limit," so enter a larger value. I used 9999.

See attached screenshot.

Updated:
Users expecting to see all of their product selections should now see them (up to 9999 of course). This is especially useful for those clients who are expecting to see all of their products rather than be limited to the 10 product options.

andyg5000’s picture

Clients who have sites pre-dating the limit of 10 commit might expect for this list to not be limited. When it is, they can't select the products that they're expecting to be able to select.

matthiasm11’s picture

I can confirm the patch from #9 works. It doesn't make sense to limit a select list in the UI to the 10 first products, a shop administrator should be able to reference the product he/she wants to the current line item.

bpopp’s picture

The patch in #9 worked for me!

matthiasm11’s picture

Status: Needs review » Reviewed & tested by the community
rszrama’s picture

Status: Reviewed & tested by the community » Closed (duplicate)