Setting up many products with one product display and multiple selection categories

Apologies if this is an old question with an existing question, I'm a newbie and despite searching around, can't find an answer.

Basically, I'm trying to set up the T-shirt type commerce site with only some success. In this example, I have different types of T-shirts from different suppliers. I want to set up a product display for each supplier and allow customers to select the T-shirt spec from pull downs for each supplier. So I have, say, three colours and three sizes from each suppler (red, green, blue and S, M, L). Bulk add products is excellent as it allows me to create products for every combination for a supplier and associate all of them with one product display. In reality, my product combinations are rather large (my example here has, I think, only 9 combinations) This is perfect, except when I want to edit the product display (say I get a better image of the T-shirt or I got it wrong). I can't find a way of editing the product display alone without also having to specify the products in the Products field of the Edit Product display form; as I said, I have a large number of product combinations per product display, more than can be specified in the Edit Product display form so the link is broken for all the products that aren't in the Products field (although the bulk product create managed this perfectly). Any suggestions please (or ideally pointers)?

Secondly, having done this, after the bulk product creation the product selection my customers would see comes up with a single pull down containing the combinations so, back to the T-shirt example, it has Red S, Red M, Red L, Green S, Green M etc. I'd prefer there to be two pull downs, one with the colours and one with the sizes. Again, any suggestions for how this might be done?

Many thanks for any suggestions in advance.

Posted: Jan 18, 2012


rfay Randy Fay on January 18, 2012

If you have only one dropdown, it probably means you didn't select each attribute as an attribute when adding them to the product. There should be two separate selects.

If you'd rather have the photo on the product display, you could just remove the field from the product and add one to the product display.

PedroKTFC on January 20, 2012

Thanks rfay, not sure about your selecting each attribute, but I'll look at it a bit later.

As for my problem with product display, I've managed to get a little further, at least in understanding it.

Looking at the database structure, I think I've found out what the key tables are for this. It looks like there's a row in the node table for each product display, while the body data for the product display (ie the big body field in the product display, referred to as content:body in places) is held in the table field_data_body. The table field_data_field_product acts as a link entity between products and product displays. I don't want to update this link entity, I simply want to edit the product display body (specifically the field field_data_body.body_value) for the particular product display I'm interested in. Any suggestions how I do this within Drupal rather than editing the table explicitly?

Thanks again.

rfay Randy Fay on January 20, 2012

Oh please don't access the database directly :-) You would load the node, edit it, and save it. There's a shortcut you can use (field_attach_something) to save just the body field. Still, seems like you're trying to do something you shouldn't have to do.

PedroKTFC on January 21, 2012

I certainly don't want to access the d/b directly. How do I load, edit and save an arbitrary node? I can't seem to get to it. Or how do I find a shortcut? (Btw, I was driven to try this because I bulk set up a load of T shirts pointing to one product display. I found I'd got the wrong T shirt image so edited the product display but the product list field in the product display is limited to 128 characters, and I'd got more T shirts references than 128 characters would allow. I can't easily avoid this.)

rfay Randy Fay on January 21, 2012

We can't do developer API support here. You might want to check out the excellent "Drupal 7 Module Development" (book). There are lots of other resources.

You can change the size of a textfield by editing the field settings.

PedroKTFC on January 21, 2012

In case anyone's interested, I've cracked it and put a description below of how I did it. I've now got another issue which, if I can't sort out, I'll be back with soon!

Thanks for the suggestions which helped steer me.

**Editing Product Display body only**

Go to Configuration and click on Rules, from there click on the Component tab and then click on Add new component in the form that comes up.

Choose an “Action Set” from the Component plugin pull down and click on Continue.

In the next form (which is non-trivial!), give your new component a name (I used “Change product body”), no need for any tags (whatever they are, something else I’ll have to learn about no doubt!), and then you need to configure two variables as follows:

1. Data type: Node; Label: something convenient eg “Product body”; Machine Name: eg “product_body”; Usage: parameter.

2. Data type: Text; Label: something convenient eg “New Body”; Machine Name: eg “new_body”; Usage: parameter.

Click on Continue.

In the new form that displays, click on “Add action” and in the new pulldown that appears, select “Set a data value” (in the Data set of options) which automatically causes the form to change and you now have a new field “Data selector”. You don’t need to type anything, just select the down arrow to the right of the data entry box, and select “document-display... (Document Display)” from the pulldown that appears, which updates the pulldown with the next layer down, select “document-display:body... (The main body text)” which again updates the pulldown and from this last one select “document-display:body:value (Text)”. (Notice how this could be used to update any single text field in the product display.) Click on Continue.
In the next form that appears, click on the “Switch to data selection” button which changes the form to include a Data selector field. As in the last form, clicking in here pullsdown the allowed options and you should see the variable you configured in two above in the list (if you used the same names, you’d see “new-body (New Body)”, select it.

You now have the mechanics for updating the field, you just have to add it to somewhere useful!

Click on Structure>Views and choose the view you want it to operate in. In my case, the sensible place is in Product Display Nodes (VBO) so click on the edit option for that view. In the new form that appears, click on Content: Bulk operations under the FIELDS area. A new form appears and look down and under SELECTED OPERATIONS, you should see your new component unchecked. Check it, some more options appear but ignore them and click on Apply (all displays). Click on Save and you’ve finished!

Now, if you go to your bulk product view (PRODUCT DISPLAY (VBO) tab) , then if you have many products for each product display, you’ll have lots of entries all sharing a product display. To change the Body for a particular product display without changing anything else about it, just select one entry using that product display, from the OPERATIONS select your new “Change product body” action, click on Execute and a new form will open allowing you to enter a new value for the body. Bingo!