Gift Certificate Module

Contrib type: 
Module
Status: 
Initial upload
Compatibility: 
Ubercart Alpha 8

REFER TO THE INCLUDED README.TXT FOR DETAILS

We are posting this now for people who want to help out with testing and provide feedback. We will be cleaning up the code and making some changes over the next few days.

Written by TaRA Consulting Services. As well, Erik (torgosPizza) provided invaluable input and suggestions.

This module will add gift certificate functionality to your "Uberstore". It uses "attributes" to create gift certificate products. It allows an administrator to add an "attribute" for the gift certificate recipient's email, and an optional attribute (textarea) for a personal message to be sent with the email to the recipient. If this attribute is added to a product, it will function as a gift certificate. Administrators can directly issue certificates to any user as well. Please test thoroughly as the ubercart API's are still in development and there may be incompatibilities. The details of module installation/usage are in the included README.txt file.

It would be appreciated if people could leave a comment here letting us know of the compatibility with their cart version.

EDIT: I have updated the tar file with the changes mentioned in some of the comments below. Note: If you are having any problems with duplicate certificates (or no certificates) being created, change the last setting in admin/settings/gift_certificates, so they are only created for chosen "order status".

AttachmentSize
uc_gift_certificate.tar69.5 KB



Re: Gift Certificate Module

Looks pretty good! One thing I noticed and would like to bring up, not sure if you have the time now, but .. to integrate with Workflow-ng, or at least to put a function in your module that updates the order status when the balance and cert amount negate each other.

I bought a product for 3.99 with a 3.99 certificate, and when I completed the order, the status was left at "Pending." It'd help if we could make that "Complete" perhaps.

Also when looking at the admin view of an order, the Total is not displaying correctly.

Subtotal: $3.99
Gift Certificates: -$3.99
Total: $3.99

Still testing but so far it looks awesome. Nice work!

TorgosPizza, Thanks, I will

TorgosPizza,

Thanks, I will look into this. I have not yet familiarized myself much with the workflow-ng module; I was actually just looking into it today.

Cheers!

Re: Re: Gift Certificate Module

Couple other things - it doesn't seem to be deducting the amount of the certificate. I paid for that 3.99 item as mentioned above, and the only certificate I had was for 3.99. When I went to buy another item, it still told me I had 3.99 available in gift certs.

Also, since this is a non-shippable item, and I have checked the box to tell the cart that this is so, the Delivery pane shouldn't be visible - but I have a Delivery pane when I try to purchase a new certificate for someone.

And since it is technically not shippable, it tells me I need to select a shipping option before I can continue.

Just a few minor bugs, hope you can get 'em worked out! Would love to start using this Smiling

TorgosPizza, Your first

TorgosPizza,

Your first comment about the certificate not being "used up" is a concern. It definitely works with my version of the cart. Please test again and if you are sure this is happening, then I will test here with your version of the cart.

Regarding you later comment, the module should not be affecting anything to do with shippability. If you have a product that is non-shippable, then adding the attributes to "make it a certificate" could not affect this.

Cheers,
Darron

Re: TorgosPizza, Your first

No, this is when I'm attempting to purchase a gift certificate for someone. This is with the latest version of the module (downloaded from this page). I will double-check and test to make sure it's not a fluke.

Re: Gift Certificate Module

how do you handle if somebody is placing more than one amount into the cart, like email and textarea, then?

Problems using with Alpha 8

Hi,

I know this module was only tested with Alpha 7e so this is just an FYI.

When I user this module with Alpha 8.

I get the following error:

mysql_real_escape_string() expects parameter 1 to be string, object given in /mnt/w0402/d20/s41/b0265cfb/www/sitev2/includes/database.mysql.inc on line 400.

It occurs after the payment has been processed.

alpha 8 testing

madsqrl,

We will be testing with alpha 8 soon. I don't know offhand why you are getting this error. Are you sure that this module is the cause of the error? If anybody else is testing with alpha 8 could you leave a comment letting us know whether you encounter problems or not.

Re: alpha 8 testing

It appears to be the situation.

When I disable the module I do not get that error on purchasing everything works. When it is enabled I get that error.

I get (4) instances of the error message:

mysql_real_escape_string() expects parameter 1 to be string, object given in /mnt/w0402/d20/s41/b0265cfb/www/sitev2/includes/database.mysql.inc on line 400.

I am purchasing using a real PayPal provider with IPN enabled. The error happens after the IPN is processed successfully and at which point the gift certificate should be granted.

Btw issues aside this is a VERY cool module and a great idea!

