The latest release of Ubercart had checkbox attributes. This (comprehensive) patch now allows the shop owner to select by default none, one, some or all of the available options. More or less the last part of integrating the checkbox attributes in Ubercart.

Still to do:
Testing! Works flawless (as far as I know) with normal products but didn't test for classes or product kits. Did however try to change the existing code so it should be working.
The table in the node/x/edit/attributes states the default attribute, but now merely N/A. Should be easily changed to show the default option(s), but since we have a new "label" there, space is getting a little cramped and it could be omitted altogether imho.

Changes:
This patch includes database changes and updates. The default options are dropped from the attribute tables and included in the option tables. Upgrade queries included.

Hope we can enjoy checkbox default options support in core soon!

Best regards

Mark

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

splash112’s picture

Status: Active » Needs review
splash112’s picture

Forgot to check the new code with coder.
Please find a cleaned up version of the patch in the attachments.

Schoonzie’s picture

Will this be included in a future release of Ubercart (ie 6.x-2.3)?

I'm just wary of changing the database structure now if this won't make it into a future release.

splash112’s picture

So far: no

TR’s picture

It sounds like a reasonable feature, but I need someone other than the original poster to actually install the patch and test it out in various circumstances then report back here before it can possibly be committed. So if this is something you're interested in, I encourage you to help out.

splash112’s picture

Title: Checkboxes for attributes, now with default boxes checked or unchecked » New feature: Attribute options, default checked none, one or many (essentially for check boxes)

Hi TR,

Thanks for looking into it.
Testers please! Module will make database changes, but when rolled back, site will continue as before (deleting data is commented out).

While patching anyway, you might want to have a look at:
http://drupal.org/node/590918

Thanks
Mark

muddie’s picture

I would love to get this working but I have a newer version of ubercart than the one this patches.
Any chance someone who knows how could update the patch?
Thanks.

cYu’s picture

I'm subscribing because if this does go in, it will break some of the code in uc_aac which expects default_option to be a string and not an array.

Berdir’s picture

I can confirm that this works as expected, attaching a slightly updated patch (removed some commented out stuff).

Note: Configuring default values for attribute type "checkboxes" is currently broken or to say more exactly, simply not implemented:

'#default_value' => ($attr_type == "checkboxes" ? array() : $attribute->default_option),

If the attribute type is checkboxes, the default value is always an empty array. It would also be possible to fix this *bug* by just changing that line, without breaking the schema and API and introducing new features. Downside is that it is only possible to define a single default value for checkboxes attributes, but that's already better than the current broken code.

There is an additional issue that when an attribute is required, the default option is removed. This is removed in the original patch too and I'm also removing that in the bugfix patch. Imho, it would be better if it would be possible to allow not selecting a default value.

Attaching the updated original patch (update function to remove fields still disabled) and the bugfix only patch.

SeanA’s picture

Title: New feature: Attribute options, default checked none, one or many (essentially for check boxes) » Attribute options, default checked none, one or many (essential for check boxes)

If we're going to have attribute checboxes, there really needs to be a way to set them as checked or unchecked by default. Patch in #9 works properly for setting default values. Patch applies cleanly and works on Ubercart 2.4. Thanks!

evancooperman’s picture

I also just applied the patch. Unfortunately, for those who already have many attributes created this patch will force a reinstallation of the uc_attribute module which will wipe out all your attributes - beware!

I will try to post the code to do the database migration so you don't actually have to uninstall/reinstall the module.

Thanks for the patch, other than the issue above it works great, thanks for doing this!

evancooperman’s picture

Oops, didn't run the update part of the install script, my mistake! If this is run all should be fine.

daamy’s picture

Thank you Berdir for the patch

anacronaut’s picture

Component: Code » Module integration
Category: feature » bug

Thanks for the patch Berdir (post #9)!

And thanks also for the tip, cYu (post #8). Patch works fine as long as uc_aac is not enabled.

Hope to see a patch for that soon.

TR’s picture

Component: Module integration » Code
Category: bug » feature

Restoring tags.

Status: Needs review » Needs work

The last submitted patch, default_checkboxes_fix_only.patch, failed testing.

luis_san’s picture

Status: Needs work » Needs review

#2: default_checkboxes_2.patch queued for re-testing.

TR’s picture

Title: Attribute options, default checked none, one or many (essential for check boxes) » Attribute options, default checked none, one or many
Status: Needs review » Needs work

I don't know what the point is of requesting a re-test. The patch in #9 failed two years ago and no-one has fixed it since, so there's absolutely no way that it is going to magically pass if you try the test again.

If you want to help get this feature implemented, you can re-work the patch to make it pass, to fix the problems raised in #11, and make it apply to the current version of Ubercart. You can and should do all your testing locally before you submit a new patch. Any new patch should also include new test cases - uc_attributes already has extensive test cases, and will need new test cases for the new features.

Alan D.’s picture

Version: 6.x-2.x-dev » 7.x-3.x-dev

Considering the age, I think D7 is the best place to start again on this :(

After 10 or so "works as designed" related issues, it is nice to see this being considered :)

TR’s picture

Version: 7.x-3.x-dev » 8.x-4.x-dev
Component: Code » Product attributes
Issue summary: View changes
Related issues: +#2953584: default_option is always null

This is still a valid feature request, but unless someone puts in the work this is not going to be changed in D7 because of the data loss issue when changing the data model from a single valued default to an array default.

The intermediate step proposed in #9, to let checkbox attributes use a single valued default, can be done without impact. Perhaps another way to go is to use a bitmap rather than an array to set multi-valued defaults. That would not require a data model change and could be backwards compatible with a suitable update function.

Also not addressed here is the question of what to do if an attribute is changed from a checkbox with many default options to a select box where only one default is permitted.

Regardless, moving this to D8 as that is where new features should go at this point.

It will still require community participation to get this implemented.