I just figured this out and I'm pretty exited.
function custom_cart_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'uc_cart_view_form') {
//Here I just remove the title of the image column
$form['items']['#columns']['image']['cell'] = '';
//Now I am moving around the columns by adjusting the weight
$form['items']['#columns']['image']['weight'] = 0;
$form['items']['#columns']['desc']['weight'] = 1;
$form['items']['#columns']['qty']['weight'] = 2;
$form['items']['#columns']['total']['weight'] = 3;
$form['items']['#columns']['remove']['weight'] = 4;
//There are 6 fields in this array other than the cart items, so I loop through and don't account for those 6... haha elegant!
for($i=0;$i<count($form['items'])-6;$i++){
//So... I don't know if there's another way to get the info from the node other than using node_load but since it comes from cache it's fast right?
$form['items'][$i]['image']['#value'] = '<img src="' . base_path() . node_load($form['items'][$i]['nid']['#value'])->field_cart_image[0]['filepath'] . '" alt="Product Image" />';
}
}
}
So basically I'm looping through the cart items in the form and re-assigning the value of the image field to an image in the node that was defined by modifying the product content type.
Background Info
The client designed the cart! So the cart features an image that's 100% different than the product image. So I added a new image to the product and use this code above. Additionally the client wants the image first, remove last, and a few other small modifications which I have yet to make.
How to Use this Code
1. Create a folder in sites/all/modules called "custom_cart"
2. Create a custom_cart.info file:
name = Custom Cart
description = Customizes the ubercart cart display
dependencies[] = uc_cart
package = "Ubercart - core (optional)"
core = 6.x3. Create a custom_cart.module file
4. paste above code.
5. Add an image field to your product content type (I called mine cart image)
6. Upload some cart imagse
7. Enable the new custom cart module
Pretty cool eh? I'm starting to get the hang of this Ubercart/Drupal thing. This will be my third store and my most custom cart.
