Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Problem with Discount Codes - error notifications.


Guest

Recommended Posts

The following types of codes do not generate an error message to alert the user:

 

1. User does not meet the Minimum Order requirement for that particular discount code

2. User does not meet the Valid Product requirement.

3. User does not meet the Valid Category requirement.

 

Granted, the discount code is not applied - but the user is not notified that there discount wasn't applied.

 

Another error,

catalog/includes/modules/order_total/ot_coupon.php

line 73ish

 

$selection_string .= ' <td align="right"' . $image_submit . '</td>';

 

shouldn't it be

 

$selection_string .= ' <td align="right">' . $image_submit . '</td>';

 

?? With the '>' in there - the redeem button shows up, otherwise it doesn't. Granted I still get the same errors with or without the redeem button.

 

Any help with these error messages would be greatly, greatly appreciated.

 

SMurphy

Link to comment
Share on other sites

I think I solved the problem - I changed the collect_posts function in catalog/includes/modules/order_total/ot_coupon.php to the following:

 

(ignore all my TEST markings, they just help identify which codes areas apply to which errors)

 

  function collect_posts() {

   global $HTTP_POST_VARS, $customer_id, $currencies, $cc_id, $order;

//	,$order	added 

   if ($HTTP_POST_VARS['gv_redeem_code']) {



// get some info from the coupon table

     $coupon_query=tep_db_query("select coupon_id, coupon_amount, coupon_type, coupon_minimum_order, 

                                      uses_per_coupon, uses_per_user, restrict_to_products, 

                                      restrict_to_categories from " . TABLE_COUPONS . " 

                                      where coupon_code='".$HTTP_POST_VARS['gv_redeem_code']."' 

                                      and coupon_active='Y'");

     $coupon_result=tep_db_fetch_array($coupon_query);



     if ($coupon_result['coupon_type'] != 'G') {



       //TEST4 - this is an invalid coupon code

 if (tep_db_num_rows($coupon_query)==0) {

         tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'error_message=' . urlencode(ERROR_NO_INVALID_REDEEM_COUPON), 'SSL'));

       }

 //END TEST4



       //TEST9 - has this coupon been activated yet?

 $date_query=tep_db_query("select coupon_start_date from " . TABLE_COUPONS . " 

                               where coupon_start_date <= now() and 

                               coupon_code='".$HTTP_POST_VARS['gv_redeem_code']."'");



       if (tep_db_num_rows($date_query)==0) {

         tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'error_message=' . urlencode(ERROR_INVALID_STARTDATE_COUPON), 'SSL'));

       }

 //END TEST9



 //TEST10 - is this coupon still valid, or has it expired?

       $date_query=tep_db_query("select coupon_expire_date from " . TABLE_COUPONS . " 

                               where coupon_expire_date >= now() and 

                               coupon_code='".$HTTP_POST_VARS['gv_redeem_code']."'");



       if (tep_db_num_rows($date_query)==0) {

         tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'error_message=' . urlencode(ERROR_INVALID_FINISDATE_COUPON), 'SSL'));

       }

 //END TEST10

 

       //TEST5 - has this coupon been used too many times?

 $coupon_count = tep_db_query("select coupon_id from " . TABLE_COUPON_REDEEM_TRACK . " 

                                         where coupon_id = '" . $coupon_result['coupon_id']."'");

       $coupon_count_customer = tep_db_query("select coupon_id from " . TABLE_COUPON_REDEEM_TRACK . " 

                                                  where coupon_id = '" . $coupon_result['coupon_id']."' and

                                                  customer_id = '" . $customer_id . "'");

   

       if (tep_db_num_rows($coupon_count)>=$coupon_result['uses_per_coupon'] && $coupon_result['uses_per_coupon'] > 0) {

         tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'error_message=' . urlencode(ERROR_INVALID_USES_COUPON . $coupon_result['uses_per_coupon'] . TIMES ), 'SSL'));

       }

 //END TEST5



 //TEST6 - has this user used up all their coupon uses?

       if (tep_db_num_rows($coupon_count_customer)>=$coupon_result['uses_per_user'] && $coupon_result['uses_per_user'] > 0) {

         tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'error_message=' . urlencode(ERROR_INVALID_USES_USER_COUPON . $coupon_result['uses_per_user'] . TIMES ), 'SSL'));

       }

 //END TEST6

      

   //TEST2 - user gets free shipping ??

    if ($coupon_result['coupon_type']=='S') {

         $coupon_amount = $order->info['shipping_cost'];

       } else {

         $coupon_amount = $currencies->format($coupon_result['coupon_amount']) . ' ';

       }

 //END TEST2

 

 //TEST3 - user gets a percentage deduction

       if ($coupon_result['type']=='P') $coupon_amount = $coupon_result['coupon_amount'] . '% ';

 //END TEST3

 

