Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

Printable Gift Certificates for Customer and Backend
 
Reply
   X-Cart forums > X-Cart 4 > Changing and adding new features
 
Thread Tools Search this Thread
  #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
  #2  
Old 01-18-2005, 01:21 PM
  CC's Avatar 
CC CC is offline
 

eXpert
  
Join Date: Jun 2004
Posts: 349
 

Default

Cant fault you!
That is a quality mod!

Gd job
__________________
XC 4.2 inc (unofficial) patch release.
Reply With Quote
  #3  
Old 12-23-2005, 08:18 AM
 
Delw Delw is offline
 

Member
  
Join Date: Aug 2005
Location: Glendale, Az.
Posts: 29
 

Default

This is a great MOD, My wife had been trying to get me to do this for weeks, last night I finally did it

My Daughter made the graphic not bad for a 15 year old. its amazing what kids can do.
http://del-mart.com/pics/giftcert.jpg

I am using X-Cart version 4.0.14 and found a few things different than above.


Quote:
8. edit skin1/admin/modules/Gift_Certificates/gc_admin.tpl

on my cart it is at skin1/modules/Gift_Certificates/gc_admin.tpl


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


files/images/misc dirs had to be created ( I didnt have the images or misc directories in my shopping cart ), I didnt know if they were in the version you used when you posted.


Not counting the graphic the whole mod took about 10 mins, then aligning the names and such took about 20 mins. Make sure you print them out because it looks a tad different on the paper than on the screen.


Putting the code in the email I still need to play with a little so my customers can find a easy way to print out the cert with out all the other information that comes in the email.


Again Awsum job

Delw
__________________
Version 4.0.14
Reply With Quote
  #4  
Old 02-15-2006, 10:47 AM
  Alltribes's Avatar 
Alltribes Alltribes is offline
 

Senior Member
  
Join Date: Dec 2004
Posts: 192
 

Default

I just implimented this, but would like the message included too. After attempting to do this I can see why it was left out of the original mod.

The problem is if the message is too long it runs off the side of the image. I had considered using the str_replace() function to rewrite the perios to be periods followed by line breaks, but that would look ugly.

I suck at PHP, so if any PHP gurus out there read this, it would be a huge help if you could figure out how to format the message text into multiple lines.
__________________
Alltribes.com
Native American Jewelry
Pottery, Baskets, Kachinas & More

X-cart Gold Version 4.0.17 Live
PHP 5.2.6
MySQL 4.1.25
(mt)
Reply With Quote
  #5  
Old 02-15-2006, 12:27 PM
  Alltribes's Avatar 
Alltribes Alltribes is offline
 

Senior Member
  
Join Date: Dec 2004
Posts: 192
 

Default

Ok, I've got it!

Add this after #Company info
Code:
$message = wordwrap($giftcert["message"], 30, "\r \n");

Change the 30 to however many characters you want to wrap the text at.

And add this with the rest of the ImageTTFText statements

Code:
ImageTTFText($image, 10, 0, 190, 500, $black, $ttf_location,$message);

You'll need to mess with the layout a bit
__________________
Alltribes.com
Native American Jewelry
Pottery, Baskets, Kachinas & More

X-cart Gold Version 4.0.17 Live
PHP 5.2.6
MySQL 4.1.25
(mt)
Reply With Quote
  #6  
Old 10-03-2007, 04:27 PM
 
scottWB scottWB is offline
 

Member
  
Join Date: Jun 2006
Posts: 19
 

Default Re: Printable Gift Certificates for Customer and Backend

A way to allow the customer to print in 4.1.8 using the templates.

Edit giftcert.php and add:

Code:
#Added for GC Printing elseif ($mode == 'print') { $giftcerts = false; if (!empty($gcids) && is_array($gcids)) { $tpl_cond = (!empty($tpl_file) ? " AND tpl_file='$tpl_file'" : ''); $giftcerts = func_query("SELECT *, add_date+'".$config["Appearance"]["timezone_offset"]."' as add_date FROM $sql_tbl[giftcerts] WHERE send_via<>'E' AND gcid IN ('".implode("','", array_keys($gcids))."') ".$tpl_cond); } if (empty($giftcerts) || !is_array($giftcerts)) { $top_message['type'] = 'W'; $top_message['content'] = func_get_langvar_by_name("msg_adm_warn_gc_sel"); func_header_location('giftcerts.php'); } foreach ($giftcerts as $k=>$v) { if ($config["General"]["use_counties"] == "Y") $giftcerts[$k]["recipient_countyname"] = func_get_county($v["recipient_county"]); $giftcerts[$k]["recipient_statename"] = func_get_state($v["recipient_state"], $v["recipient_country"]); $giftcerts[$k]["recipient_countryname"] = func_get_country($v["recipient_country"]); } $smarty->assign("giftcerts",$giftcerts); header("Content-Type: text/html"); header("Content-Disposition: inline; filename=giftcertificates.html"); $_tmp_smarty_debug = $smarty->debugging; $smarty->debugging = false; if (!empty($tpl_file)) { $css_file = preg_replace('!\.tpl$!', '.css', $tpl_file); if ($css_file != $tpl_file) { $smarty->assign('css_file', $css_file);; } } func_display("modules/Gift_Certificates/gc_admin_print.tpl",$smarty); $smarty->debugging = $_tmp_smarty_debug; exit; } # End added

