Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Credit Class/Gift Vouchers/Discount Coupons


Recommended Posts

Hi there all,

 

This may or may not be a useful idea to anybody, but I think it would be perfect for my setup.

 

In my store, I need to allow only certain customers to use a particular discount code.

 

I'm just not sure how to do it!

 

I'm guessing the code would be pretty much the same as the restrict_to_products or restrict_to_categories stuff, but I can't seem to get it right.....

 

Any help would be much appreciated!

 

Here's what I've got so far, placed in the 'function calculate_credit($amount)' section in modules/order_total/ot_coupon.php:

 

function calculate_credit($amount) {
global $customer_id, $order, $cc_id;
//$cc_id = $_SESSION['cc_id']; //Fred commented out, do not use $_SESSION[] due to backward comp. Reference the global var instead.
$od_amount = 0;
if (isset($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'] <= $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'])) {
      	 if ($get_result['coupon_type'] == 'P') {
        	 /* Fixes to Gift Voucher module 5.03
        	 =================================
        	 Submitted by Rob Cote, [email protected]

        	 original code: $od_amount = round($amount*10)/10*$c_deduct/100;
        	 $pr_c = $order->products[$i]['final_price']*$order->products[$i]['qty'];
        	 $pod_amount = round($pr_c*10)/10*$c_deduct/100;
        	 */
        	 //$pr_c = $order->products[$i]['final_price']*$order->products[$i]['qty'];
        	 $pr_c = $this->product_price($pr_ids[$ii]); //Fred 2003-10-28, fix for the row above, otherwise the discount is calc based on price excl VAT!
        	 $pod_amount = round($pr_c*10)/10*$c_deduct/100;
        	 $od_amount = $od_amount + $pod_amount;
         } else {
        	 $od_amount = $c_deduct;
         }
      	 }
       }
    	 } else {
       $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]) {
           if ($get_result['coupon_type'] == 'P') {
          	 /* Category Restriction Fix to Gift Voucher module 5.04
          	 Date: August 3, 2003
          	 =================================
          	 Nick Stanko of UkiDev.com, [email protected]

          	 original code:
          	 $od_amount = round($amount*10)/10*$c_deduct/100;
          	 $pr_c = $order->products[$i]['final_price']*$order->products[$i]['qty'];
          	 $pod_amount = round($pr_c*10)/10*$c_deduct/100;
          	 */
          	 //$od_amount = round($amount*10)/10*$c_deduct/100;
          	 //$pr_c = $order->products[$i]['final_price']*$order->products[$i]['qty'];
          	 $pr_c = $this->product_price(tep_get_prid($order->products[$i]['id'])); //Fred 2003-10-28, fix for the row above, otherwise the discount is calc based on price excl VAT!
          	 $pod_amount = round($pr_c*10)/10*$c_deduct/100;
          	 $od_amount = $od_amount + $pod_amount;
           } else {
          	 $od_amount = $c_deduct;
           }
        	 }
         }
      	 }
       }
///// My Additions for Customer Restriction!      }else{
         if ($get_result['restrict_to_customer']) {
    	 $cus_ids = split("[,]", $get_result['restrict_to_customers']);
    	 for ($ii = 0; $ii < count($cus_ids); $ii++) {
       if ($cus_ids[$ii] == tep_get_prid($order->products[$i]['id'])) {
      	 if ($get_result['coupon_type'] == 'P') {
        	 /* Fixes to Gift Voucher module 5.03
        	 =================================
        	 Submitted by Rob Cote, [email protected]

        	 original code: $od_amount = round($amount*10)/10*$c_deduct/100;
        	 $pr_c = $order->products[$i]['final_price']*$order->products[$i]['qty'];
        	 $pod_amount = round($pr_c*10)/10*$c_deduct/100;
        	 */
        	 //$pr_c = $order->products[$i]['final_price']*$order->products[$i]['qty'];
        	 $pr_c = $this->product_price($pr_ids[$ii]); //Fred 2003-10-28, fix for the row above, otherwise the discount is calc based on price excl VAT!
        	 $pod_amount = round($pr_c*10)/10*$c_deduct/100;
        	 $od_amount = $od_amount + $pod_amount;
         } else {
        	 $od_amount = $c_deduct;
         }
      	 }
       }
///// End of My Additions
    	 }
     }
  	 } else {
     if ($get_result['coupon_type'] !='P') {
    	 $od_amount = $c_deduct;
     } else {
    	 $od_amount = $amount * $get_result['coupon_amount'] / 100;
     }
  	 }
   }
	 }
 if ($od_amount>$amount) $od_amount = $amount;
 }
return $od_amount;
}

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...