Jump to content

Gift certificate - valid period


fettlebox

Recommended Posts

I've just set up gift certificates on my shop & done a test purchase.

I have them set to be valid for 18 months but would like the purchaser & recipient to be aware.

Can anyone please tell me how to add this info to the product info & recipients email as the certificate expiry date doesn't currently show.

Link to comment
Share on other sites

Hello fettlebox,

Let's start by modifying the language phrase, "Gift certificates must have a minimum value...". This is found in the admin Languages screen, choose to edit the language(s) of your choice, select the catalogue group, and scroll to gift_certificate_value. (It may help to copy this phrase to a text editor, make changes there, and then copy the result back.)

You can add some thing like, "Certificates expire %3s months from the date they were purchased." The %3s is important. It is a placeholder for the actual value.

Now, in the file /classes/cubecart.class.php, at about line 713, find:

$GLOBALS['smarty']->assign('LANG_CERT_VALUES', sprintf($GLOBALS['language']->catalogue['gift_certificate_value'], $GLOBALS['tax']->priceFormat($gc['min'], true, true), $GLOBALS['tax']->priceFormat($gc['max'], true, true)));




We need to add the argument for the placeholder we just added. So,


... priceFormat($gc['max'], true, true), $gc['expires']));

This solves the explanatory text in the Gift Certificate product info page.

We still need to add this certificate's actual expiration date to the cart summary listing and purchaser's and recipient's email notices.

I'll get back to you on that.

Link to comment
Share on other sites

I've just checked it in my code again, and it works.

So, lets review:

1. Edit the language string, such as:

Gift certificates must have a minimum value of %1$s, and a maximum of %2$s. Certificates expire %3$s months from the date they were purchased. Please note that it is only possible to purchase a gift certificate in the stores main currency.

2. Edit line 713 (or there-about) in cubecart.class.php:

$GLOBALS['smarty']->assign('LANG_CERT_VALUES', sprintf($GLOBALS['language']->catalogue['gift_certificate_value'], $GLOBALS['tax']->priceFormat($gc['min'], true, true), $GLOBALS['tax']->priceFormat($gc['max'], true, true), $gc['expires']));

Note also that stores main currency is a punctuation error. Don't try to add an apostrophe just yet.

Link to comment
Share on other sites

OK

As per 1 above I have copied & pasted that as the language string.

Same with 2. The site then returns an entirely blank page in Firefox/Ubuntu - in IE/XP it returns a 500 error.

There's one less closed bracket in the line 713 code in the 2nd snippet when compared to the first. If I add the third ) the site comes back but with no info on the gift certificate page about value, time or currency.

Link to comment
Share on other sites

Yes, this 511. I upgraded maybe a week to ten days ago.


// Validate email if email delivery

   if (strtolower($_POST['gc']['method']) == 'e' && !filter_var($_POST['gc']['email'], FILTER_VALIDATE_EMAIL)) {

    $GLOBALS['gui']->setError($GLOBALS['language']->catalogue['error_gc_email']);

    $error = true;

   }

   if (!$error) {

    $GLOBALS['cart']->add($gc['product_code'], $_POST['gc']);

   } else {

    $GLOBALS['smarty']->assign('POST', $_POST['gc']);

   }

  }

  $GLOBALS['smarty']->assign('LANG_CERT_VALUES', sprintf($GLOBALS['language']->catalogue['gift_certificate_value'], $GLOBALS['tax']->priceFormat($gc['min'], true, true), $GLOBALS['tax']->priceFormat($gc['max'], true, true, $gc['expires'])));

  $ctrl_allow_purchase = ($GLOBALS['session']->get('hide_prices')) ? false : true;

  $GLOBALS['smarty']->assign('ctrl_allow_purchase', $ctrl_allow_purchase);

  $GLOBALS['smarty']->assign('GC', $gc);

  $content = $GLOBALS['smarty']->fetch('templates/content.certificates.php');

  $GLOBALS['smarty']->assign('SECTION_NAME', 'giftcertificate');

  $GLOBALS['smarty']->assign('PAGE_CONTENT', $content);

Link to comment
Share on other sites

If I've removed the right ) this is what I have now.This give me a blank page (admin panel still accessible) http://www.fettlebox.co.uk/


