9 replies [Last post]
sisko's picture
Offline
Joined: 09/17/2009
Juice: 266
Was this information Helpful?

Hello guys,

I know how to setup ubercart attributes and then activate the attributes node by node.

The problem is my client has thousands of products. There is no way anyone has physically edit all
of them node by node.

Can anyone tell me how I can setup attributes for my one class of products which will then be visible and usable immideiately
in my thousands of node?

Thanks for your time.

Andy's picture
Offline
Administrator
Joined: 08/07/2007
Juice: 1140
Product Class - Attributes

The solution is to create a product class at: admin/store/products/classes
Then add attributes to that class via the attribute tab when you click on edit for the specific product class. If you just have one product class, you still need to create a class (which will include all your products).
Cheers,
Andy

sisko's picture
Offline
Joined: 09/17/2009
Juice: 266
I don't quite understand ....

Hi Andy,

Can you please shed some more light on your steps?

As I already have a product class called "stock" with an attribute called "service" which has "lease" and "buy" as options.
Does that cover your first 2 steps ? :

Andy wrote:

The solution is to create a product class at: admin/store/products/classes
Then add attributes to that class via the attribute tab when you click on edit for the specific product class.

If my step described above is what you mean in the above quotation, then so far so good.

But I don't understand the following:

Quote:

If you just have one product class, you still need to create a class (which will include all your products).
Cheers,
Andy

It still leaves me with thousands of node that don't have the attribute exposed and usable without going through each one.

Please keep the ideas coming. I appreciate them all.
Thanks

Andy's picture
Offline
Administrator
Joined: 08/07/2007
Juice: 1140
Re: I don't quite understand ....

I'm sorry. I thought you could add products to a class after creating the class,but it doesn't really work that way. Try the patch related to this issue http://drupal.org/node/298395 and see if it works for you. Remember to back up your files and database. If that doesn't work, I have one more trick up my sleeve involving a views integration for Ubercart products, and a views module to allow mass changing, but I'm to lazy to go find the exact modules until unless this patch doesn't work for you.
Again, sorry for providing the wrong info above,
Andy

sisko's picture
Offline
Joined: 09/17/2009
Juice: 266
Hey Andy ...

first of all, thanks. You are the man and I really appreciate your ongoing help.

Secondly, 2 small problems. My clients don't trust patches. They have a few drupal sites already and insist I find a non-patch solution.
And, I don't still know how to apply a patch even after much googling in the past.

Please, please let me know what that alternate solution is. I always suspected there should be a views type module that does updating. I'm dying to know.

Thanks a great deal.

Andy's picture
Offline
Administrator
Joined: 08/07/2007
Juice: 1140
Re: Hey Andy ...

"Your killing me smalls!" Smiling
For future knowledge, the link I provided also has a decent explanation of how to apply a patch, and that patch is going to be included in the next version of Ubercart, but I understand clients.

http://drupal.org/project/uc_views will add views support for products, but I'm not 100% about attributes. If it doesn't work for attributes, this approach won't work. Then there is http://drupal.org/project/views_bulk_operations After glancing over the docs, I'm actually pretty sure this won't work. Maybe if Views Bulk Operations (VBO for short) allows you to change the content type which is the same thing as the product class, it will pickup the attributes during the change, but I think I tried that once before, and it didn't work.

I really think the patch is the best option. Maybe you can convince the client to let you copy the files, apply the patch, make the changes, and then replace the patched file with the original.
The only other option I can think of is to edit the database by hand. This is dangerous, so MAKE A BACKUP. But, I tested this on a fresh install and it worked for me.

Look in uc_attributes for the attribute you want to apply to all the products. Note the AID.

Look in uc_attribute_options for the options (OID) matching the AID above (if you only want to apply some of the options then just note those).

Then look in uc_product_attributes for a row with the matching AID from above. You need to create a new row for each node (NID) you want to attach the attribute to that is identical to the row you just found except with the NID of the new node.

Then look in uc_product_options. Do the same thing as above, but this time you need a new row for each combination of NID (node) and OID option.

Best of luck.
Andy

sisko's picture
Offline
Joined: 09/17/2009
Juice: 266
Hi Andy

So, I've read about and tried to execute the patch and I've been unsuccessful.

I'm still trying...as you can imagine, it's important I get it working.

However, I had a brainwave and I checked out the notes on the next scheduled release of ubercart. It seems the patch changes are committed to the 2010-Jan-20 ubercart version.

I took a chance and overwrote my ubercart installation with the as yet unreleased version. So far so good, all is working great.

I wonder if you can help me by confirming the patch is applied to the upcoming new release and if it is, can you give me directions on how to apply attributes to all my products ?

Thanks a great deal.

bensey's picture
Offline
Joined: 07/20/2011
Juice: 16
Using VBO.

Late reply, but I just though I'd put this out there for anyone else...

By using VBO's excellent "Execute arbitrary PHP script" feature, I was able to add attributes to huge amounts of products.

This is based on D7 db query and entity structure, but with some small changes could be made to work in D6.

Select the product nodes in your VBO view, and select the operation "Execute arbitrary PHP script".

Paste the following into the textarea, changing the $aid to the attribute ID you wish to add.
It will add the attributes to the selected products with the default values.

EDIT: Change the label "Ring Backing" to whatever you wish your label to be...

// attribute ID
$aid  = 2;

$nid = db_insert('uc_product_attributes')
    ->fields(array(  'nid' => $entity->nid,
    'aid' => $aid,
    'label' => 'Ring Backing',
    'ordering' => 0,
    'default_option' => 4,
    'required' => 1,
    'display' => 1,
    ))
    ->execute();

$attribute = uc_attribute_load($aid);
foreach ($attribute->options as $option) {
        $id = db_insert('uc_product_options')->fields(array(
          'nid' => $entity->nid,
          'oid' => $option->oid,
          'cost' => $option->cost,
          'price' => $option->price,
          'weight' => $option->weight,
          'ordering' => $option->ordering,
        ))->execute();
}

zdendaf's picture
Offline
Joined: 10/09/2013
Juice: 6
Re: Using VBO.

Thans a lot for this tip. VBO with PHP scripts helped me to resolve my problem with adding attributes to thousands of products.

kopeboy's picture
Offline
Joined: 02/21/2014
Juice: 12
How to set stock value?

I tried creating a component to use in VBO to set stock value as shown here for Drupal Commerce (http://browse-tutorials.com/video-tutorial/edit-node-fields-using-vbo-dr...),
but with Ubercart I cannot select any stock entity in Rules.

Has anyone done this? Adjusting stock values is the single most time consuming operation in our shop.

Thanks