//added for additional error messages

//used for TEST1, TEST7, and TEST8	

$_SESSION['cc_id'] = $coupon_result['coupon_id']; 

   $cc_id = $_SESSION['cc_id'];

   $od_amount = 0;



  // if ($cc_id) {

     $coupon_query = tep_db_query("select coupon_code from " . TABLE_COUPONS . " where coupon_id = '" . $cc_id . "'");

     if (tep_db_num_rows($coupon_query) !=0 ) {

       $coupon_result = tep_db_fetch_array($coupon_query);

       $this->coupon_code = $coupon_result['coupon_code'];

       $coupon_get = tep_db_query("select coupon_amount, coupon_minimum_order, restrict_to_products, restrict_to_categories, coupon_type from " . TABLE_COUPONS ." where coupon_code = '". $coupon_result['coupon_code'] . "'");

       $get_result = tep_db_fetch_array($coupon_get);

       //$c_deduct = $get_result['coupon_amount'];

       //if ($get_result['coupon_type']=='S') $c_deduct = $order->info['shipping_cost'];

 

  if ($get_result['coupon_minimum_order'])	$overMinOrder = false;

  if ($get_result['restrict_to_products'])	$validProduct = false;

  if ($get_result['restrict_to_categories'])	$validCategory = false;

  

      

    if ($get_result['coupon_minimum_order'] <= $this->get_order_total()) {

         if ($get_result['restrict_to_products'] || $get_result['restrict_to_categories']) {

	 for ($i=0; $i<sizeof($order->products); $i++) {

             if ($get_result['restrict_to_products']) {

             

   $pr_ids = split("[,]", $get_result['restrict_to_products']);

          	 for ($ii = 0; $ii < count($pr_ids); $ii++) {

    if ($pr_ids[$ii] == tep_get_prid($order->products[$i]['id'])) {

              	 $validProduct = true;

  	 //$validCategory = true;

                 }

               }         

             } else {

     //$validCategory = false;

               $cat_ids = split("[,]", $get_result['restrict_to_categories']);

               for ($i=0; $i<sizeof($order->products); $i++) {

                 $my_path = tep_get_product_path(tep_get_prid($order->products[$i]['id']));

                 $sub_cat_ids = split("[_]", $my_path);

                 for ($iii = 0; $iii < count($sub_cat_ids); $iii++) {                  

                   for ($ii = 0; $ii < count($cat_ids); $ii++) {

                     if ($sub_cat_ids[$iii] == $cat_ids[$ii]) {

       $validCategory = true;

                     }

                   }

                 }

               } 

             }

           }

         } 

       $overMinOrder = true;

 }

     }

     //if ($od_amount>$amount) $od_amount = $amount;

  // }



 //TEST1 - have they purchased enough to fulfill the min purchase requirement?

      if($get_result['coupon_minimum_order'] > 0) 

   {

     if(!$overMinOrder)

   {   tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'error_message=You must purchase a minimum of $' . number_format($get_result['coupon_minimum_order'],2) . ' before using this coupon.' . $overMinOrder, 'SSL'));	}

 }

 //if ($coupon_result['coupon_minimum_order']>0) $coupon_amount .= 'on orders greater than ' .  $coupon_result['coupon_minimum_order'];

 //END TEST1

 

 //TEST7 - does this coupon require you buy a certain product - does the user have that product

 if($get_result['restrict_to_products'] > 0)

 { 

	 if(!$validProduct)

	 {	tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'error_message=This coupon has product restrictions, please click the Coupons: more info link in your Shopping Cart box for more information.', 'SSL'));	}

 }

 //END TEST7

 

 //TEST8 - does this coupon require you buy from a certain category - does the user have the right products?

 if($get_result['restrict_to_categories'] > 0)

 { 

	 if(!$validCategory)

	 {	tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'error_message=This coupon has category restrictions, please click the Coupons: more info link in your Shopping Cart box for more information.', 'SSL'));	}

 }

 //END TEST8

 

     }

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...