When you have > 1 product type, you can restrict the product types in the product reference module attached to a display so only the products belonging to that product types are selectable. This feature is only working for the autocomplete widget of product reference module but not for the options/checkboxes.
The reason is that commerce_product_reference_options_list (hook_options_list) lack of instance context and therefore there is no way to filter for the settings of a field instance on a particular bundle.
I've opened an issue for drupal core to see if it makes sense to have $instance in hook_options_list #1066274: hook_options_list should allow to pass the instance of a field but meanwhile we need a workaround for this.

Comments

rszrama’s picture

Status: Active » Postponed

Reviewing this, pcambra's issue is RTBC and just awaiting core maintenance to catch-up to the issue queue. I don't see any reason to work in some form altering based work around for this, as there's a valid work around in the Product Reference module already - use the autocomplete text field in instances where it's really necessary for this to be restricted. It's less than ideal for sure, but as soon as #1066274: hook_options_list should allow to pass the instance of a field gets fixed, we can fix this in Product Reference, too. I'm more than happy to make that change at any time.

Marking postponed until the core issue is fixed.

rszrama’s picture

Issue tags: +dcsprint6

And tagging to make sure we review this in a month.

jeffschuler’s picture

subscribing, to catch this when it flies.

D7/D8 critical bugs and critical tasks are both < 15, though major tasks are > 100.

pcambra’s picture

Ok core patch has been committed into D8 and it seems that soon will be in D7, attaching a patch to get this in commerce as soon as the core patch gets into a D7 release.

pcambra’s picture

I totally had forgotten about the test cases, here's the right patch with those included :)

pcambra’s picture

Status: Postponed » Needs review

The patch has just been committed to D7 core: http://drupalcode.org/project/drupal.git/commit/a5fd8c9

rszrama’s picture

Ok, great. Is there any adverse affect on Commerce if we commit your patch before we get a new point release of Drupal 7?

pcambra’s picture

Yup, rolling this without the core patch will produce warnings on product display edit form, I think that committing this next week (when 7.9 version is supposed to get released) is the safer option

Pasting here the warnings, just in case someone get those in the future b/c they haven't updated core.

Warning: Missing argument 2 for commerce_product_reference_options_list() in commerce_product_reference_options_list() (line 602 of /sites/all/modules/commerce/modules/product_reference/commerce_product_reference.module).
Notice: Undefined variable: instance in commerce_product_reference_options_list() (line 606 of /sites/all/modules/commerce/modules/product_reference/commerce_product_reference.module).

Status: Needs review » Needs work

The last submitted patch, 1066326-product_restrict_by_instance-5.patch, failed testing.

pcambra’s picture

Yeah testbot, those two :)

I guess we need to update that to drupal 7.9?

pcambra’s picture

Status: Needs work » Needs review
StatusFileSize
new4.74 KB

New patch with optional $instance so it's safer and doesn't break the tests.

rszrama’s picture

Status: Needs review » Fixed

Wonderful. Works as expected on Drupal 7.8 and 7.9. It's about time, eh? : )

chriscalip’s picture

Happy day. good job guys

Status: Fixed » Closed (fixed)
Issue tags: -dcsprint6

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