View Single Post
  #1  
Old 01-18-2005, 09:58 AM
 
sstillwell@aerostich.com sstillwell@aerostich.com is offline
 

eXpert
  
Join Date: Jun 2004
Location: Duluth, MN
Posts: 242
 

Default Printable Gift Certificates for Customer and Backend

Gift certificates sure do complicate things, at least for us.

This is my first posted mod so go easy. I'll post others soon.

This mod allows you to send each gift certificate recipient a custom graphic they can print and use instore or give to someone else. It also allows you to create a gift certificate using a custom graphic in the backoffice to print up and send. Example http://www.spydorweb.com/images/5F14BC86D0C0D640.jpg

This mod is not for the faint of heart and you have to make sure that your hosting server supports the functions used.

WARNING!! WARNING!!! WARNING!!!!
Backup up your database and xcart directories before making any alterations.

Need to have the GD library compiled with PHP.

How do you verify this?
Create a file called php.php in the root directory
Code:
<?php phpinfo(); ?>
Access this file in a browser and make sure that is says somewhere --with-gd
FreeType support must be enabled as well.

Ok Getting started

1. Create a basic graphic. Mine is 672pixels X 672pixels.
You can see it here http://www.spydorweb.com/images/giftcert.jpg
We'll call it giftcert.jpg. Oh it must be a jpg as well.

2. Copy the graphic to files/images/misc/giftcert.jpg

3. Grab this TrueTypeFont File here http://www.spydorweb.com/images/Vera.ttf
And throw that in files/images/misc/Vera.ttf as well.

4. add this to the bottom of include/func.php
Code:
# # Create GC Image to include in the customer email # function func_create_gc($giftcert){ global $xcart_dir, $config, $xcart_http_host; # Variables $gc_exp_date = date("m/d/Y", strtotime("+1 year",$giftcert["add_date"])); $image = ImageCreateFromJPEG($xcart_dir.'/files/images/misc/giftcert.jpg'); $white = imagecolorallocate($image, 255, 255, 255); $black = imagecolorallocate($image, 0, 0, 0); $ttf_location = $xcart_dir."/files/images/misc/Vera.ttf"; # Company info $phone = $config["Company"]["company_phone"]; $url = $xcart_http_host; ImageTTFText($image, 10, 0, 12, 22, $white, $ttf_location,$phone); ImageTTFText($image, 10, 0, 522, 660, $white, $ttf_location,$url); ImageTTFText($image, 18, 0, 190, 258, $black, $ttf_location,$giftcert["recipient"]); ImageTTFText($image, 24, 0, 190, 440, $black, $ttf_location,"$".$giftcert["debit"]); ImageTTFText($image, 18, 0, 190, 351, $black, $ttf_location,$giftcert["gcid"]); ImageTTFText($image, 18, 0, 190, 585, $black, $ttf_location,$gc_exp_date); ImageTTFText($image, 18, 0, 190, 301, $black, $ttf_location,$giftcert["purchaser"]); ImageJPEG($image,$xcart_dir."/templates_c/".$giftcert["gcid"].".jpg"); }

You will need to edit this function more later I'll explain below.

5. add
Code:
func_create_gc($giftcert);

to include/func.php (this starts around line 3238)
as follows
Code:
# # This function sends GC emails (called from func_place_order # and provider/order.php" # function func_send_gc($from_email, $giftcert, $from_login = '') { global $mail_smarty, $config, $to_customer, $sql_tbl; $giftcert["purchaser_email"] = $from_email; $mail_smarty->assign("giftcert", $giftcert); func_create_gc($giftcert);

This will create the image right before it's sent via email and store it in the templates_c directory as <giftcertificate id>.jpg (e.g. 5873F758D81A063C.jpg)

6. Now edit the skin1/mail/html/giftcert.tpl add the following somewhere in the mix
Code:
[img]{$xcart_web_dir}/templates_c/{$giftcert.gcid}.jpg[/img]

Backoffice side

7. add the file "admin/view_gc.php"
Code:
<?php # Creates the GC image and then displays it on the screen require "./auth.php"; require $xcart_dir."/include/security.php"; $giftcert = func_query_first("SELECT * from $sql_tbl[giftcerts] where gcid = '$gcid'"); if($giftcert){ func_create_gc($giftcert); header("Location: ".$xcart_web_dir."/templates_c/".$giftcert["gcid"].".jpg"); }else{ print "Could not create Gift Certificate Image"; } ?>

8. edit skin1/admin/modules/Gift_Certificates/gc_admin.tpl (around line 38)
replace
Code:

with
Code:

You can now log into the back office, go to Gift Certificates and there should be a "View" link next to each GC code. Clicking it will create that image and then display it.

9. Last part, you need to edit the position of the text for your custom image. This is done through trial/error. Look back again at the func_create_gc function we added to include/func.php.

There are several lines like such
Code:
ImageTTFText($image, 10, 0, 12, 22, $white, $ttf_location,$phone);
To move that particular object around the image you need to change the 3rd number (12) which is the horizontal position and the 4th number (22) which is the vertical position. Look here http://www.php.net/manual/en/function.imagettftext.php for more information about this particular php function.

Hey this works for me on v4.0.9.

Why didn't I just do an HTML image? A graphic will show the same on all plateforms/email clients and just looks professional.
__________________
No longer using Xcart, was good while it lasted.
Reply With Quote