mysql_real_escape_string error

madsqrl,
Thanks for more details. So the certificate is not granted at this point? I am going to try the module with alpha 8 tomorrow and see if I get the same problem. I will let you know and we can sort this out. If you have the devel module installed you can let me know the sql queries sent to the DB.

Cheers,
Darron

EDIT: if you don't have the devel module installed, don't bother until I look into things further, get back to you soon Smiling

Re: mysql_real_escape_string error

The certificate is never granted, I checked the certificate database table and it is empty.

Please let me know your results and if I can help you debug further.

I can install the devel module if necessary.

OK, I will test to see what

OK,

I will test to see what is going on. Don't spend time installing the devel module until I check it out.

Cheers

just sharing the love

Wanted to say this is a great module...I'll be having a shot over the next few days...

Change for alpha 8

madsqrl,

I tried out the module with alpha 8 and I did get the same error you were getting. Here are the technicalities for anybody interested. There was a change to the argument passed to hook_order when $op is 'update'. $arg1 used to be an order id, now it is the whole order object. If you put the following code at the beginning of the 'update' case, it should fix things:

if (!is_string($arg1)) {
$arg1 = $arg1->order_id;
}

I will update the .module file soon, so if you find it easier, just get the new file. Please let me know if this fixes your problem.

Cheers!

EDIT: the file has been updated

Thanks for the update. I

Thanks for the update.

I added the above lines of code to my local version.

The previous error is gone now but I am seeing some odd behavior.

In the case where the recipient email address is for a registered user I get two gift certificate records created one for a $0 dollar amount and one for the amount of the product. The gift certificate does appear to work in terms of reducing order total and the value is deducted from the certificate.

In the case where recipient email address is NOT for a registered user then I get two duplicate gift certificate records created for the amount of the product. BUT no email is sent to the user's email address that was given.

Thoughts?

Re: Thanks for the update.

BTW, I dont see an email for the registered user either informing him about the gift certificate.

Email functionality is definitely working on the site, as other Drupal modules including Ubercart use it successfully.

In the case where as administration I directly (without purchase) create/grant a gift certificate, only one certificate database record is created but no emails are sent.

Also it does look like new user accounts are being created for the the non-registered users so it looks like we have email issue and an issue with duplicate record generation on purchase.

Re: Re: Thanks for the update.

I have not experienced any problems with sending emails. B.t.w., when an admin creates a gift certificate, it is not set to automatically send an email. I can add a setting to allow for an email to be sent in this case as well.

When a certificate is purchased by a user, it either sends an email to an existing user, or creates a new account and sends an email with the acct info / certificate info. Also, this has been set up and tested for a site that does not have anonymous purchases.

EDIT: I just tested (with alpha 8 ) the case where recipient email address is NOT for a registered user. It emailed correctly. I'm thinking your email got blocked by a spam filter, did you check the spam box?

Re: Re: Re: Thanks for the update.

Yep it was the the SPAM filter for not seeing the emails.

I think it would be good option to allow Admin issued certificates to have the option of sending an email also generation of a certificate code.

Still seeing the duplicate database record issue. Also the order ID is null in the certificate database table even in the case of purchases which may be a bug.

Thankx much this is a cool module!

madsqrl,

madsqrl,

Thanks. No, this is not a bug. Also the gift certificate rows you see in the database that are $0 are "used up". Say someone has a certificate of value $100 and they make a purchase of $10, the certificate value is updated to $90. So certificates are used up until their value is $0. I think everything is working fine on your install.

I will be adding in the option you mentioned (With a seperate configurable email for this case). Thanks for helping with the testing!

Re: madsqrl,

I hate to disagree but I think something weird is going on here still:

This is not a case of used up certificates, for example for a new order I get two certificate entries:

certificate_id name value user_id order_id purchaser_id cert_code
9 Gift Certificate 2.00 7 NULL 3 9-M4BSjb9aRVus
8 Gift Certificate 2.00 7 NULL 3 8-oHQLE5nGTlmL

I think the issue may be that for different order states the order transitions through, you are generating multiple certificates in your order update case?

Also interesting condition I have seen with user emails. Sometimes the user email isnt sent until the order is in the completed state. But a user has be created (but never accessed) in Drupal. This leads to the wrong email being sent because a user does exist even though the user has never been notified or used the account.

Thoughts?

UPDATE:

I changed my local version to only issue new certificates on the payment received order update case and it is definitely much better behaved. I also added a check to see if the user account was ever accessed in determining which email type to issue.

Hmm,

Hmm,

