? 435084_200904161504+1000.patch
? 435088_200904161515+1000.patch
? 437268_200904181246+1000.patch
? 437268_200904181250+1000.patch
? uc_reports/views
Index: uc_attribute/uc_attribute.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/ubercart/uc_attribute/Attic/uc_attribute.admin.inc,v
retrieving revision 1.1.2.8
diff -u -r1.1.2.8 uc_attribute.admin.inc
--- uc_attribute/uc_attribute.admin.inc	2 Apr 2009 21:01:47 -0000	1.1.2.8
+++ uc_attribute/uc_attribute.admin.inc	18 Apr 2009 02:50:35 -0000
@@ -11,6 +11,7 @@
 function uc_attribute_admin() {
   $header = array(
     array('data' => t('Name'), 'field' => 'a.name', 'sort' => 'asc'),
+    array('data' => t('Label'), 'field' => 'a.label'),
     t('Required'),
     array('data' => t('List position'), 'field' => 'a.ordering'),
     t('Number of options'),
@@ -20,7 +21,7 @@
 
   $display_types = _uc_attribute_display_types();
 
-  $result = pager_query("SELECT a.aid, a.name, a.required, a.ordering, a.display, COUNT(ao.oid) AS options FROM {uc_attributes} AS a LEFT JOIN {uc_attribute_options} AS ao ON a.aid = ao.aid GROUP BY a.aid, a.name, a.ordering, a.required, a.display". tablesort_sql($header), 30, 0, "SELECT COUNT(aid) FROM {uc_attributes}");
+  $result = pager_query("SELECT a.aid, a.name, a.label, a.required, a.ordering, a.display, COUNT(ao.oid) AS options FROM {uc_attributes} AS a LEFT JOIN {uc_attribute_options} AS ao ON a.aid = ao.aid GROUP BY a.aid, a.name, a.ordering, a.required, a.display". tablesort_sql($header), 30, 0, "SELECT COUNT(aid) FROM {uc_attributes}");
   while ($attr = db_fetch_object($result)) {
     $ops = array(
       l(t('edit'), 'admin/store/attributes/'. $attr->aid .'/edit'),
@@ -29,6 +30,7 @@
     );
     $rows[] = array(
       check_plain($attr->name),
+      check_plain($attr->label),
       $attr->required == 1 ? t('Yes') : t('No'),
       array('data' => $attr->ordering, 'align' => 'center'),
       array('data' => $attr->options, 'align' => 'center'),
@@ -67,10 +69,16 @@
   $form['name'] = array(
     '#type' => 'textfield',
     '#title' => t('Name'),
-    '#description' => t('This name will appear to customers on product add to cart forms.'),
+    '#description' => t('This name will appear to customers on product add to cart forms unless a label is entered below.'),
     '#default_value' => $attribute->name,
     '#required' => TRUE,
   );
+  $form['label'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Label'),
+    '#description' => t("Enter a label here if you want more than one attribute displaying the same label on product add to cart forms. Use <none> if you don't want a label."),
+    '#default_value' => $attribute->label,
+  );
   $form['description'] = array(
     '#type' => 'textfield',
     '#title' => t('Help text'),
@@ -112,10 +120,10 @@
  */
 function uc_attribute_form_submit($form, &$form_state) {
   if (!empty($form_state['values']['aid'])) {
-    db_query("UPDATE {uc_attributes} SET name = '%s', ordering = %d, required = %d, display = %d, description = '%s' WHERE aid = %d", $form_state['values']['name'], $form_state['values']['ordering'], $form_state['values']['required'], $form_state['values']['display'], $form_state['values']['description'], $form_state['values']['aid']);
+    db_query("UPDATE {uc_attributes} SET name = '%s', label = '%s', ordering = %d, required = %d, display = %d, description = '%s' WHERE aid = %d", $form_state['values']['name'], $form_state['values']['label'], $form_state['values']['ordering'], $form_state['values']['required'], $form_state['values']['display'], $form_state['values']['description'], $form_state['values']['aid']);
   }
   else {
-    db_query("INSERT INTO {uc_attributes} (name, ordering, required, display, description) VALUES ('%s', %d, %d, %d, '%s')", $form_state['values']['name'], $form_state['values']['ordering'], $form_state['values']['required'], $form_state['values']['display'], $form_state['values']['description']);
+    db_query("INSERT INTO {uc_attributes} (name, label, ordering, required, display, description) VALUES ('%s', '%s', %d, %d, %d, '%s')", $form_state['values']['name'], $form_state['values']['label'], $form_state['values']['ordering'], $form_state['values']['required'], $form_state['values']['display'], $form_state['values']['description']);
   }
 
   $form_state['redirect'] = 'admin/store/attributes';
@@ -447,8 +455,10 @@
   }
 
   $used_aids = array();
+  $used_labels = array();
   foreach ($attributes as $attribute) {
     $used_aids[] = $attribute->aid;
+    $used_labels[] = $attribute->label;
   }
 
   if ($view == 'overview') {
@@ -466,6 +476,11 @@
           'name' => array(
             '#value' => check_plain($attribute->name),
           ),
+          'label' => array(
+            '#type' => 'textfield',
+            '#default_value' => ($attribute->label == '<none>' ? $attribute->label : check_plain($attribute->label)),
+            '#size' => 6,
+          ),
           'option' => array(
             '#value' => $option ? (check_plain($option->name) .' ('. uc_currency_format($option->price) .')' ) : t('n/a'),
           ),
@@ -496,9 +511,9 @@
   elseif ($view == 'add') {
     // Get list of attributes not already assigned to this node or class.
     $unused_attributes = array();
-    $result = db_query("SELECT a.aid, a.name FROM {uc_attributes} AS a LEFT JOIN {uc_attribute_options} AS ao ON a.aid = ao.aid GROUP BY a.aid, a.name ORDER BY a.name");
+    $result = db_query("SELECT a.aid, a.name, a.label FROM {uc_attributes} AS a LEFT JOIN {uc_attribute_options} AS ao ON a.aid = ao.aid GROUP BY a.aid, a.name ORDER BY a.name");
     while ($attribute = db_fetch_object($result)) {
-      if (!in_array($attribute->aid, $used_aids)) {
+      if (!in_array($attribute->aid, $used_aids) && !in_array($attribute->label, $used_labels)) {
         $unused_attributes[$attribute->aid] = $attribute->name;
       }
     }
@@ -543,13 +558,14 @@
  */
 function theme_uc_object_attributes_form($form) {
   if ($form['view']['#value'] == 'overview') {
-    $header = array(t('Remove'), t('Name'), t('Default'), t('Required'), t('List position'), t('Display'));
+    $header = array(t('Remove'), t('Name'), t('Label'), t('Default'), t('Required'), t('List position'), t('Display'));
 
     if (count(element_children($form['attributes'])) > 0) {
       foreach (element_children($form['attributes']) as $aid) {
         $row = array(
           drupal_render($form['attributes'][$aid]['remove']),
           drupal_render($form['attributes'][$aid]['name']),
+          drupal_render($form['attributes'][$aid]['label']),
           drupal_render($form['attributes'][$aid]['option']),
           drupal_render($form['attributes'][$aid]['required']),
           drupal_render($form['attributes'][$aid]['ordering']),
@@ -597,7 +613,7 @@
         $remove_aids[] = $aid;
       }
       else {
-        db_query("UPDATE $attr_table SET ordering = %d, required = %d, display = %d WHERE aid = %d AND $id = $sql_type", $attribute['ordering'], $attribute['required'], $attribute['display'], $aid, $form_state['values']['id']);
+        db_query("UPDATE $attr_table SET label = '%s', ordering = %d, required = %d, display = %d WHERE aid = %d AND $id = $sql_type", $attribute['label'], $attribute['ordering'], $attribute['required'], $attribute['display'], $aid, $form_state['values']['id']);
         $changed = TRUE;
       }
     }
@@ -633,7 +649,7 @@
       else {
         $oid = 0;
       }
-      db_query("INSERT INTO $attr_table ($id, aid, ordering, default_option, required, display) SELECT $sql_type, aid, ordering, %d, required, display FROM {uc_attributes} WHERE aid = %d", $form_state['values']['id'], $oid, $aid);
+      db_queryd("INSERT INTO $attr_table ($id, aid, label, ordering, default_option, required, display) SELECT $sql_type, aid, label, ordering, %d, required, display FROM {uc_attributes} WHERE aid = %d", $form_state['values']['id'], $oid, $aid);
     }
     if (count($form_state['values']['add_attributes']) > 0) {
       if ($form_state['values']['type'] == 'product') {
Index: uc_attribute/uc_attribute.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/ubercart/uc_attribute/uc_attribute.install,v
retrieving revision 1.10.2.6
diff -u -r1.10.2.6 uc_attribute.install
--- uc_attribute/uc_attribute.install	17 Mar 2009 19:19:27 -0000	1.10.2.6
+++ uc_attribute/uc_attribute.install	18 Apr 2009 02:50:35 -0000
@@ -19,6 +19,14 @@
         'not null' => TRUE,
       ),
       'name' => array(
+        'description' => t('Name of the attribute'),
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => TRUE,
+        'default' => '',
+      ),
+      'label' => array(
+        'description' => t('Label to use when attribute is displayed'),
         'type' => 'varchar',
         'length' => 255,
         'not null' => TRUE,
@@ -131,6 +139,13 @@
         'not null' => TRUE,
         'default' => 0,
       ),
+      'label' => array(
+        'description' => t('Label to use when attribute is displayed'),
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => TRUE,
+        'default' => '',
+      ),
       'ordering' => array(
         'description' => t('Determines the list position of attributes.'),
         'type' => 'int',
@@ -232,6 +247,13 @@
         'not null' => TRUE,
         'default' => 0,
       ),
+      'label' => array(
+        'description' => t('Label to use when attribute is displayed'),
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => TRUE,
+        'default' => '',
+      ),
       'ordering' => array(
         'description' => t('Determines the list position of attributes.'),
         'type' => 'int',
@@ -631,3 +653,26 @@
   return $ret;
 }
 
+/**
+ * Add label to attributes to allow differently named attributes to show with
+ * the same label on product add to cart forms.
+ */
+function uc_attribute_update_6003() {
+  $ret = array();
+  
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      $ret[] = update_sql("ALTER TABLE {uc_attributes} ADD COLUMN label varchar(255) NOT NULL DEFAULT ''");
+      $ret[] = update_sql("ALTER TABLE {uc_class_attributes} ADD COLUMN label varchar(255) NOT NULL DEFAULT ''");
+      $ret[] = update_sql("ALTER TABLE {uc_product_attributes} ADD COLUMN label varchar(255) NOT NULL DEFAULT ''");
+      break;
+    case 'pgsql':
+      db_add_column($ret, 'uc_attributes', 'label', 'varchar(255)', array('not null' => TRUE, 'default' => "''"));
+      db_add_column($ret, 'uc_class_attributes', 'label', 'varchar(255)', array('not null' => TRUE, 'default' => "''"));
+      db_add_column($ret, 'uc_product_attributes', 'label', 'varchar(255)', array('not null' => TRUE, 'default' => "''"));
+  }
+  $ret[] = array('success' => TRUE, 'query' => 'Added label to product attributes.');
+  
+  return $ret;
+}
Index: uc_attribute/uc_attribute.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/ubercart/uc_attribute/uc_attribute.module,v
retrieving revision 1.12.2.19
diff -u -r1.12.2.19 uc_attribute.module
--- uc_attribute/uc_attribute.module	14 Apr 2009 13:51:21 -0000	1.12.2.19
+++ uc_attribute/uc_attribute.module	18 Apr 2009 02:50:37 -0000
@@ -322,7 +322,7 @@
         $output = '';
         $attributes = uc_product_get_attributes($node->nid);
         foreach ($attributes as $attribute) {
-          $output .= '<h3>'. $attribute->name .'</h3>';
+          $output .= '<h3>'. uc_attribute_get_name($attribute) .'</h3>';
           foreach ($attribute->options as $option) {
             $output .= $option->name .' ';
           }
@@ -462,7 +462,7 @@
   if ($nid) {
     switch ($type) {
       case 'product':
-        $attribute = db_fetch_object(db_query("SELECT a.aid, a.name, a.ordering AS default_ordering, a.required AS default_required, a.display AS default_display, a.description, pa.default_option, pa.required, pa.ordering, pa.display FROM {uc_attributes} AS a LEFT JOIN {uc_product_attributes} AS pa ON a.aid = pa.aid AND pa.nid = %d WHERE a.aid = %d", $nid, $attr_id));
+        $attribute = db_fetch_object(db_query("SELECT a.aid, a.name, a.label AS default_label, a.ordering AS default_ordering, a.required AS default_required, a.display AS default_display, a.description, pa.label, pa.default_option, pa.required, pa.ordering, pa.display FROM {uc_attributes} AS a LEFT JOIN {uc_product_attributes} AS pa ON a.aid = pa.aid AND pa.nid = %d WHERE a.aid = %d", $nid, $attr_id));
         $result = db_query("SELECT po.nid, po.oid, po.cost, po.price, po.weight, po.ordering, ao.name, ao.aid FROM {uc_product_options} AS po LEFT JOIN {uc_attribute_options} AS ao ON po.oid = ao.oid AND nid = %d WHERE aid = %d ORDER BY po.ordering, ao.name", $nid, $attr_id);
         break;
       case 'class':
@@ -471,7 +471,7 @@
         break;
       default:
         $attribute = db_fetch_object(db_query("SELECT * FROM {uc_attributes} WHERE aid = %d", $attr_id));
-        $result = db_query("SELECT * FROM {uc_attribute_options} WHERE aid = %d ORDER BY ordering, name", $attr_id);
+        $result = db_query("SELECT * FROM {uc_attribute_options} WHERE aid = %d ORDER BY ordering, name, label", $attr_id);
         break;
     }
     if (isset($attribute->default_ordering) && is_null($attribute->ordering)) {
@@ -483,6 +483,9 @@
     if (isset($attribute->default_display) && is_null($attribute->display)) {
       $attribute->display = $attribute->default_display;
     }
+    if (isset($attribute->default_label) && is_null($attribute->label)) {
+      $attribute->label = $attribute->default_label;
+    }
   }
   else {
     $attribute = db_fetch_object(db_query("SELECT * FROM {uc_attributes} WHERE aid = %d", $attr_id));
@@ -546,7 +549,7 @@
       // Only discrete options can affect the price of an item.
       if ($attribute->display && count($attribute->options)) {
         $options[$aid] = (array)$attribute->options[$oid];
-        $options[$aid]['attribute'] = $attribute->name;
+        $options[$aid]['attribute'] = _uc_attribute_get_name($attribute, TRUE);
       }
       else {
         $options[$aid] = array(
@@ -626,7 +629,6 @@
       }
       $form_attributes[$attribute->aid] = array(
         '#type' => $attribute->display == 1 ? 'select' : 'radios',
-        '#title' => check_plain($attribute->name),
         '#description' => check_markup($attribute->description),
         '#default_value' => $attribute->default_option,
         '#options' => $options,
@@ -636,12 +638,17 @@
     else {
       $form_attributes[$attribute->aid] = array(
         '#type' => 'textfield',
-        '#title' => $attribute->name,
         '#description' => check_markup($attribute->description),
         '#default_value' => $attribute->required == FALSE ? $attribute->options[$attribute->default_option]->name : '',
         '#required' => $attribute->required,
       );
     }
+    
+    $name = _uc_attribute_get_name($attribute);
+    if (!is_null($name)) {
+      $form_attributes[$attribute->aid]['#title'] = check_plain($name);
+    }
+    
     $form_attributes['#theme'] = 'uc_attribute_add_to_cart';
   }
   return $form_attributes;
@@ -689,3 +696,31 @@
 
   return $output;
 }
+
+/**
+ * Returns the attribute name to display. An attributes with a label set
+ * returns that label except when set to '<none>'. In this case, a NULL is
+ * returned. The $force argument forces the function to return the name
+ * property instead of label when label is set to '<none>'.
+ * 
+ * The NULL return value is typically used by forms so they know to hide the
+ * #title property of the element.
+ *  
+ * @param $attribute
+ *   Attribute object
+ * @param $force
+ *   TRUE if the function is to return the attribute name when its label is set
+ *   to '<none>'.
+ * @return
+ *   NULL if label is set to NONE and $force is FALSE. Otherwise, when $force
+ *   is FALSE, returns attribute label or, if a label isn't set, the attribute
+ *   name. When $force is TRUE, returns attribute name when label is '<none>'
+ *   otherwise the label.
+ */
+function _uc_attribute_get_name(&$attribute, $force = FALSE) {
+  if (!$force && $attribute->label == '<none>') {
+    return NULL;
+  } else {
+    return (empty($attribute->label) || ($attribute->label == '<none>' && $force) ? $attribute->name : $attribute->label);
+  }
+}