// Validate email if email delivery

   if (strtolower($_POST['gc']['method']) == 'e' && !filter_var($_POST['gc']['email'], FILTER_VALIDATE_EMAIL)) {

	$GLOBALS['gui']->setError($GLOBALS['language']->catalogue['error_gc_email']);

	$error = true;

   }

   if (!$error) {

	$GLOBALS['cart']->add($gc['product_code'], $_POST['gc']);

   } else {

	$GLOBALS['smarty']->assign('POST', $_POST['gc']);

   }

  }

  $GLOBALS['smarty']->assign('LANG_CERT_VALUES', sprintf($GLOBALS['language']->catalogue['gift_certificate_value'], $GLOBALS['tax']->priceFormat($gc['min'], true, true), $GLOBALS['tax']->priceFormat($gc['max'], true, true, $gc['expires']));

  $ctrl_allow_purchase = ($GLOBALS['session']->get('hide_prices')) ? false : true;

  $GLOBALS['smarty']->assign('ctrl_allow_purchase', $ctrl_allow_purchase);

  $GLOBALS['smarty']->assign('GC', $gc);

  $content = $GLOBALS['smarty']->fetch('templates/content.certificates.php');

  $GLOBALS['smarty']->assign('SECTION_NAME', 'giftcertificate');

  $GLOBALS['smarty']->assign('PAGE_CONTENT', $content);

Link to comment
Share on other sites

Move, not Remove. The first line of code in my instruction above indicates the red parenthesis to move to the green parenthesis position in the second line of code.

It's:

['max'] - comma - true - comma - true - close parenthesis - comma - $gc['expires'] - close parenthesis - close parenthesis - semi-colon.

Link to comment
Share on other sites

Ok, now that we got the informational dialog adapted to your needs, we shall now proceed to finding and modifying the email to state a phrase that reads something like:

"This gift certificate expires (the actual date that is calculated from the date of the Gift Certificate purchase plus 548 days - that's 18 months)."

I'll get back to you on that.

Link to comment
Share on other sites

Well, after much digesting of the code, I believe that the Gift Card expiration date is already available to the email template. I will give instructions on how to add that to the place where the email template is edited. However...

I believe there to be a bug that causes the value of the card to fail to be retrieved from the database. Thus, any expression in the template that includes the value will end up being like, "The certificate has _ loaded onto it." where the underscore is simply a blank space.

Has anyone ever had a Gift Certificate purchased as of yet?

Fettlebox, what did the email to the recipient look like? Did it show the amount?

Link to comment
Share on other sites

Without explaining too deeply about what you will be reading, these are instructions for adding the expiration date to the template used to send an email to the recipient of a Gift Certificate purchased at your store.

The first step is to add to the array of language phrases the describe to the admin what is available to include in the template.

To change the Gift Certificate email:

Admin screens, click on the link Email Templates (under File Manager).

On the Email Contents tab, click on the flag for Cart: Gift Certificate in the language you want to change.

On the HTML Content tab, examine the table of Available Macros. This table comes from an array in the file /admin/sources/documents.email.inc.php, at about line 83.

The array (and thus the Macro table) is disconnected from the whole process, other than displaying in the language of the store in giving descriptions for what data is available. Changing this array does not change what data is available and changing the data that is available does not change this array. Let's add a new description to the array, remembering we will also have to add a language string and also add to the available data - if it's not already available. (It would be nice to be able to add to this list without editing a file.)

Find this:

'{$DATA.message}' => $lang['email']['macro_sender_message'],

Add After:

'{DATA.expires}' => $lang['email']['macro_cert_expiry_date'],

The $lang array comes from XML elements in the file /language/definitions.xml with matching entries in the other language files. (It would be nice to be able to add new phrases to languages without editing files.)

Find this (it's alphabetical, so that should make things easier):

<group name="email">

Then find this just below that:

<string name="macro_cert_code" introduced="5.0.0"><![CDATA[The certificate's redemption code.]]></string>

Add After:

<string name="macro_cert_expiry_date"><![CDATA[The certificate's expiration date.]]></string>

As I said, the expiry date should already be available. According to the code, this is what should be available:

$_order_summary: Everything about the actual completed purchase but without the list of items in this purchase.

$array: The info provided in the form the purchaser filled out when purchasing the gift certificate: Value, Delivery Method (as enabled), Recipient Name, Recipient email, Optional Message.

$coupon[0]: cart_order_id, claim code, discount_price(will be gift cert value but will be reduced as used), expires(in Y-m-d format), and about 10 other unuseful pieces of info.

So, given all that, instructions to add rows to the table of Available Macros and the assertion that there is plenty more data available to put in the template, should provide you with the means to add to the table almost whatever you want.

This discrepancy between what is available and what is indicated to be available is disheartening. I hope Devellion revamps the Available Macro hint table.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...