Automatic assign of atributes

Posts: 87
Joined: 09/08/2007
Bug Finder

Yo,
I'd like same attributes to be auto assigned to every product I create. Example:
My site sells only T-shirts. Every t-shirt can have 3 different colors.
Every time I create a product node, I'd like the color attributes to be automatically enabled.

Btw, Ryan – do you get extra juice when you write hook_form_alter() Eye-wink

Posts: 5269
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

lol No, I don't get extra juice, but it's such a versatile function that it pops up everywhere. Eye-wink

Regarding your question, you can assign default attributes/options to product classes, so I'd create a new product class called t-shirt or something similar and assign it the defaults you need.

Posts: 87
Joined: 09/08/2007
Bug Finder

Thanks!

Posts: 87
Joined: 09/08/2007
Bug Finder
Posts: 5269
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

Very clever solution. Smiling I hope it works out well!

Posts: 87
Joined: 09/08/2007
Bug Finder

Warning, newbie developer! Smiling

I'm playing with doing a more generic integration (snap1). My question is how to save the new form values which should not be in the DB. should I use variable_set for EVERY option?

<?php
function uc_attribute_option_form_submit($form_id, $form_values){
  if (!isset(
$form_values['oid'])){
   
$oid = db_next_id('{uc_attribute_options}_oid');
     
db_query("INSERT INTO {uc_attribute_options} (aid, name, cost, price, weight, ordering) VALUES (%d, '%s', %f, %f, %f, %d)",
     
$form_values['aid'], $form_values['name'], $form_values['cost'], $form_values['price'], $form_values['weight'], $form_values['ordering']);
  }
  else{
   
db_query("UPDATE {uc_attribute_options} SET name = '%s', cost = %f, price = %f, weight = %f, ordering = %d WHERE aid = %d AND oid = %d",
     
$form_values['name'], $form_values['cost'], $form_values['price'], $form_values['weight'], $form_values['ordering'], $form_values['aid'], $form_values['oid']);
   
$oid = $form_values['oid'];
  }
  if (
$form_values['view']) {
   
variable_set('uc_attribute_view_' . $oid, $form_values['view']);
   
variable_set('uc_attribute_view_args_' . $oid, $form_values['view_args']);
  }
  return
'admin/store/products/attributes/'. $form_values['aid'];
}
?>

"For some reason the db_next_id returns a wrong value? (i.e. the table Cardinal, but not the OID value)" I guess this table needs an index for that no?

[edit]
Or maybe we should add two more columns to the DB for this feature?

btw, I think it's better Views per option, and not View per attribute, because like this different views can have different price.
Do you agree?

AttachmentSize
Views integration23.47 KB
Posts: 87
Joined: 09/08/2007
Bug Finder

I'm continuing with it, by changing the DB. I'll post here once I get, hopefully, something running...

Posts: 24
Joined: 11/17/2007

or did anything come of this?

Posts: 87
Joined: 09/08/2007
Bug Finder