Active
Project:
Ubercart Attribute Length
Version:
6.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
4 Sep 2011 at 17:25 UTC
Updated:
4 Sep 2011 at 17:25 UTC
Hi cYu,
Thanks again for this module, I have just patched the attributes module on my Ubercart site to allow bulk flushing of class attributes (i.e. when a change is made to the attributes of a class there is an option to bulk apply the changes to all existing products of that class). This is working successfully but the Max Length and Is Numeric options are not propagated to the products because the patched code doesn't take it into account. Do you think it would be easily possible to incorporate this into the following code (take from patch #18 here):
function uc_bulk_attributes_flush($form, &$form_state) {
$nodes = array_filter($form_state['values']['nodes']);
foreach($nodes as $nid) {
$node = node_load($nid);
// DELETE all attributes and options
db_query("DELETE FROM {uc_product_options} WHERE nid = %d", $node->nid);
db_query("DELETE FROM {uc_product_adjustments} WHERE nid = %d", $node->nid);
db_query("DELETE FROM {uc_product_attributes} WHERE nid = %d", $node->nid);
//Iterate through nodes and add class attributes and options
switch ($GLOBALS['db_type']) {
case 'mysqli':
case 'mysql':
db_query("INSERT IGNORE INTO {uc_product_attributes} (nid, aid, label, ordering, required, display, default_option) SELECT %d, aid, label, ordering, required, display, default_option FROM {uc_class_attributes} WHERE pcid = '%s'", $node->nid, $node->type);
db_query("INSERT IGNORE INTO {uc_product_options} (nid, oid, cost, price, weight, ordering) SELECT %d, oid, cost, price, weight, ordering FROM {uc_class_attribute_options} WHERE pcid = '%s'", $node->nid, $node->type);
break;
case 'pgsql':
db_query("INSERT INTO {uc_product_attributes} (nid, aid, label, ordering, required, display, default_option) SELECT %d, aid, label, ordering, required, display, default_option FROM {uc_class_attributes} WHERE pcid = '%s'", $node->nid, $node->type);
db_query("INSERT INTO {uc_product_options} (nid, oid, cost, price, weight, ordering) SELECT %d, oid, cost, price, weight, ordering FROM {uc_class_attribute_options} WHERE pcid = '%s'", $node->nid, $node->type);
break;
}
}
drupal_set_message(t("Bulk update completed successfully"));
}