PDA

View Full Version : Include thumbnail images on any page you like (like view cart) w/out a module


Luke
02-09-07, 09:01 PM
I just wrote this little php script that allows you to include a thumbnail image on the view cart page or anywhere else you want a thumbnail image. You need to upload this script to a server with php enabled as well as a mysql beck-end (merchant 5) in order for it to work.

Here is how you implement it, step-by-step

1. Copy this file, change the settings in the top of the file to match your server, and save it as get_image.php
<?php
/******* SETTINGS **************************************************/

// root url to images
define('BASEURL', 'http://store.yoursite.com/merchant2/');

// database host
define('DBHOST', 'localhost');

// database username
define('DBUSER', 'youruser');

// database password
define('DBPASS', 'yourpass');

// database name
define('DBNAME', 'yourdbname');

/******** DO NOT EDIT BEYOND THIS POINT!! **************************/

if (!isset($_GET['id']))
{
exit;
}

$prod_code = preg_replace('/[^a-zA-Z0-9]/', '', $_GET['id']);

$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
mysql_select_db(DBNAME, $conn);

$query = "
SELECT thumbnail
FROM s01_Products
WHERE code = '" . $prod_code . "'
LIMIT 1
";
$r = mysql_query($query);
while($row = mysql_fetch_assoc($r))
{
$thumb = $row['thumbnail'];
}

header('Content-Type: image/jpeg');
readfile(BASEURL . $thumb);
?>


2. Upload this script to a php-enabled server
(for my example, I uploaded it to www.my-non-miva-site.com/php/get_image.php)

3. Log into your miva merchant backend, find your view cart page, click edit, then click "basket contents", then wherever you want your image to show up, you can add this line:
<img src="http://www.my-non-miva-site.com/php/get_image.php?id=&mvt:item:code;" alt="&mvt:item:name;">
Remember to change www.my-non-miva-site.com to whatever the location is of the file you uploaded.

Hope this helps somebody! :D

This could be modified to display a thumbnail or regular image just about anywhere on your miva site. If you need help implementing this, send me a PM and I'll assist you.

nordicwolf
02-09-07, 09:13 PM
very creative , gives me all sorts of ideas.....

chucklasker
02-09-07, 10:28 PM
THANKS! I'm not a PHP guy - would it take much modification to make it show product description?

Luke
02-09-07, 10:33 PM
well this trick I'm doing is taking advantage of the img element's ability to call remote urls. Unfortunately, there is no way within html to call a remote url w/out the image tag (that I know of). That said, there are a few different ways you could achieve what you want with php.

#1: AJAX - have javascript request the remote url and insert the description in where it needs to go

#2: Purchase Emporium Plus Toolkit Module (http://www.emporiumplus.com/merchant2/merchant.mvc?Screen=PROD&Store_Code=wcw&Product_Code=1AA00223&Category_Code=WC_&Search=toolkit&Offset=&filter_cat=&exclude_word=&the_fieldlist=g.SRCH_CODE%7Cg.SRCH_NAME%7Cg.SRCH_D ESC%7Cg.SRCH_CIRCA%7Cg.SRCH_COMPANY%7Cg.SRCH_ITEMS IZE%7Cg.SRCH_ACTORS%7Cg.SRCH_DIRECTOR%7Cg.SRCH_GEN RE&range_low=&range_high=&dopowersearch=1&SRCH_CATEGORY_HF=&PowerSearch_Begin_Only=) and then use it's callurl or vcallurl functions to call the remote php page to extract the description.

Luke
02-09-07, 10:46 PM
Oh I just thought of another way you could request a remote url via html... the iframe.
<iframe href="http://www.yoursite.com/php/get_description.php?id=code">

Still not an ideal solution though. Of all of these, I'd have to say that I like javascript the best (since description is not vital to the customer, I find that javascript may be a viable option here)

Brandon MUS
02-09-07, 11:05 PM
Very nice of you to include the code. I could see this same logic used to CREATE a thumbnail if it doesn't exist, and even supply a default thumbnail in the event that one wasn't found.

I would recommend swapping out the validation for the product code:
$prod_code = substr(preg_replace('/[^a-zA-Z0-9-_]/', '', $_GET['id']), 0,50);
The main thing is allowing for hyphens and underscores (which I use in my product codes), but also enforcing a string size is never a bad idea :D

I think a lot of store owners will appreciate your code.

Luke
02-09-07, 11:43 PM
yea I just noticed that I had forgot the dashes and underscores... I added them in my own code, but could not find an edit button to edit my code here. Also, I am not exactly a regex expert... wouldn't the dash imply a range in your code? shouldn't it be \- and not - ?

Brandon MUS
02-09-07, 11:47 PM
it's only a range if it's between certain characters. The way it sits, the expression is correct (I copied it exactly from my code to validate product codes :D). I think the backslash wouldn't have any effect.

Luke
02-09-07, 11:49 PM
very good. thanks brandon.