Ubercart Color Attribute

Contrib type: 
Module
Status: 
Uploaded for testing
Moderation: 
Awaiting moderation

Downloads

Compatibility: 
Ubercart 2.x

This module creates an attribute for a product called "Color choice", it allows a user to choose certain colors as options and store the hex value of the color along with the color name to be shown on the product page. So for example if you are selling an item with multiple color options you could use this module to display the color choices in boxes on the product page. Now with added jquery to allow clicking of the color box.


PreviewAttachmentSize
UC Color Attribute.zip3.53 KB
davery's picture
Offline
Joined: 02/25/2011
Juice: 12
extend to work on all add to cart forms

Hi,

I modified your color attribute module to provide the color picker on any page with the add to cart from, including views, instead of only the product's node page. The relevant bits of code are here, GPL 2 or later, if you're interested in putting them in your official release. I tried posting this to your page but the captcha did not work no matter how many times i entered it correctly.

The php:
foreach($node->attributes as $value)
{
if($value->name == "colorChoice")
{
/* We have a colour attribute choice */

$attId = $value->aid;
$html = "";

foreach($form['attributes'][$attId]['#options'] as $key => $value)
{
$kexValue = db_result(db_query("select hexValue from {uc_color_attribute} where oid = %d limit 1;",check_plain($key)));
if(!empty($kexValue))
{
$html .= "";
}
}

$html .= "";
$form['attributes'][$attId]['#prefix'] = $html;
}
}

The js:

$(document).ready(function(){
$('div.colors-color').click(function() {
var attrId = $(this).attr('attrid');
var oId = $(this).attr('oid');
var exists = $('div.txtmsg', $(this).parent().parent()).html();
var title = $(this).attr('title');

$('select[id^="edit-attributes-"]', $(this).parent().parent()).val(oId).trigger('change');

if(exists){
$('div.txtmsg', $(this).parent().parent()).html('Selected Colour: '+title);
}else{
$(this).parent().before('Selected Colour: '+title+'');
}
});
});

The css:

div#colors-background{
margin:5px;
background-color:#fff;
min-height:30px;
}

div.colors-color{
/*cursor:pointer;*/
cursor:hand;
height:20px;
width:20px;
float:left;
border:1px solid black;
margin:4px;
}

div#txtmsg{
clear:both;
}

Enjoy.

temp's picture
Offline
Joined: 08/02/2011
Juice: 5
Re: Ubercart Color Attribute

i manualy delete atribute called "Color choice"
how to back it again, i try reinstall module - it not help.

i have trouble with this module, when i choice color by clicking on one of color squares, desired color dosent chooze in select box above.

Buro Friesen's picture
Offline
Joined: 10/10/2011
Juice: 13
Not showing colors

I have the UC Color Attribute module installed, have made a set of colors and attached them to a product. But there are no colors showing up when i select a color.

krista's picture
Offline
Joined: 03/22/2012
Juice: 3
Re: Not showing colors

Did you ever resolve this issue? I am having the same problem. The colors appear for a second then they disappear. I have disabled modules that may interfere and changed themes to no avail.

Buro Friesen's picture
Offline
Joined: 10/10/2011
Juice: 13
nope

I never solved the issue, went with the text instead of actual colours.