As it stands when the user clicks on the the product thumbnail it shows the original uploaded product image. I would like to instead link it to an imagecache image that puts a watermark over the image. I already Have the watermark settings set up. But now I need to tell ubercart to link the product thumbnail to the watermarked image instead of the original. Any ideas how I could acheive this?
Thanks
Linking the thumbnail to an imagecache image
|
|
The link you can create manually. It will just be something like "/files/imagecache/YOUR_PRESET_NAME/[filepath]"
(The filepath is usually $node->field_image_cache[0]['filepath'] for the first image.
Im not very familier with messing around with the module code. I found $node->field_image_cache[0]['filepath'] referanced several times in the uc_product module. I really dont know what to do with it. Could you explain more indepthly. Thank You
Am I changing all the instances of $node->field_image_cache[0]['filepath'] to $node->field_image_cache[0]/files/imagecache/YOUR_PRESET_NAME/['filepath']? in the entire module?
No, you won't need to change anything in the module. The change you'll be making will be in the TEMPLATE for your product node type. The easiest way is to create a node-product.tpl.php file within your theme's directory - you can basically reuse node.tpl.php and edit the file to be specific to your node type.
There, you can create your image showing up as I've described.
A good tutorial is available here: http://neemtree.com.au/drupal-theming-designers and I'm sure if you do a search for "node-product.tpl.php" here on the Ubercart forums you'll find some more helpful info.
Secondly, if creating templates by hand isn't your cup of tea, download the Contemplate module, which will give you a good starting point for learning the ins and outs of theming node types: http://drupal.org/project/contemplate
Ok Im using contemplate but it appears that I have to rewrite the entire page template instead of just changing one attribute of it. I cant find the default product template code anywhere on this site so I may copy and paste it and make the nessasary change. All I want to do is change the code so the default uc imagecache preset "product" shows up in the thickbox instead of the original image.
Also I have almost no programming knowledge so if it seems Im missing something obvious its prob cause I dont know what Im doing lol
While creating your own node-product.tpl.php is the most flexible solution, as torgosPizza said, it's overkill for what you need to do. All you have to do here is to override theme_uc_product_image() and change the one line where it specifies the 'product' preset. Simply copy the body of the theme function and substitute the name of your own preset in place of 'product' and you're good to go. If you've never overridden a theme function before, start here: http://www.ubercart.org/faq/617
OK well here is the function, what line do I need to change so thickbox uses the imagecache preset "products" instead of the original image file. Im sorry I feel really dumb needing to be handed every step but this is all really new territory for me.
function theme_uc_product_image($images) {
static $rel_count = 0;
$thickbox_enabled = module_exists('thickbox');
$first = array_shift($images);
$output = '<div class="product_image">';
if ($thickbox_enabled) {
$output .= '<a href="'. check_url(file_create_url($first['filepath'])) .'" title="'. $first['title'] .'" class="thickbox" rel="field_image_cache_'. $rel_count .'">';
}
$output .= theme('imagecache', 'product', $first['filepath'], $first['alt'], $first['title']);
/* if (count($images)) {
$output .= '<br />'. t('Click for more images.');
} */
if ($thickbox_enabled) {
$output .= '</a>';
}
$output .= '<br />';
foreach ($images as $thumbnail) {
if ($thickbox_enabled) {
$output .= '<a href="'. check_url(file_create_url($thumbnail['filepath'])) .'" title="'. $thumbnail['title'] .'" class="thickbox" rel="field_image_cache_'. $rel_count .'">';
}
$output .= theme('imagecache', 'uc_thumbnail', $thumbnail['filepath'], $thumbnail['alt'], $thumbnail['title']);
if ($thickbox_enabled) {
$output .= '</a>';
}
}
$output .= '</div>';
$rel_count++;
return $output;
}my thinking is that it has something to do with this line
$output .= theme('imagecache', 'product', $first['filepath'], $first['alt'], $first['title']);But I really dont know what to do with it
does anyone know? this is the last thing I need to do before I can launch my site. Im not trying to change the product image to use a differnt image cache preset. Im trying to change the link of the product image to use the 'product' preset.
thanks
Change this:
<?php
$output .= '<a href="'. check_url(file_create_url($first['filepath'])) .'" title="'. $first['title'] .'" class="thickbox" rel="field_image_cache_'. $rel_count .'">';
?>to this:
<?php
$output .= '<a href="'. check_url(file_create_url('/files/imagecache/YOUR_PRESET_NAME/'. $first['filepath'])) .'" title="'. $first['title'] .'" class="thickbox" rel="field_image_cache_'. $rel_count .'">';
?>You will need to do the same thing for the thumbnail href paths. Basically you can use thickbox to load any image you want - so the thing you need to change is <a href=...> to link to your imagecache preset. All imagecache images are created the same way, on the fly, with this type of pattern:
/files/imagecache/YOUR_PRESET_NAME/files/YOUR_FILE_PATH
.. where YOUR_FILE_PATH is usually something like $node->field_image_cache[0]['filepath'] and which sometimes, already contains the "files" directory. In which case you can remove the extra "files/" in the URL pattern I mention above.
You could also combine all of these into one l() function, but that can make things look a little messy. Best to wait until you're more familiar with the syntax before you dive into that.
thank you so much!! that did the trick. There was one typo in your code though. You need to omit the leading / (slash) in the url. But after that everything worked out beautifully. I can finally launch my site....damn now I need to write the EULA...privacy stuff haha. well hey if your interested my site is www.pixel-vortex.com. It still needs a little work done like for example I need a logo but the functionality I needed is all there. I could not have done it with out all your support!!!
|
|




Joined: 01/19/2008