after

Code:
elseif ($mode == "delgc") { # # Remove GC from cart # array_splice($cart["giftcerts"],$gcindex,1); func_header_location("cart.php"); }

Then in skin1/mail/html/order_data.tpl, add:

Code:
<!-- Added for Custom Print GC --> <br /><h3><a href="/giftcert.php?mode=print&tpl_file={$gc.tpl_file}&gcids[{$gc.gcid}]=on" target="_blank">Click here for printable gift certificate.</a></h3> <!-- /Added -->

after

Code:
{if $gc.send_via eq "P"} {$lng.lbl_gc_send_via_postal_mail}<br /> {$lng.lbl_mail_address}: {$gc.recipient_firstname} {$gc.recipient_lastname}<br /> {$gc.recipient_address}, {$gc.recipient_city},<br /> {if $gc.recipient_countyname ne ''}{$gc.recipient_countyname} {/if}{$gc.recipient_state} {$gc.recipient_country}, {$gc.recipient_zipcode}<br /> {$lng.lbl_phone}: {$gc.recipient_phone}

It works.
__________________
X-Cart Pro 4.1.10
PHP 4.4.2
Apache 2.0.52 RedHat
MySQL 4.1.20
Reply With Quote
  #7  
Old 02-26-2008, 12:59 AM
  bullfrog's Avatar 
bullfrog bullfrog is offline
 

eXpert
  
Join Date: Oct 2004
Location: Oregon, USA
Posts: 366
 

Default Re: Printable Gift Certificates for Customer and Backend

I used scottWB's mod to print Gift Certificates in 4.1.9 and it worked nicely! But if you try it, here are a couple of pointers so your edit will go faster than mine.

First, in X-cart 4.1.9 find giftcert.php in the root directory. That wasn't clear to me from the posting above.

Second, I was able to print the customers Gift Certificate from the receipt at the end of checkout, but I could not print from the receipt that I display thru Admin/Orders. My fix was to hard code the URL in the order_data.tpl edit. I suspect my shared SSL to be the reason for not being able to print from Admin.

Like this worked for me:

Code:
<!-- Added for Custom Print GC --> <br /><h3><a href="http://www.mysite.com/giftcert.php?mode=print&tpl_file={$gc.tpl_file}&gcids[{$gc.gcid}]=on" target="_blank">Click here for printable gift certificate.</a></h3> <!-- /Added -->
__________________
Bullfrog ~~~ X-Cart Gold v4.7.2 (2) v4.7.8. ⌠If the road is easy, you're likely going the wrong way.■ ― Terry Goodkind
Reply With Quote
  #8  
Old 02-26-2008, 02:42 PM
 
collings26 collings26 is offline
 

Senior Member
  
Join Date: Dec 2007
Posts: 149
 

Default Re: Printable Gift Certificates for Customer and Backend

Hello bullfrog,

I have the same version as you and im trying to work this out but failing miserabley. I cannot get ANYTHING to work.

Sorry to be a pain. Ive followed ScottWB steps and nothing

Regards
Chris
Reply With Quote
  #9  
Old 10-20-2008, 09:06 AM
 
Brian Schade Brian Schade is offline
 

Member
  
Join Date: Apr 2008
Posts: 25
 

Default Re: Printable Gift Certificates for Customer and Backend

ScottWB and/or Bullfrog - I'm a bit confused on how to implement this in 4.1.9. I was wondering if the original code modifications mentioned at the beginning of this thread (by sstillwell) still need to be added or can I just start at ScottWB's post?
__________________
Brian Schade
Owner and CTO
Twilight Teez, LLC
www.twilightteez.com
X-Cart 4.1.9 GOLD
Reply With Quote
  #10  
Old 10-30-2008, 10:36 AM
  bullfrog's Avatar 
bullfrog bullfrog is offline
 

eXpert
  
Join Date: Oct 2004
Location: Oregon, USA
Posts: 366
 

Default Re: Printable Gift Certificates for Customer and Backend

Sorry for the delay in responding. I don't go to the forum as much as I used to.

From re-reading my 02-26-2008 post, I think I started at scottWB's mod and did not use anything from previous posts.

The code in my post is a change I made to scottWB's to get printing to work on my system. If you use my line of code within scottWB's mod, make sure you use your URL where the example shows http: //www.mysite.com.

I don't understand his mod, but I followed it and it worked for me. There is more than one file named giftcert.php. Make sure you are editing the one in the root directory. Use a simple text editor to make the edits.

Good luck.
__________________
Bullfrog ~~~ X-Cart Gold v4.7.2 (2) v4.7.8. ⌠If the road is easy, you're likely going the wrong way.■ ― Terry Goodkind
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Changing and adding new features


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 08:45 AM.

   

 
X-Cart forums © 2001-2018