I need to automatically generate Alternate SKU, with the ability to accept token from already exiting fields

In my store of 200 products, each product has 2 different part number types. a part number for 240 volts and another for 120 volts. The part numbers for the 240 and 120 volts are in custom text fields.

I will like to dynamically create attributes using the data in the two text fields for all the 200 products. And have the attribute display on the add to cart form

so i will like my user to select either of them before adding it to the cart and have the select they chose( the attribute they chose) appear on the checkout as well as get emailed out.

Any help

Thanks

Comments

TR’s picture

Priority: Major » Normal
Status: Active » Fixed

Well, this is what attributes were designed for, so the best way would be to make an attribute with two options, 120 and 240, add that attribute to all your products, and for each product assign different SKUs to those two options. Leave the text fields if you want if they will be part of the product description, but they won't be needed for Ubercart. You can write a little script to assign the SKUs programmatically using the text field values, and you can do this automatically every time a new product is added. This is a small piece of custom code. Note that the part number is not an attribute option, the supply voltage is. That way you have one attribute with two options that you use for all your products, you don't have two unique options for each product. The part number corresponds to a SKU, so you have a different part number / SKU for each product/option combination.

If you insist on keeping the part numbers in text fields, then you're going to have to invent your own mechanism for making these selectable by the customer and for recording the selection, as well as assigning prices and SKUs to the purchase given the selection, as well as tracking stock and reports, etc. This is way more work than just switching to use attributes in the first place.

One quick way to do what you want would be to add a textfield attribute to each product then write a little jQuery for your product page which turns the fields into a select then records the selection into the (hidden) textfield attribute. This would let you get the part number into the attribute, but you loose the ability to designate different SKUs depending on option chosen and you loose being able to price the options differently (unless you add additional custom code). And you will need more custom code to do things like see what percentage of your orders are 240 vs 120, something that would be trivial if these were attribute options.

This issue queue is not really for detailed support questions. If you need further help please do so on ubercart.org, in IRC, or elsewhere.

docans’s picture

Thanks you very Much TR

You have been really helpful as to the breakdown but i will like to know where i can find additional resources to find how to programmatically assign the alternate sku

Thanks

longwave’s picture

You might want to look at the UC Product Power Tools module and the patch supplied in #639542: automatic Alternate SKU adjustments - this is for 6.x but should be portable to 7.x.

docans’s picture

I tried porting the patch but it would not work for drupal 7, the database queries are different along with other things.

Is there a way to just make the alternate SKU accept tokens. I took a look at this article at this link http://clikfocus.com/blog/how-add-token-support-drupal-7

But i dont know where exactly to implement the code

Thanks

docans’s picture

Can any one please help me as to how i can make Attribute options accept field tokens?

docans’s picture

Status: Fixed » Active
docans’s picture

Status: Active » Needs review
TR’s picture

Status: Needs review » Fixed

This issue queue is not really for detailed support questions. If you need further help please do so on ubercart.org, in IRC, or elsewhere.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.