Results 1 to 9 of 9
  1. #1
    Join Date
    Mar 2007
    Posts
    248
    Plugin Contributions
    6

    Default Coupon Restriction for Specials - Solution

    Perhaps best for someone to package and put in dowmloads section and get all the glory , just too busy at the moment to do it, but thought i would share a little mod to enable you to restrict a coupon from all items on special.
    Its pretty basic in how it works, just two buttons added to the coupon restrictions page, an add and remove button.

    The add button will search all products currently on special and will list them in the products retricted area, for that coupon for you.
    the remove button removes all restricted products, that are on special for that coupon, from the restricted products.

    File to change is /admin/coupon_restrict.php

    The above is a core file so care to be taken, as always backup before performing any mod.

    around line 36:

    After:
    Code:
     where restrict_id = '" . $_GET['info'] . "'");
        }
      }
    add:
    Code:
    if ($_GET['action']=='specials')  {
    $new_products_query = "select products_id from " . TABLE_SPECIALS . "  where status = 1 and products_id not in (select product_id from " . TABLE_COUPON_RESTRICT . " where coupon_id = '" . $_GET['cid'] . "')";
    $new_products = $db->Execute($new_products_query);
    
    while(!$new_products->EOF) {
    // add all products from specials for each product not already defined in coupons_restrict
    $db->Execute("insert into " . TABLE_COUPON_RESTRICT . " (coupon_id, product_id, coupon_restrict) values ('" . $_GET['cid'] . "', '" . $new_products->fields['products_id'] . "', 'Y')");
    $new_products->MoveNext();
     }
    }  
    
    //remove specials
    if ($_GET['action']=='remove_specials')  {
     // to delete existing products from coupon code that are selected as specials coupon_code that are already in the table
    $new_products_query = "select products_id from " . TABLE_SPECIALS . "  where status = 1 and products_id in (select product_id from " . TABLE_COUPON_RESTRICT . " where coupon_id = '" . $_GET['cid'] . "')";
    $new_products = $db->Execute($new_products_query);
     
    // nothing to be done
              if ($new_products->RecordCount() == 0) {
                $messageStack->add(ERROR_DISCOUNT_COUPON_DEFINED_CATEGORY . ' ' . $_POST['cPath'], 'caution');
              }
              while(!$new_products->EOF) {
                // product needs to be deleted
              $db->Execute("delete from " . TABLE_COUPON_RESTRICT . " WHERE coupon_id = '" . $_GET['cid'] . "' and product_id = '" . $new_products->fields['products_id'] . "'");
                $new_products->MoveNext();
              }  
    }
    around line 387

    After:
    Code:
    <!-- body_text_eof //-->
      </tr>
    </table>
    add:

    Code:
    <form name="restrict_specials" method="post" action="<?php echo zen_href_link('coupon_restrict.php', zen_get_all_get_params(array('info', 'action', 'x', 'y')) . 'action=specials&info=' . $cInfo->restrict_id, 'NONSSL'); ?>"><?php echo zen_draw_hidden_field('securityToken', $_SESSION['securityToken']); ?>
    <input type="submit" name="add" value="Add Specials">
    </form>
    <form name="remove_specials" method="post" action="<?php echo zen_href_link('coupon_restrict.php', zen_get_all_get_params(array('info', 'action', 'x', 'y')) . 'action=remove_specials&info=' . $cInfo->restrict_id, 'NONSSL'); ?>"><?php echo zen_draw_hidden_field('securityToken', $_SESSION['securityToken']); ?>
    <input type="submit" name="add" value="Remove Specials">
    </form>

    and that's it.

  2. #2
    Join Date
    Jan 2009
    Posts
    84
    Plugin Contributions
    0

    Default Re: Coupon Restriction for Specials - Solution

    Version 1.5


    Thanks fo your contribution. But I tried this and it did not work to restrict the coupon on a special. There are actually 2 instances of where restrict_id = '" . $_GET

    ['info'] . "'");
    }
    }

    I tried both places and did not work. Is there another trick to this?


    Thanks!

  3. #3
    Join Date
    Mar 2007
    Posts
    248
    Plugin Contributions
    6

    Default Re: Coupon Restriction for Specials - Solution

    You need to follow the instructions, no point putting code where it isn't needed.

    You need to give me more info, what aspect isn't working?
    Are the buttons shown?
    Do they add products when you click to add them?
    Do you have any products on special/discount at the moment?
    After adding the products,usig the button, they still allowed to have a discount coupon working on them?

    Its a really simple mod, so there really isn't much to go wrong.

  4. #4
    Join Date
    Feb 2012
    Posts
    19
    Plugin Contributions
    0

    Default Re: Coupon Restriction for Specials - Solution

    Worked perfectly for me thank you!!!
    If anyone's trying it, remember that once you've pasted in the first block; for the second chunk, line 387 is no longer at line 387 as you've added several lines above it with the first paste (was line 414 on mine).

  5. #5
    Join Date
    Apr 2009
    Posts
    2,134
    Plugin Contributions
    3

    Default Re: Coupon Restriction for Specials - Solution

    Or if you just want to exclude all specials from the Coupon Order Total calculations you could just go to includes/modules/order_total/ot_coupon.php and do something like this:

    Change line 470ish

    Code:
    if (!is_product_valid($products[$i]['id'], $couponCode)) {
    to:

    Code:
    $specials_price = zen_get_products_special_price($products[$i]['id'], true);
    if (!is_product_valid($products[$i]['id'], $couponCode) or $specials_price) {
    Which stops you having to change the restrictions every time you change a special.

  6. #6
    Join Date
    Mar 2007
    Posts
    248
    Plugin Contributions
    6

    Default Re: Coupon Restriction for Specials - Solution

    Someone recently pointed me back to this thread. the post above didn't work for them or me, but if I want to exclude all specials, easier to add a line to includes/functions/functions_general.php

    around line 814 inside the "is_product_valid" function,

    add under this line:

    if ($coupons->RecordCount() == 0) return true;

    Code:
    $specials_price = zen_get_products_special_price((int)$product_id , true);
    if ($specials_price) return false;
    if your are using the bundles mod, you can also add:

    Code:
    if (isBundle((int)$product_id))  return false;
    Hope this helps people out.

  7. #7
    Join Date
    Mar 2007
    Posts
    248
    Plugin Contributions
    6

    Default Re: Coupon Restriction for Specials - Solution

    just an update, noticed that specials created under "salemaker" were not being restricted.

    If you want to restrict those then add following line under the others above:

    //if product in salemaker category
    $product_check = $db->Execute("select master_categories_id from " . TABLE_PRODUCTS . " where products_id = '" . $product_id . "'");
    $category_check = $product_check->fields['master_categories_id'];

    $saler = $db->Execute("select sale_specials_condition, sale_deduction_value, sale_deduction_type from " . TABLE_SALEMAKER_SALES . " where sale_categories_all like '%," . $category_check . ",%' and sale_status = '1' and (sale_date_start <= now() or sale_date_start = '0001-01-01') and (sale_date_end >= now() or sale_date_end = '0001-01-01')");
    if ($saler->RecordCount() >= 1) {
    return false;
    }

  8. #8
    Join Date
    Feb 2014
    Location
    The Netherlands
    Posts
    58
    Plugin Contributions
    0

    help question Re: Coupon Restriction for Specials - Solution

    I'm afraid non of the solutions work for me... I don't get any error messages, but nothing changes either.

    By the way, the is_product_valid function is on 769 for me. I'm running Zen Cart v 1.5.1.

  9. #9
    Join Date
    Jun 2010
    Posts
    32
    Plugin Contributions
    0

    Default Re: Coupon Restriction for Specials - Solution

    Quote Originally Posted by niccol View Post
    Or if you just want to exclude all specials from the Coupon Order Total calculations you could just go to includes/modules/order_total/ot_coupon.php and do something like this:

    Change line 470ish

    Code:
    if (!is_product_valid($products[$i]['id'], $couponCode)) {
    to:

    Code:
    $specials_price = zen_get_products_special_price($products[$i]['id'], true);
    if (!is_product_valid($products[$i]['id'], $couponCode) or $specials_price) {
    Which stops you having to change the restrictions every time you change a special.
    The above is what I just used. I added the following right after line 488 in includes/modules/order_total/ot_coupon.php:
    Code:
    // BOF Specials Coupon Restriction
    	$specials_price = zen_get_products_special_price($products[$i]['id'], true);
    if (!is_product_valid($products[$i]['id'], $couponCode) or $specials_price) {
    // EOF Specials Coupon Restriction
    The good news? Items not on special get their discounts while items on special do not, even when it's a mixed cart.

    The bad news? There is no alert to tell the customer an item is being excluded, in fact it still gives the green A.O.K message.

    The workaround? For now, I have appended a short notice to the TEXT_VALID_COUPON, which now reads:

    Code:
    //	BOF Edited TEXT_VALID_COUPON to add special restriction notice.
    //	BOF Commented out for posterity
    //	define('TEXT_VALID_COUPON', 'Congratulations you have redeemed the Discount Coupon.');
    //	EOF Commented out for posterity
    
    	define('TEXT_VALID_COUPON', 'Congratulations you have redeemed the Discount Coupon. Keep in mind that if your order contains items on special, the discount will not be applied for those items.');
    
    //	EOF Edited TEXT_VALID_COUPON to add special restriction notice.
    This is almost perfect but just not quite.

    FYI: We are using v1.5.4

 

 

Similar Threads

  1. v138a Restriction to specials for cuopons
    By navido in forum General Questions
    Replies: 1
    Last Post: 3 Nov 2013, 12:53 AM
  2. Coupon Restriction
    By enzo-ita in forum General Questions
    Replies: 2
    Last Post: 29 Nov 2010, 09:28 AM
  3. Coupon for already reduced item (specials)
    By brooklyn44 in forum Discounts/Coupons, Gift Certificates, Newsletters, Ads
    Replies: 0
    Last Post: 3 Sep 2009, 03:35 PM
  4. Coupon and Specials restriction
    By jeking in forum Discounts/Coupons, Gift Certificates, Newsletters, Ads
    Replies: 2
    Last Post: 4 Sep 2008, 08:14 PM
  5. Coupon restriction logic
    By dbrewster in forum Discounts/Coupons, Gift Certificates, Newsletters, Ads
    Replies: 3
    Last Post: 3 Jul 2006, 06:42 PM

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