If this is happening, then there must have been some other changes to hook_order. I will look into this.

EDIT: It looks like hook_order was called twice for your setup wth $op 'update'. As we mentioned at the bottom of the included README, this could be an issue for certain setups. Also, as it says "We will be adding in a setting to only issue certificates on certain specified statuses.".

I hope everything is working for your setup now.

Re: Hmm,

Yep. When you add the setting to issue certificates only on certain specified statuses that should address the issues related to what I patched locally.

Thanks again.

madsqrl, You're welcome,

madsqrl,

You're welcome, thank you for your input. I will post here when the changes are finished.

Specifying a date

Hi there,

thanks again...

I was wondering if there was a way to set the date that the email/account was issued, or delay the issuing. This would allow users to buy, say birthday presents, setting the date that the email was sent out. Also, if the email is to be accompanied by a gift card, it will take a few days to ship, but if the gift card arrives after the email, the email would ruin the surprise.

Can anyone see a way of adding this functionality?

thanks

thomas

Email/account creation delay

Thomas,

This sounds like an interesting feature to add. I think we need a new field to the cert table, a new setting (delay time), and the email sent with hook cron. I am a little busy at the moment to add this right away. Would be glad to integrate this into the module now if you or anybody else gets the chance to do the work.

Cheers

Willing to try

Hi TCS,

so happy to get stuck in and learn how to do the coding...and will do. I was wondering if anyone had any good suggestions as to where to start to learn how to do the things you've suggested. Are there any particularly good tutorials...would you recommend one of the Drupal books...or where do I start.

I'll work it out somehow, but tips would be great.

thanks

Re: Willing to try

I recommend Pro Drupal Development. It's the most recent (last time I checked) and has great examples and easy-to-follow narration.

@ TCS - testing the latest code on our test box, everything seems to work great! I can import our old certs and it seems to recognize everything as it should. Kinda wish we had the certificate entry code on the checkout page, but that's okay - I think attaching it to a user is cool!

But, suppose an admin wants to send a certificate to a user not on the system. Seems you can only do that if you are purchasing a certificate, but not administratively sending one. Any thoughts on that? Or am I missing something?

Otherwise - great work! Will be implementing it soon Smiling

Drupal Book

muirland,

Thats great. I think the suggestion of "pro drupal development" is good. There is really no other resource that compares. I will be posting soon the new files with the changes I mentioned. Thanks for all your useful input!

Cheers

torgosPizza, Thats good to

torgosPizza,
Thats good to hear. Good point about the admin. I will make the changes to allow for non-registered users to be issued certs from an admin.

Cheers

Invalid argument supplied for foreach() in

Hi I am getting the error: warning: Invalid argument supplied for foreach() in /home/loopske/public_html/modules/ubercart/contrib/uc_gift_certificate/uc_gift_certificate.module on line 816. I know this is a PHP4 error so i upgraded to php5 uninstalled the module and reinstalled and for some reason it it is stil giving me the foreach () error. Does anyone know why this is? Thanks

Re: Invalid argument supplied for foreach() in

I looked at the code line from your error message and it is not immediately apparent what the problem is. I will be updating the file tomorrow. If you still have errors after testing the new file, we can take it from there Smiling

Re: Re: Invalid argument supplied for foreach() in

I got the same error on php 5

<?php
warning
: Invalid argument supplied for foreach() in /sites/all/modules/ubercart/contrib/uc_gift_certificate/uc_gift_certificate.module on line 816.
?>

zmove,

zmove,

you could try putting the following before the foreach statement on 816:

if (!$form["attributes"]) {
return;
}

I will upload a new tar file and include this. The new files have other fixes mentioned above. This might result in the "message area" of a product to be a textfield as opposed to a textarea. If so, you could try changing the "weight" of the gift certificate module. Do let me know what you had to do to get it working.

Cheers

TCS, I tested the gift certs

TCS,

I tested the gift certs again, and I had a question. When the order status is updated, does it reissue the certificate?

I "purchased" a certificate for a "friend" who did not have an account, for $20. Paid for it by check / test gateway.

The account was created, and it sent an email with those details, along with the gift certificate information.

Since the order was placed using the test gateway, the admin had to manually change the status to "completed."

Upon doing this another email was sent, 3 minutes later (the time it took for me to login as admin and change the order status, it seems).

When I logged in as the "friend's" account, added an item to my cart, and checked out, it told me I have $40 worth of gift certificates - twice the amount that was actually purchased.

This could be a problem especially for workflow integration, where the order status might need to get updated a couple times (for shipping purposes especially).

TorgosPizza, The latest

TorgosPizza,

The latest version has a setting in the admin now that would allow you to only issue a certificate when the status changes to "completed", or what ever status you choose. I made the following edit in the post above:

Note: If you are having any problems with duplicate certificates (or no certificates) being created, change the last setting in admin/settings/gift_certificates, so they are only created for chosen "order status".

I hope this setting will allow you to configure things correctly so multiple certificates are not sent.

let me know.

Cheers,

Darron

Re: TorgosPizza, The latest

Thanks, thought I had the most recent version - guess not Smiling Will check this out! Thanks!

Re: Re: TorgosPizza, The latest

I have downloaded the latest code, and the gift certificates do not seem to be updating after a successful completed purchase using them. Checked the database, my $10 gift cert that I used to successfully complete a $2.99 zero-total purchase with, still shows a 10.00 value in uc_gift_certificates table.

Also in the invoice (emailed and through Order History), the token [order-payment-method] is not being replaced correctly.

Finally, and this is minor, the Gift Certificates line item comes after the Subtotal in the Order Detail screen. Since it's a subtraction, it should probably come after the Subtotal.

torgosPizza, I have not had

torgosPizza,

I have not had any problems with the gift certificates not updating the way you described. I have been testing with alpha 8, are you using the latest bazaar? not sure if this is the problem. Do you have the side block enabled to see the gift cert amount that is credited to you? If so, after your 2.99 purchase, it still says 10.00?

It would be good if others could leave a comment letting me know if they are experiencing this (and what version of the cart they are using). I will test here again to make sure the tar file I uploaded is good.

Re: torgosPizza,

I found the problem. It seems that the certificate is only updated when the Status moves to "Completed." My test site had order completed Workflow config set to Payment Received. Testing again, but all seems to work now. Thanks!

Although I did see your mention of the sidebar in your README file, but I don't see the config option for that anywhere...

torgosPizza, Thats good to

torgosPizza,

Thats good to hear. The block can be enabled at admin/build/block. It is called "gift certificate" I believe.

Cheers

unregistered user never receive the gift cert

Hello, first off all, good idea, and defenitly needed! thx

I'm testing on alpha8 and experience some problems:
1. Both unregistred: With a unregistred user buying a gift cert using bank transfer as payment (admin has to set complete) the message for the one who should receive the gift cert will never arrive (or sent out)
2. Buyer registered: same problem, there is no gift cert in the store admin -> gift cert
3. Both registrered: same problem, ...

it seems like that there is no cert entered or sent out when payment methods involving "admins setting changing" are used...

Re: unregistered user never receive the gift cert

Just had an incident where the certificate did not work. They had a $20 certificate and when they checked out and tried to use the Zero Total option (since the cert covered the entire 18.95 order), this is the message they got:

Your final order total is 3.5527136788005E-15, not $0.
Please go back and select a different method of
payment.

Your order is not complete. Please review the details
of your order and click Submit Order if all the
information is correct. You may use the Back button to
make changes to your order if necessary.

Payment Method
Subtotal: $18.95
Gift Certificates: -$18.95
Total: $0.00
Paying by: Zero Total

