I have a product where there are many colors available, but each product will only have one color. Currently, when you put up a new product, the admin has to deselect more than 20 checkboxes, which is rather cumbersome.

I want to stop the uc_attributes from selecting all of the Options on the ../edit/options page. I would like to do this correctly and use the hook_form_alter in a custom module--and avoid versioning problems in the future.

Can someone please help me out with the below code? I just need to get the if statement correct and this should work.


<?php

function mb_custom_form_alter(&$form, &$form_state, $form_id) {

	if ($form_id == 'uc_object_attributes_form') { /** THIS LINE NEEDS TO BE CORRECTED **/
  		$form["#submit"][] = 'mb_attribute_form_submit';
	}

}


function mb_attribute_form_submit($form, &$form_state) {
    if($form_state['values']['view'] == 'add') {
        $attribute = uc_attribute_load($aid);
        foreach ($attribute->options as $option) {
            db_query("DELETE FROM {uc_product_options} WHERE nid = %d AND oid = %d", $form_state['values']['id'], $option->oid);
        }
    }
}

Comments

rszrama’s picture

If I'm not mistaken, this may have been fixed already w/ a checkall box. : ?

colinjallen’s picture

It would be great if there was an preference pane to have Options either all checked or have none selected. I'm working on the lastest version of UC Attributes(6.x-2.0-rc3), and that's not the case.

Andy_Lowe’s picture

Status: Active » Closed (fixed)

cleaning old / stale issues out of the queue

drifter’s picture

Version: 6.x-2.0-rc3 » 6.x-2.2
Status: Closed (fixed) » Active

This is still active I'm afraid: having about 20 color options out of which only 2 or 3 will apply for a single product. Having to deselect all checkboxes is cumbersome. There is no 'check/uncheck all' option. Running Ubercart 2.2.

TR’s picture

@drifter: On the options page at node/%/edit/options you'll see a checkbox in the header of the first column. That checkbox can be used to select or deselect all the options.

drifter’s picture

Status: Active » Closed (fixed)

My bad, I was also using uc_option_image module, which has a bug that hides the 'select all' checkbox as well as the drag handles.