diff --git a/ubercart/uc_attribute/uc_attribute.admin.inc b/ubercart/uc_attribute/uc_attribute.admin.inc index 73745ca..f1b96f4 100644 --- a/ubercart/uc_attribute/uc_attribute.admin.inc +++ b/ubercart/uc_attribute/uc_attribute.admin.inc @@ -1034,9 +1034,21 @@ function uc_object_options_form_submit($form, &$form_state) { */ function uc_product_adjustments_form($form_state, $node) { drupal_set_title(check_plain($node->title)); - $nid = $node->nid; + // Check the number of option combinations before continuing, and abort if + // there are too many. + $combinations = uc_product_adjustments_form_combinations_check($node); + $max_combinations = 1000; + if($combinations > $max_combinations) { + $form['description'] = array( + '#type' => 'markup', + '#value' => t('There are !count possible combinations of attribute options for this product. SKU alternates cannot be set for products with more than !max combinations.', array('!count' => $combinations, '!max' => $max_combinations)), + ); + return $form; + } + //Populate table and such. + $nid = $node->nid; $model = $node->model; $query_select = "SELECT DISTINCT"; $query_from = " FROM"; @@ -1162,6 +1174,31 @@ function uc_product_adjustments_form($form_state, $node) { } /** + * Determines whether a product has too many potential combinations of attribute + * options before exposing them on the adjustments form. + * + * @param $node + * A product node object to check. + * @return An integer value representing the number of combinations. + * + * @see uc_product_adjustments_form() + */ +function uc_product_adjustments_form_combinations_check($node) { + $combinations = 1; + foreach ($node->attributes AS $aid => $attribute) { + // Ignore attributes with checkbox displays. + if ($attribute->display == 3) { + continue; + } + // Only count attributes that provide at least one option. + if ($count_options = count($attribute->options)) { + $combinations = $combinations * $count_options; + } + } + return $combinations; +} + +/** * @see uc_product_adjustments_form() */ function uc_product_adjustments_form_submit($form, &$form_state) {