Currently, if you have access to view unpublished variations, when you view an Add to Cart form that either lists variations or presents attribute options, these lists will always include any unpublished variations.
As a feature, this is interesting because it lets you include variations that the general public may not be able to purchase but would be purchaseable by an admin. However, there's no indication in the UI that some are published vs. unpublished (the privileged user just has to know), and there's no way to disable the functionality if you don't want it. This ticket is about solving that latter use case.
I'd like to see the "Product variation title" and "Product variation attributes" widgets have an additional option added, a checkbox that reads:
[ ] Filter options for unpublished variations out of select lists.
Edit: See suggestion in #5 to better use:
[ ] Show unpublished variations (unchecked by default)
I don't normally like toggling a checkbox on to disable something, but I think regarding this as enabling a filter is alright. This simplifies the upgrade path, as the absence of a value would be treated as the disabling of the filter.
Issue fork commerce-3572669
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #4
rhovland+1 on this being needed.
I ran into the consequences of this change when I updated from 8.x-2.x to 3.x
#3167716: Unpublished variations are not properly checked for access
In my case I was already using a variation filter subscriber so I filtered out unpublished variations there as a temp fix but this needs to be added for everyone else that is using stock commerce without custom code.
Comment #5
anybodyI agree this makes a lot of sense for solving #3167716: Unpublished variations are not properly checked for access
Still
is not the right way around in Drupal. Drupal follows a security-by-design concept so filtering out unpublished variations should definitely be the default!
Show unpublished variations (unchecked by default) is the correct implementation in Drupal IMHO.
Furthermore, it needs a description to tell details and who can see these unpublished variations then!
Comment #8
tbkot commentedComment #9
zaporylieComment #10
zaporylieAFAIK this one is "Needs review". I rerolled the MR but haven't review it myself.
Comment #11
jsacksick commentedThanks for working on this. I reviewed MR !657, and I'd like a few changes before it can go in:
ProductVariationStorage::loadEnabled()already filters variations byviewaccess, so customers never see unpublished variations today. The only users who see them are users who are allowed to view unpublished variations (e.g. administrators). Sinceshow_unpublisheddefaults toFALSE, existing sites would silently stop showing them to those users after updating. Could we add an update hook that setsshow_unpublished: TRUEon existing form displays using these widgets, so the current behavior is preserved and the filtering is opt-in for existing sites?hide_singleout of this MR. Moving it toProductVariationWidgetBaseexposes the setting on every widget extending the base class (including contrib/custom ones that don't implement it), and changes the config schema. That's a separate change; if we want it, let's open a follow-up issue.Also, the issue mentions that there's no visual cue distinguishing unpublished variations when they are shown. That isn't addressed here. Fine to handle in a follow-up, but worth noting.