You'll need two files to accomplish this. First, /includes/auto_loaders/config.limit_coupons.php:
Code:
<?php
$autoLoadConfig[200][] = array('autoType'=>'class',
'loadFile'=>'observers/class.limit_coupons_observer.php');
$autoLoadConfig[200][] = array('autoType'=>'classInstantiate',
'className'=>'limit_coupons_observer',
'objectName'=>'limit_coupons_observer');
That file instructs the Zen Cart base code to load the actual processing code (/includes/classes/observers/class.limit_coupons_observer.php):
Code:
<?php
if (!defined('IS_ADMIN_FLAG')) {
die('Illegal Access');
}
define ('NO_COUPONS_FOR_AFFILIATE_PURCHASES', 'list,of,coupon,codes,separated,by,commas');
class limit_coupons_observer extends base {
function __construct() {
$this->coupons_limited = explode (',', NO_COUPONS_FOR_AFFILIATE_PURCHASES);
$this->attach ($this, array ( 'NOTIFY_HEADER_END_CHECKOUT_CONFIRMATION' ));
}
function update (&$class, $eventID, $p1) {
global $messageStack, $ot_coupon;
if (isset ($_SESSION['referrer_key']) && zen_not_null ($_SESSION['referrer_key']) && isset ($_POST['dc_redeem_code']) && in_array ($_POST['dc_redeem_code'], $this->coupons_limited)) {
$messageStack->add_session ('redemptions', TEXT_INVALID_REDEEM_COUPON, 'caution');
$ot_coupon->clear_posts ();
zen_redirect (zen_href_link (FILENAME_CHECKOUT_PAYMENT, '', 'SSL', true, false));
}
}
}
This code processes at the very end of the pre-checking code for the checkout_confirmation page (which is the first place a coupon code is inspected). Essentially, the processing checks for the 'referrer_key' which indicates that any order will be a candidate for a SNAP Affiliate's commission. If the order qualifies for a commission, the next check is to see if the coupon-code is one of the "not allowed" ones and, if so, a message indicating that the coupon code is invalid is recorded and the customer is sent back to the checkout_payment page.
Bookmarks