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.
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | 1066326-product_restrict_by_instance-11.patch | 4.74 KB | pcambra |
| #5 | 1066326-product_restrict_by_instance-5.patch | 4.74 KB | pcambra |
| #4 | 1066326-product_restrict_by_instance-4.patch | 1.03 KB | pcambra |
Comments
Comment #1
rszrama commentedReviewing 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.
Comment #2
rszrama commentedAnd tagging to make sure we review this in a month.
Comment #3
jeffschulersubscribing, to catch this when it flies.
D7/D8 critical bugs and critical tasks are both < 15, though major tasks are > 100.
Comment #4
pcambraOk 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.
Comment #5
pcambraI totally had forgotten about the test cases, here's the right patch with those included :)
Comment #6
pcambraThe patch has just been committed to D7 core: http://drupalcode.org/project/drupal.git/commit/a5fd8c9
Comment #7
rszrama commentedOk, great. Is there any adverse affect on Commerce if we commit your patch before we get a new point release of Drupal 7?
Comment #8
pcambraYup, 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).
Comment #10
pcambraYeah testbot, those two :)I guess we need to update that to drupal 7.9?Comment #11
pcambraNew patch with optional $instance so it's safer and doesn't break the tests.
Comment #12
rszrama commentedWonderful. Works as expected on Drupal 7.8 and 7.9. It's about time, eh? : )
Comment #13
chriscalip commentedHappy day. good job guys