Sorry for the delayed response. I've been working on this over the last couple of weeks. There's been a bit of discussion on this topic recently so I thought I'd post my solution. Please read the deficiencies before you give this a go.
Based on Kevin's hints in:
http://www.zen-cart.com/forum/showthread.php?t=42386
I've come up with a solution to this problem. Before I give you the code I'll outline the method and note the deficiencies.
Method:
In index.php, check for a visitor_code in the URL. If present, sanitize and sessionalize it.
In ot_coupon, instead of validating/sessionalizing a form submitted coupon code, validate/sessionalize the visitor_code. Then set visitor_code to null.
Deficiencies: This method has some major deficiencies. As it stands, there's no validation of the coupon code when the visitor arrives on your site. There's not even acknowledgment of the coupon until they get to checkout. So, if a visitor follows an outside link that promises them a discount, they will be confused until checkout_payment and/or angry if the coupon is invalid.
My solution: Outside links point to pages in my store with "Click Here to Begin Shopping Using This Coupon" links. This way I can explain the coupon details, let them know it won't show up until payment, and I can make sure that only valid coupons are provided.
Deficiency: For some reason the user is notified through the message stack twice that their coupon has been added. Once during payment and once during confirmation. My attempts to show this only during checkout_payment sent the user to checkout_payment a second time.
My solution: I settled on eliminating the message and applying <strong> to the coupon reporting in order total.
Deficiency: My method does not allow for submitting coupons via form during checkout_payment.
My solution: I removed the discount coupon field from checkout_payment. This was a feature for me, my entire goal was to remove coupon submission from checkout.
Code: Solution implemented in 1.3.7, code may or may not apply to other versions.
From /store/index.php, around line 101
Code:
<?php
/**
* Load general code run before page closes
*/
?>
Becomes:
Code:
<?php
/**
* Load general code run before page closes
*/
if (!empty($_GET['visitor_code']))
$_SESSION['visitor_code'] = trim(htmlspecialchars($_GET['visitor_code']));
?>
From /store/includes/templates/yourtemplate/templates/tpl_checkout_payment_default.tpl, around line 80:
Code:
<fieldset>
<legend><?php echo $selection[$i]['module']; ?></legend>
<?php echo $selection[$i]['redeem_instructions']; ?>
<div class="gvBal larger"><?php echo $selection[$i]['checkbox']; ?></div>
<label class="inputLabel"<?php echo ($selection[$i]['fields'][$j]['tag']) ? ' for="'.$selection[$i]['fields'][$j]['tag'].'"': ''; ?>><?php echo $selection[$i]['fields'][$j]['title']; ?></label>
<?php echo $selection[$i]['fields'][$j]['field']; ?>
</fieldset>
Becomes:
Code:
<?php if($selection[$i]['module']!=MODULE_ORDER_TOTAL_COUPON_TITLE) {?><fieldset>
<legend><?php echo $selection[$i]['module']; ?></legend>
<?php echo $selection[$i]['redeem_instructions']; ?>
<div class="gvBal larger"><?php echo $selection[$i]['checkbox']; ?></div>
<label class="inputLabel"<?php echo ($selection[$i]['fields'][$j]['tag']) ? ' for="'.$selection[$i]['fields'][$j]['tag'].'"': ''; ?>><?php echo $selection[$i]['fields'][$j]['title']; ?></label>
<?php echo $selection[$i]['fields'][$j]['field']; ?>
</fieldset><?php } ?>
Finally: /store/includes/modules/order_total/ot_coupon.php
Code:
line 54: $this->output[] = array('title' => $this->title . ': ' . '<a href="javascript:couponpopupWindow(\'' . zen_href_link(FILENAME_POPUP_COUPON_HELP, 'cID=' . $_SESSION['cc_id']) . '\')">' . $this->coupon_code . '</a> :',
Becomes: $this->output[] = array('title' => '<strong>' . $this->title . ': ' . '<a href="javascript:couponpopupWindow(\'' . zen_href_link(FILENAME_POPUP_COUPON_HELP, 'cID=' . $_SESSION['cc_id']) . '\')">' . $this->coupon_code . '</a></strong> :',
Lines 220-221:
if ($_POST['submit_redeem_coupon_x'] && !$_POST['gv_redeem_code']) zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, 'credit_class_error_code=' . $this->code . '&credit_class_error=' . urlencode(TEST_NO_REDEEM_CODE), 'SSL', true, false));
$messageStack->add_session('checkout', TEXT_VALID_COUPON,'success');
Become:
// if ($_POST['submit_redeem_coupon_x'] && !$_POST['gv_redeem_code']) zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, 'credit_class_error_code=' . $this->code . '&credit_class_error=' . urlencode(TEST_NO_REDEEM_CODE), 'SSL', true, false));
// $messageStack->add_session('checkout', TEXT_VALID_COUPON, 'success');
$_SESSION['visitor_code'] = NULL;
Lines 144-209:
Replace every instance of: $_POST['dc_redeem_code']
with: $_SESSION['visitor_code']
There's probably a cleaner and easier way to remove the Discount Coupon field.
If anyone sees a violation of proper practices, please let me know.
If anyone tries this and it doesn't work, let me know. I've done other modifications to the files above, and though I think I've isolated the coupon solution I may have gotten something else mixed in.
Hope this helps,
Joe