Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16
  1. #11
    Join Date
    Jan 2007
    Location
    Australia
    Posts
    6,167
    Plugin Contributions
    7

    Default Re: Coupon behavior changed between 1.3.8 and 1.5.1?

    Quote Originally Posted by Ajeh View Post
    I will try to look at this when I have some free time ...
    What's this thing called 'free time' that you mention? Is it a free download? If not, where can I buy some? :-)

    Cheers
    RodG

  2. #12
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default Re: Coupon behavior changed between 1.3.8 and 1.5.1?

    I have been looking for a coupon for Free Time for a long while ... not yet located one ...
    Linda McGrath
    If you have to think ... you haven't been zenned ...

    Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!

    Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today: v1.5.5]
    Officially PayPal-Certified! Just click here

    Try our Zen Cart Recommended Services - Hosting, Payment and more ...
    Signup for our Announcements Forums to stay up to date on important changes and updates!

  3. #13
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default Re: Coupon behavior changed between 1.3.8 and 1.5.1?

    A temporary fix would be to change line 190 in the file:
    /includes/modules/order_total/ot_coupon.php

    Code:
    // left for total order amount vs qualified order amount just switch the commented lines
    //        if ($order_total['totalFull'] < $coupon_result->fields['coupon_minimum_order']) {
    //        if (strval($order_total['orderTotal']) < $coupon_result->fields['coupon_minimum_order']) {
            if ($coupon_result->fields['coupon_minimum_order'] > 0 && strval($order_total['orderTotal']) < $coupon_result->fields['coupon_minimum_order']) {
    
              $messageStack->add_session('redemptions', sprintf(TEXT_INVALID_REDEEM_COUPON_MINIMUM, $currencies->format($coupon_result->fields['coupon_minimum_order'])),'caution');
              $this->clear_posts();
              zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL',true, false));
    Which will skip that message if the coupon Minimum is not set and show the message for nothing qualified ...
    Linda McGrath
    If you have to think ... you haven't been zenned ...

    Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!

    Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today: v1.5.5]
    Officially PayPal-Certified! Just click here

    Try our Zen Cart Recommended Services - Hosting, Payment and more ...
    Signup for our Announcements Forums to stay up to date on important changes and updates!

  4. #14
    Join Date
    Jan 2007
    Location
    Australia
    Posts
    6,167
    Plugin Contributions
    7

    Default Re: Coupon behavior changed between 1.3.8 and 1.5.1?

    Quote Originally Posted by Ajeh View Post
    Which will skip that message if the coupon Minimum is not set and show the message for nothing qualified ...

    That is only a part of the solution though. What about the case where a coupon minimum *is* set (say for $100.00) but there are no products in the cart eligible for the discount (for example, when the coupon is also restricted by product or category), but the cart also contains other products to the value of (say) $200.00


    In this case the customer is going to be given a message like 'You must spend a minimum of $100.00 to redeem this coupon" rather than the more accurate response of "THIS COUPON CODE IS NOT VALID FOR ANY PRODUCT CURRENTLY IN YOUR CART".


    Also, I think I owe you an apology, I wasn't really asking you for a solution (I already have one that appears to work). I was merely trying to explain the issue.


    FWIW though, this is how I took care of it.


    Code:
    function collect_posts() {
        global $db, $currencies, $messageStack, $order;
        global $discount_coupon;
        // remove discount coupon by request
        if (isset($_POST['dc_redeem_code']) && strtoupper($_POST['dc_redeem_code']) == 'REMOVE') {
          unset($_POST['dc_redeem_code']);
          unset($_SESSION['cc_id']);
          $messageStack->add_session('checkout_payment', TEXT_REMOVE_REDEEM_COUPON, 'caution');
        }
    //    print_r($_SESSION);
        // bof: Discount Coupon zoned always validate coupon for payment address changes
        // eof: Discount Coupon zoned always validate coupon for payment address changes
        if ((isset($_POST['dc_redeem_code']) && $_POST['dc_redeem_code'] != '') || (isset($discount_coupon->fields['coupon_code']) && $discount_coupon->fields['coupon_code'] != '')) {
          // set current Discount Coupon based on current or existing
          if (isset($_POST['dc_redeem_code']) && $discount_coupon->fields['coupon_code'] == '') {
            $dc_check = $_POST['dc_redeem_code'];
          } else {
            $dc_check = $discount_coupon->fields['coupon_code'];
          }
    
    
    
    
    
    
          $sql = "select coupon_id, coupon_amount, coupon_type, coupon_minimum_order, uses_per_coupon, uses_per_user,
                  restrict_to_products, restrict_to_categories, coupon_zone_restriction
                  from " . TABLE_COUPONS . "
                  where coupon_code= :couponCodeEntered
                  and coupon_active='Y'
                  and coupon_type !='G'";
    
    
          $sql = $db->bindVars($sql, ':couponCodeEntered', $dc_check, 'string');
    
    
          $coupon_result=$db->Execute($sql);
    
    
          if ($coupon_result->fields['coupon_type'] != 'G') {
    
    
            if ($coupon_result->RecordCount() < 1 ) {
              $messageStack->add_session('redemptions', TEXT_INVALID_REDEEM_COUPON,'caution');
              $this->clear_posts();
              zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL',true, false));
            }
            $order_total = $this->get_order_total($coupon_result->fields['coupon_id']);
    
    
    // left for total order amount vs qualified order amount just switch the commented lines
    //        if ($order_total['totalFull'] < $coupon_result->fields['coupon_minimum_order']) {
    //        if (strval($order_total['orderTotal']) < $coupon_result->fields['coupon_minimum_order']) {
    //
    //          $messageStack->add_session('redemptions', sprintf(TEXT_INVALID_REDEEM_COUPON_MINIMUM, $currencies->format($coupon_result->fields['coupon_minimum_order'])),'caution');
    //          $this->clear_posts();
    //          zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL',true, false));
    //        }
    
    
            // JTD - added missing code here to handle coupon product restrictions
            // look through the items in the cart to see if this coupon is valid for any item in the cart
            $products = $_SESSION['cart']->get_products();
            $foundvalid = true;
    
    
            if ($foundvalid == true) {
              $foundvalid = false;
              for ($i=0; $i<sizeof($products); $i++) {
                if (is_product_valid($products[$i]['id'], $coupon_result->fields['coupon_id'])) {
                  $foundvalid = true;
                  continue;
                }
              }
            }
    
    
            if (!$foundvalid) {
              $this->clear_posts();
            }
    
    
            if (!$foundvalid) zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, 'credit_class_error_code=' . $this->code . '&credit_class_error=' . urlencode(TEXT_INVALID_COUPON_PRODUCT . ' ' . $dc_check), 'SSL',true, false));
            // JTD - end of additions of missing code to handle coupon product restrictions
    
    
            $date_query=$db->Execute("select coupon_start_date from " . TABLE_COUPONS . "
                                      where coupon_start_date <= now() and
                                      coupon_code='" . zen_db_prepare_input($dc_check) . "'");
    
    
            if ($date_query->RecordCount() < 1 ) {
              $messageStack->add_session('redemptions', TEXT_INVALID_STARTDATE_COUPON,'caution');
              $this->clear_posts();
              zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL', true, false));
            }
    
    
            $date_query=$db->Execute("select coupon_expire_date from " . TABLE_COUPONS . "
                                      where coupon_expire_date >= now() and
                                      coupon_code='" . zen_db_prepare_input($dc_check) . "'");
    
    
            if ($date_query->RecordCount() < 1 ) {
              $messageStack->add_session('redemptions', TEXT_INVALID_FINISHDATE_COUPON,'caution');
              $this->clear_posts();
              zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL', true, false));
            }
    
    
            $coupon_count = $db->Execute("select coupon_id from " . TABLE_COUPON_REDEEM_TRACK . "
                                          where coupon_id = '" . (int)$coupon_result->fields['coupon_id']."'");
    
    
            $coupon_count_customer = $db->Execute("select coupon_id from " . TABLE_COUPON_REDEEM_TRACK . "
                                                   where coupon_id = '" . $coupon_result->fields['coupon_id']."' and
                                                   customer_id = '" . (int)$_SESSION['customer_id'] . "'");
    
    
            if ($coupon_count->RecordCount() >= $coupon_result->fields['uses_per_coupon'] && $coupon_result->fields['uses_per_coupon'] > 0) {
              $messageStack->add_session('redemptions', TEXT_INVALID_USES_COUPON . $coupon_result->fields['uses_per_coupon'] . TIMES ,'caution');
              $this->clear_posts();
              zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL', true, false));
            }
    
    
            if ($coupon_count_customer->RecordCount() >= $coupon_result->fields['uses_per_user'] && $coupon_result->fields['uses_per_user'] > 0) {
              $messageStack->add_session('redemptions', sprintf(TEXT_INVALID_USES_USER_COUPON, $dc_check) . $coupon_result->fields['uses_per_user'] . ($coupon_result->fields['uses_per_user'] == 1 ? TIME : TIMES) ,'caution');
              $this->clear_posts();
              zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL', true, false));
            }
    
    
            $_SESSION['cc_id'] = $coupon_result->fields['coupon_id'];
            if ($_SESSION['cc_id'] > 0) {
              $sql = "select coupon_id, coupon_amount, coupon_type, coupon_minimum_order, uses_per_coupon, uses_per_user,
                      restrict_to_products, restrict_to_categories, coupon_zone_restriction, coupon_code
                      from " . TABLE_COUPONS . "
                      where coupon_id= :couponIDEntered
                      and coupon_active='Y'";
              $sql = $db->bindVars($sql, ':couponIDEntered', $_SESSION['cc_id'], 'string');
    
    
              $coupon_result=$db->Execute($sql);
    
    
              $foundvalid = true;
    
    
              $check_flag = false;
    
    
              // base restrictions zone restrictions for Delivery or Billing address
              switch($coupon_result->fields['coupon_type']) {
                case 'S': // shipping
                  // use delivery address
                  $check_zone_country_id = $order->delivery['country']['id'];
                  break;
                case 'F': // amount
                  // use billing address
                  $check_zone_country_id = $order->billing['country']['id'];
                  break;
                case 'O': // amount off and free shipping
                  // use delivery address
                  $check_zone_country_id = $order->delivery['country']['id'];
                  break;
                case 'P': // percentage
                  // use billing address
                  $check_zone_country_id = $order->billing['country']['id'];
                  break;
                case 'E': // percentage and Free Shipping
                  // use delivery address
                  $check_zone_country_id = $order->delivery['country']['id'];
                  break;
                default:
                  // use billing address
                  $check_zone_country_id = $order->billing['country']['id'];
                  break;
              }
    
    
    //          $sql = "select zone_id, zone_country_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . $coupon_result->fields['coupon_zone_restriction'] . "' and zone_country_id = '" . $order->billing['country']['id'] . "' order by zone_id";
              $sql = "select zone_id, zone_country_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . $coupon_result->fields['coupon_zone_restriction'] . "' and zone_country_id = '" . $check_zone_country_id . "' order by zone_id";
              $check = $db->Execute($sql);
    
    
              // base restrictions zone restrictions for Delivery or Billing address
              switch($coupon_result->fields['coupon_type']) {
                case 'S': // shipping
                  // use delivery address
                  $check_zone_id = $order->delivery['zone_id'];
                  break;
                case 'F': // amount
                  // use billing address
                  $check_zone_id = $order->billing['zone_id'];
                  break;
                case 'O': // amount off and free shipping
                  // use delivery address
                  $check_zone_id = $order->delivery['zone_id'];
                  break;
                case 'P': // percentage
                  // use billing address
                  $check_zone_id = $order->billing['zone_id'];
                  break;
                case 'E': // percentage and free shipping
                  // use delivery address
                  $check_zone_id = $order->delivery['zone_id'];
                  break;
                default:
                  // use billing address
                  $check_zone_id = $order->billing['zone_id'];
                  break;
              }
    
    
              if ($coupon_result->fields['coupon_zone_restriction'] > 0) {
                while (!$check->EOF) {
                  if ($check->fields['zone_id'] < 1) {
                    $check_flag = true;
                    break;
    //              } elseif ($check->fields['zone_id'] == $order->billing['zone_id']) {
                  } elseif ($check->fields['zone_id'] == $check_zone_id) {
                    $check_flag = true;
                    break;
                  }
                  $check->MoveNext();
                }
                $foundvalid = $check_flag;
              }
              // remove if fails address validation
              if (!$foundvalid) {
                $messageStack->add_session('checkout_payment', TEXT_REMOVE_REDEEM_COUPON_ZONE, 'caution');
                $this->clear_posts();
                if (!$foundvalid) zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL',true, false));
              } else {
              //      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('checkout', TEXT_VALID_COUPON,'success');
              }
            }
          } else {
            $messageStack->add_session('redemptions', TEXT_INVALID_REDEEM_COUPON,'caution');
            $this->clear_posts();
            zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL',true, false));
          }
    
    
        }
          // left for total order amount vs qualified order amount just switch the commented lines
    //       if ($order_total['totalFull'] < $coupon_result->fields['coupon_minimum_order']) {
            if (strval($order_total['orderTotal']) < $coupon_result->fields['coupon_minimum_order']) {
    
    
              $messageStack->add_session('redemptions', sprintf(TEXT_INVALID_REDEEM_COUPON_MINIMUM, $currencies->format($coupon_result->fields['coupon_minimum_order'])),'caution');
              $this->clear_posts();
              zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL',true, false));
            }
      }

    I commented out the code in RED, and pasted a copy of it as the BLUE.


    I'm not saying this is the best solution, just an easy one that appears to work with no side effects (that I'm aware of).


    Cheers
    RodG

  5. #15
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default Re: Coupon behavior changed between 1.3.8 and 1.5.1?

    Missed that one ...

    v1.6 is smarter ...

    If there are no qualifying Products in the cart and a minimum is set the message would be:
    This coupon code is not valid for any product currently in your cart.
    Plus there is a link to the Discount Coupon information in a popup link ...

    If there is a qualifying Product in the cart with other Products that made the minimum, but were not qualifying Products the message would be:
    You must spend at least $75.00 to redeem this coupon
    Plus there is a link to the Discount Coupon information in a popup link ...

    I have not tried your fix for v1.5.4, but so far it looks pretty good ... another when some Free Time, I will try to play with it and break ... er ... test it ...
    Linda McGrath
    If you have to think ... you haven't been zenned ...

    Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!

    Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today: v1.5.5]
    Officially PayPal-Certified! Just click here

    Try our Zen Cart Recommended Services - Hosting, Payment and more ...
    Signup for our Announcements Forums to stay up to date on important changes and updates!

  6. #16
    Join Date
    Jan 2007
    Location
    Australia
    Posts
    6,167
    Plugin Contributions
    7

    Default Re: Coupon behavior changed between 1.3.8 and 1.5.1?

    Quote Originally Posted by Ajeh View Post
    Missed that one ...

    If there are no qualifying Products in the cart and a minimum is set the message would be:

    Plus there is a link to the Discount Coupon information in a popup link ...

    If there is a qualifying Product in the cart with other Products that made the minimum, but were not qualifying Products the message would be:

    Plus there is a link to the Discount Coupon information in a popup link ...

    I have not tried your fix for v1.5.4, but so far it looks pretty good ... another when some Free Time, I will try to play with it and break ... er ... test it ...
    Yup, those are the messages I'm getting under those conditions with the changes I made :)

    I'm not getting links for the popups though. Possibly because this site is using the COWOA mod (just guessing).

    None of my other clients have reported this as being an issue/bug (probably because they either don't use Coupons, or if they do, they haven't applied any category/product limits (plus the fact that few customers would bother to report the problem if/when they work the way around it).

    In short, it probably isn't worth spending any time with it on the currently affected versions (which could, in theory go way back to V1.3.x) and this thread could suffice for the few that do experience the problem).

    Cheers
    RodG

 

 
Page 2 of 2 FirstFirst 12

Similar Threads

  1. v139h Difference between 'Uses per Coupon' and 'Uses per Customer' in coupon definitions
    By isaiah36 in forum Discounts/Coupons, Gift Certificates, Newsletters, Ads
    Replies: 2
    Last Post: 12 Jan 2013, 06:34 PM
  2. Analytics report changed between versions?
    By Ceoloptera in forum General Questions
    Replies: 1
    Last Post: 4 Oct 2012, 03:45 AM
  3. changing sub-menu color and behavior
    By ilsita in forum Templates, Stylesheets, Page Layout
    Replies: 7
    Last Post: 10 Oct 2009, 05:03 PM
  4. Differet behavior in css between english and swedish language
    By malci in forum Addon Language Packs
    Replies: 0
    Last Post: 22 Aug 2008, 10:54 AM
  5. Differet behavior in css between the languages
    By malci in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 22 Aug 2008, 10:49 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