I don't know of this has been discussed yet but I need some way to attach an image to an attribute i.e. colour. I've done this before on other carts so I guess its a pretty common thing to do. Whats needed is
- Some JS for changing the image when the attribute is changed
- Show the appropriate image in the cart
- the default would go off the default for that attribute
I guess I'll have to write something if the facility isn't there, but any ideas as to a good approach?
I guess whats needed is a way to map attribute values to images on a per product basis. So ether store this in the DB (somewhere like product_options) or use some sort of file naming convention. (which is bit of a hack). Something easy for the JS to read as switch quickly...?
Any thoughts on this before I hack together something?
--
under Too Much Information
------------------
PREVIOUS REPLIES:
mikejoconnor:
I started thinking about this the other day. The major issue I envisioned was cascading attributes. It would be rather easy to just do a color adjustment, but if you have a desk lamp and floor lamp, each with 4 colors, it would be nice to be able to change the image. However if you offer a camera with a 512mb flash card, or the option to upgrade to a 1gb flash card, you may not want to display another image.
I thought you could add a 'separate image' to the attributes page
** The following is just my brain storming, I haven't evaluated it **
<?php
function attribute_image_hack_form_alter($form_id, &$form){
switch($form_id){
case "uc_object_attributes_form":
foreach($form['chosen_attr'] as $key => $value){
$form['chosen_attr'][$key]['image'] = array(
'#type' => 'checkbox',
'#default_value' => variable_get('uc_attribute_images', 0)
);
}
echo var_dump($form['chosen_attr']);
break;
}
}
?>Then on the adjustments page you could provide an upload field for that image
<?php
case "uc_product_adjustments_form" :
$form['#submit']['uc_attribute_images'] = array();
$form['table']['head']['#value'] .= '<th>Image</th>';
//add a image upload field to each attribute
foreach($form['table']['body'] as $key => $value){
if(is_numeric($key)){
//add if change image is selected on attribute page
$form['table']['body'][$key]['image']= array(
'#type' => 'file',
'#prefix' => '<td>',
'#sufix' => '</td>',
);
}
}
break; //uc_product_adjustments_form
}
}
?>As far storing and changing the image goes, I was looking at the uc_product_adjustments table. The adjustment key seems to be saved as a serialized array as uc_product_adjustments.combination.
When a new option is selected, we could have jquery could submit the form(there's a nice jquery plugin for this) to a function that would return the new image url.
CpILL:
Yes but,
As is the case in the rag trade, you usually have size + colour attributes, for which the adjustments page (quite rightly) generates an entity for every combination. So if you have 5 sizes and 3 colours you need top upload 3 images 5 times each, which is really boring. This gets more complicated when you have to import via CVS Sad
The adjustments table is a mess at present. The serilaised "combination" column is an array of the attribute combination for that row in the adjustments table, which means you can't use it on any SQL cross referencing, which you might do in this case with an many-to-many table between image nodes (via imagecache), which would be one solution. After a big DB design discussion, Lyle knows the path but as we all know "there is a difference between knowing the path and walking the path [Neo]"
Also in that discussion it was brought out that each time an attribute is associated with a product instance a copy of the 'uc_attribute' table is copied to the 'uc_product_options' table (see: even more figures), so each product node has its own copy of the attributes to play with (but sadly the table doesn't have its own primary key to make it easy to associate directly with), which is a powerful idea and makes Ubercart unique (as far as I know) in the way it models product attributes.
So thats how I was thinking of tacking the issue. I guess then if you do want a different picture for each combination of attributes you'll have to associate with the adjustments table, which as you mentioned, has an ugly primary key setup, but you can do as I did with the Inventory API and use the SKU and cross your fingers the User doesn't have duplicates.
--
under Too Much Information



</off topic>
It was tricky making the ajax stock check worked after the image replace but it just forced me to be as generic as possible with each module that interfered with the product details page.








Joined: 08/08/2007