I had to process their order manually. Everything looked fine (I've used certificates on multiple occasions to purchase new releases .. so for instance I have a $500 certificate I have used to buy a 3.99 track with just for testing).

Any ideas?

Re: Re: unregistered user never receive the gift cert

It's the same PHP rounding bug... the zero total method should use the method of checking values -.01 < x < .01 for a zero total instead of x == 0. Or it could use number_format() to two decimal places... I wonder if I should be doing that instead, too. Sticking out tongue

Re: Re: Re: unregistered user never receive the gift cert

This rounding bug will be the death of me Sticking out tongue

Thanks for the response, Ryan. I'll change the code and will wait to see if more issues pop up.

Re: Gift Certificate Module

does the gift certificate "have" to be used when there is money remaining on it. is it possible to allow the user to decide if they want to use it or not on a per order basis?

Re: Re: Gift Certificate Module

Currently yes, the amount is automatically deducted at checkout; but I think ideally (and this is how our old system ran) you could "choose" to pay with your gift certificate just as you would choose PayPal or Credit card, etc.

Even more ideally, I think, would be a text field for a code, which would then free up the "users to certificates" relationship. Maybe that's not an ideal situation, but I can see why some shops would not want to restrict it to users who exist in a database (like a free promotion period where a bunch of certificates are printed and distributed to potential customers).

Haven't seen TCS on here in a while and I'm not sure what his plans are for this module. (Or if something like it is being considered for inclusion in Core?)

Incorrect total sent to Paypal

I just started monkeying around with Ubercart last week and today was the first time I looked at the gift certificate module. Everything seems to be going pretty smoothly except when I opt to use a gift certificate on checkout, it shows me the correct Total, but it seems to be sending the Subtotal (before gift certificate applied) to Paypal. It also seems to do this for the latest Coupon module I've been testing, so maybe this isn't exactly related to this module. I was just hoping someone might have an idea of where to check

Re: Incorrect total sent to Paypal

Yeah this is not so much a bug, as it seems you need to setup your PayPal settings to "send the entire order as a single line item" in your Payment Methods config.

That should fix it. (I'd like to find a more permanent fix that involves being able to send the entire order line-by-line to PayPal but I don't have much time to devote at the moment ... hopefully TCS can look into it when he has a moment!)

Re: Incorrect total sent to Paypal

Yup, that worked a dream. Thanks much!

Re: Re: Re: Gift Certificate Module

Hi. Thanks for all your work on this module, TCS.

I'd like to use the module, but there are a few things I would need it to be able to do:

1. I would need to be able to set it so that the user could choose to use, or choose not to use, their gift certificate. It would be great if there was something like an 'apply gift cert' button in the checkout pane.

2. Allow non-registered users to pay with gift certificates. Associating certs with email addresses seems like a good idea, since you would have to give each cert a unique name anyway. It would be nice if a non-registered user could view the amount of their gift cert after they input their email in the checkout pane.

3. This is not necessary, but it would be great if the gift amount appeared on the user account page.

Also, when testing in Beta 1.0, the module would not let me buy a $3 item with a $10 gift cert. The message was to 'select a diff payment method;'

Thanks.

awesome module! thanks!

Installed and successfully tested. I love the way you've done away with gift certificate codes! Thank you!

Updates

Thanks for the feedback. I have been super busy with other projects. I now have time to make some improvements to the module. Just a heads up to let people know that updates are coming.

Cheers

related gift question

I don't know if the gift certificate module is what I need or not. Can you let me know? We have just four products to sell at different prices. Right now, after the purchase, a new role is assigned to that customer based on what they purchased and the downloadable file appears in My Files. But I want to be able to give away the product (i.e., make a complimentary copy of the file available in their My Files) without having to go through the store. If I assign them the new role, that doesn't give them the downloadable product. Should I be giving them a gift certificate for the full amount and ask them to "buy" the product at zero dollars? Or is there a simplier way?

Dan

Re: related gift question

You can go to user/#/edit (the # should be the User's uid) and scroll down to "File Downloads". Expand that pane, and there you can use the form to add any available file you like to their My Files area.

thanks

Ah, beautiful, thanks. I should have seen that!

Dan

Anonymous Checkout

Hi All,
Module looks good, but doesn't quite work for what we're doing. I need certificates to be quite independent from users. As in: gift certificates are essentially identified by a unique code, and users can put that code in at checkout to pay for some or all of their order. This should also work transparently for anonymous checkout.

I was wondering how exactly the order_id field is used at the moment, and whether I should invest the time making this module support what we want, or if the change in paradigm is so great that I should just start from scratch?

Cheers,
Toby

Re: Anonymous Checkout

That sounds like you need the coupon module. Letting the customer put in a code to reduce the amount they pay is exactly how it works.

Use the mysql adapter

Just a heads up, that this module relies on the function mysql_insert_id() so if you try and use the mysqli adapter for your drupal installation you'll receive an error about a failed connection to the database. I've noticed a couple other ubercart modules rely on this function (i.e. uc_importer) so I assume it's a problem with no simple solution at this point.

Certificate Not Issued

Hey everyone - I was a Drupal message "Cert not issued" when completing on order. Any guesses why? I went into the module and just deleted that error message and left the parentheses - trouble ahead?

Re: Certificate Not Issued

Really strange, does it say you have Gift Certificate amount available? (You should see it in the Gift Cert block if you've enabled it, or in the Checkout screen right above the payment method pane).

Re: Re: Certificate Not Issued

Whoa, I think I stroked out every other word of my post. I was getting the error message when completing an order WITHOUT the purchase of a gift certificate in it.

Re: Re: Re: Certificate Not Issued

Can you open an Issue in the Issue tracker? This thread is getting a bit longish Smiling

Re: Gift Certificate Module

Any updates on this? Is this module working?

Re: Re: Gift Certificate Module

Works fine for me.. did you create an Issue?