Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2012
    Posts
    331
    Plugin Contributions
    0

    Default Disallowing certain coupon codes for orders that will be giving affiliate commission

    Looking for help adding an observer to limit certain coupon codes should not work if the order is an affiliate order?
    TIA

  2. #2
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,361
    Plugin Contributions
    94

    Default Re: Disallowing certain coupon codes for orders that will be giving affiliate commiss

    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.

  3. #3
    Join Date
    Aug 2012
    Posts
    331
    Plugin Contributions
    0

    Default Re: Disallowing certain coupon codes for orders that will be giving affiliate commiss

    Thanks worked like a charm!

    Could you also please share how I would modify the code the disallow all coupons?

    Thanks so much!

  4. #4
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,361
    Plugin Contributions
    94

    Default Re: Disallowing certain coupon codes for orders that will be giving affiliate commiss

    Different problem statement => different solution. You don't need either of the above two files, just the following (/includes/modules/pages/checkout_payment/header_php_no_coupons_for_affiliates.php):
    Code:
    <?php
    if (isset ($_SESSION['referrer_key']) && zen_not_null ($_SESSION['referrer_key'])) {
      for ($i = 0, $n = count ($order_total_modules->modules); $i < $n; $i++) {
        if ($order_total_modules->modules[$i] == 'ot_coupon') {
          unset ($order_total_modules->modules[$i]);
        }
      }
      $order_total_modules->modules = array_values ($order_total_modules->modules);
    }
    This code checks to see if an affiliate commission is going to be applied to the order and, if so, totally removes the Coupon processing (so you don't even see the coupon-entry block).

 

 

Similar Threads

  1. Coupon that will issue discount on shipping
    By timhersh in forum General Questions
    Replies: 0
    Last Post: 21 Feb 2014, 03:22 AM
  2. v139h Giving USPS First-Class only for products in a certain category
    By zaaep005 in forum Addon Shipping Modules
    Replies: 36
    Last Post: 11 Dec 2013, 03:10 PM
  3. coupon codes that apply to one item only
    By MB1 in forum Setting Up Specials and SaleMaker
    Replies: 3
    Last Post: 4 Oct 2010, 04:43 PM
  4. Can I create a coupon that will be good for one time use for 50% off any one item?
    By ppruett in forum Discounts/Coupons, Gift Certificates, Newsletters, Ads
    Replies: 0
    Last Post: 13 Mar 2010, 08:10 PM
  5. WIll ZenCart place orders my affiliate programs?
    By amanamission in forum Templates, Stylesheets, Page Layout
    Replies: 6
    Last Post: 7 Aug 2008, 05:43 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR