Zen Cart Logo
Forums / Discounts/Coupons, Gift Certificates, Newsletters, Ads / Blocking usage of Group Discount & Discount Coupons

Blocking usage of Group Discount & Discount Coupons

Views: 7,140

Results 1 to 20 of 25
02 Feb 2012, 15:38
#1
familynow avatar

familynow

Zen Follower

Join Date:
Aug 2011
Location:
Near Ottawa, Ontario, Canada
Posts:
321
Plugin Contributions:
0

Blocking usage of Group Discount & Discount Coupons

Hi.

I'd like to prevent ppl from redeeming a discount coupon code when their in a discount group. Is that possible?

03 Feb 2012, 20:29
#2
familynow avatar

familynow

Zen Follower

Join Date:
Aug 2011
Location:
Near Ottawa, Ontario, Canada
Posts:
321
Plugin Contributions:
0

Re: Blocking usage of Group Discount & Discount Coupons

Perhaps some background info would help?

I'm doign a WagJaw campaign(CDN groupon clone) and I'm selling a membership that will entitle clients to a discount for a year. I was hoping to use group pricing for this but I hadn't realized they could also redeem coupons on top of the group pricing discount. Is there a way to add restrictions to group pricing or perhaps do this another way. Worst case I guess I could give everone a coupon code they they'd have to enter at every purchase that way they could only apply a single discount but that's allot of overhead when I could just have them part of a group.

Any thoughts?

04 Feb 2012, 16:31
#3
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Blocking usage of Group Discount & Discount Coupons

To stop anyone with a Group Discount from using a Discount Coupon, you could alter the ot_coupon.php module with something like:

  function credit_selection() {
    global $discount_coupon;
    // note the placement of the redeem code can be moved within the array on the instructions or the title

    // bof: stop discount coupon for anyone in a customer group
    global $db;
    $chk_group = $db->Execute("select customers_group_pricing from " . TABLE_CUSTOMERS . " where customers_id = '" . $_SESSION['customer_id'] . "'");
    if ($chk_group->fields['customers_group_pricing'] > 0) {
      $allow_discount = false;
    } else {
      $allow_discount = true;
    }

    if ($allow_discount) {
    $selection = array('id' => $this->code,
                       'module' => $this->title,
                       'redeem_instructions' => MODULE_ORDER_TOTAL_COUPON_REDEEM_INSTRUCTIONS . ($discount_coupon->fields['coupon_code'] != '' ? MODULE_ORDER_TOTAL_COUPON_REMOVE_INSTRUCTIONS : '') . ($discount_coupon->fields['coupon_code'] != '' ? MODULE_ORDER_TOTAL_COUPON_TEXT_CURRENT_CODE . '<a href="javascript:couponpopupWindow(\'' . zen_href_link(FILENAME_POPUP_COUPON_HELP, 'cID=' . $_SESSION['cc_id']) . '\')">' . $discount_coupon->fields['coupon_code'] . '</a><br /><br />' : ''),
                       'fields' => array(array('title' => MODULE_ORDER_TOTAL_COUPON_TEXT_ENTER_CODE,
                                               'field' => zen_draw_input_field('dc_redeem_code', '', 'id="disc-' . $this->code . '" onkeyup="submitFunction(0,0)"'),
                                               'tag' => 'disc-'.$this->code
                       )));
    }
    // eof: stop discount coupon for anyone in a customer group

    return $selection;
  }

Note: you should include some type of exclusion statement in your Discount Coupons ...

06 Feb 2012, 01:13
#4
familynow avatar

familynow

Zen Follower

Join Date:
Aug 2011
Location:
Near Ottawa, Ontario, Canada
Posts:
321
Plugin Contributions:
0

Re: Blocking usage of Group Discount & Discount Coupons

Much appreciated Ajeh. I'll give that a whirl.

When you say I should include an exclusion statement, are you referring to the printed/virtual coupon itself or are you refering to code exclusion?

06 Feb 2012, 04:15
#5
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Blocking usage of Group Discount & Discount Coupons

Just a notice such as Discount Coupons not valid with other discounts or something so people do not wonder ...

14 Feb 2012, 20:26
#6
gokeypa avatar

gokeypa

New Zenner

Join Date:
Sep 2011
Posts:
86
Plugin Contributions:
0

Re: Blocking usage of Group Discount & Discount Coupons

Hi, I was wondering if I could somehow apply this idea to a coupon I am preparing for a trade show. I want to offer a coupon to all first time users, but I do not want them to be able to use the coupon if they have made a purchase in the past. Let me say first that I am in NO WAY a good coder, so if you have an idea PLEASE explain it to me as if I were a 4 year old.

Thanks.

14 Feb 2012, 23:30
#7
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Blocking usage of Group Discount & Discount Coupons

You could use this code ... note the line in blue is only needed if not using other IF statements with the same code:

    // bof: stop discount coupon for anyone with an order
    $allow_discount = true;
    if ($discount_coupon->fields['coupon_code'] == 'abc123') {
      global $db;
      $chk_group = $db->Execute("select orders_id from " . TABLE_ORDERS . " where customers_id = '" . $_SESSION['customer_id'] . "'");
      if ($chk_group->RecordCount() > 0) {
        $allow_discount = false;
      } else {
        $allow_discount = true;
      }
    }
    // eof: stop discount coupon for anyone with an order
    if ($allow_discount) {
    $selection = array('id' => $this->code,
                       'module' => $this->title,
                       'redeem_instructions' => MODULE_ORDER_TOTAL_COUPON_REDEEM_INSTRUCTIONS . ($discount_coupon->fields['coupon_code'] != '' ? MODULE_ORDER_TOTAL_COUPON_REMOVE_INSTRUCTIONS : ''),
                       'fields' => array(array('title' => ($discount_coupon->fields['coupon_code'] != '' ? MODULE_ORDER_TOTAL_COUPON_TEXT_CURRENT_CODE . '<a href="javascript:couponpopupWindow(\'' . zen_href_link(FILENAME_POPUP_COUPON_HELP, 'cID=' . $_SESSION['cc_id']) . '\')">' . $discount_coupon->fields['coupon_code'] . '</a><br />' : '') . MODULE_ORDER_TOTAL_COUPON_TEXT_ENTER_CODE,
                                               'field' => zen_draw_input_field('dc_redeem_code', '', 'id="disc-' . $this->code . '" onkeyup="submitFunction(0,0)"'),
                                               'tag' => 'disc-'.$this->code
                       )));
    }
   // eof: stop discount coupon for anyone with an order

Then you can surround the

14 Feb 2012, 23:53
#8
gokeypa avatar

gokeypa

New Zenner

Join Date:
Sep 2011
Posts:
86
Plugin Contributions:
0

Re: Blocking usage of Group Discount & Discount Coupons

Wow, thanks.

OK so, I guess I should edit includes/modules/order_total/ot_coupon.php, and NOT includes/languages/english/modules/order_total/ot_coupon.php.

Also should I add the new code to the top or the bottom of the current code?

I guess I can make the change to the abc123 coupon right in the code you gave me, and not at the coupon manager.

If these guess' are correct I will try it tonight and let you know how it worked.

thanks again.

14 Feb 2012, 23:58
#9
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Blocking usage of Group Discount & Discount Coupons

Actually, if you are going to run both of these IFs together you will need to adjust the code by commenting the line in RED:

    if ($discount_coupon->fields['coupon_code'] == 'abc123') {
      global $db;
      $chk_group = $db->Execute("select orders_id from " . TABLE_ORDERS . " where customers_id = '" . $_SESSION['customer_id'] . "'");
      if ($chk_group->RecordCount() > 0) {
        $allow_discount = false;
      } else {
//        $allow_discount = true;
      }
    }

Put that code below your other IF code:

    // bof: stop discount coupon for anyone in a customer group
    global $db;
    $chk_group = $db->Execute("select customers_group_pricing from " . TABLE_CUSTOMERS . " where customers_id = '" . $_SESSION['customer_id'] . "'");
    if ($chk_group->fields['customers_group_pricing'] > 0) {
      $allow_discount = false;
    } else {
      $allow_discount = true;
    }

Now the new IF won't conflict with the other IF for the customer group ...

Yes, change the abc123 to your your coupon code you are trying to block if a previous order exists ... and, yes, this is the code file not the language file ...

15 Feb 2012, 01:13
#10
gokeypa avatar

gokeypa

New Zenner

Join Date:
Sep 2011
Posts:
86
Plugin Contributions:
0

Re: Blocking usage of Group Discount & Discount Coupons

Ok,

So I will put both of the two new pieces of code you sent me from your last post in the code file. I will remove the // before the red code and test using the abc123 and see if it works for me.

thanks again and sorry for not being very good with the coding.

15 Feb 2012, 05:35
#11
gokeypa avatar

gokeypa

New Zenner

Join Date:
Sep 2011
Posts:
86
Plugin Contributions:
0

Re: Blocking usage of Group Discount & Discount Coupons

Ok,

I am doing something wrong.

Here is the code in the order I have it.
// bof: stop discount coupon for anyone in a customer group
global $db;
$chk_group = $db->Execute("select customers_group_pricing from " . TABLE_CUSTOMERS . " where customers_id = '" . $_SESSION['customer_id'] . "'");
if ($chk_group->fields['customers_group_pricing'] > 0) {
$allow_discount = false;
} else {
$allow_discount = true;
}

if ($discount_coupon->fields['coupon_code'] == 'abc123') {
global $db;
$chk_group = $db->Execute("select orders_id from " . TABLE_ORDERS . " where customers_id = '" . $_SESSION['customer_id'] . "'");
if ($chk_group->RecordCount() > 0) {
$allow_discount = false;
} else {
$allow_discount = true;
}
}

I have it starting at line 500 of the ot_coupon.php.

Is this right?

Please I am sorry, but I think I need to know what line it should be inserted at.

15 Feb 2012, 14:09
#12
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Blocking usage of Group Discount & Discount Coupons

It might be better to write it this way for that function:

  function credit_selection() {
    global $discount_coupon;
    // note the placement of the redeem code can be moved within the array on the instructions or the title

// bof: stop discount coupon for anyone in a customer group
    global $db;
    $allow_discount = true;
    $chk_group = $db->Execute("select customers_group_pricing from " . TABLE_CUSTOMERS . " where customers_id = '" . $_SESSION['customer_id'] . "'");
    if ($chk_group->fields['customers_group_pricing'] > 0) {
      $allow_discount = false;
    }


    if ($allow_discount) {
    // eof: stop discount coupon for anyone with an order
    $selection = array('id' => $this->code,
                       'module' => $this->title,
                       'redeem_instructions' => MODULE_ORDER_TOTAL_COUPON_REDEEM_INSTRUCTIONS . ($discount_coupon->fields['coupon_code'] != '' ? MODULE_ORDER_TOTAL_COUPON_REMOVE_INSTRUCTIONS : ''),
                       'fields' => array(array('title' => ($discount_coupon->fields['coupon_code'] != '' ? MODULE_ORDER_TOTAL_COUPON_TEXT_CURRENT_CODE . '<a href="javascript:couponpopupWindow(\'' . zen_href_link(FILENAME_POPUP_COUPON_HELP, 'cID=' . $_SESSION['cc_id']) . '\')">' . $discount_coupon->fields['coupon_code'] . '</a><br />' : '') . MODULE_ORDER_TOTAL_COUPON_TEXT_ENTER_CODE,
                                               'field' => zen_draw_input_field('dc_redeem_code', '', 'id="disc-' . $this->code . '" onkeyup="submitFunction(0,0)"'),
                                               'tag' => 'disc-'.$this->code
                       )));
    }
    return $selection;
  }

Then for blocking the coupon abc123 from customers with previous orders go to the function collect_posts and add the test for that coupon ...

// bof: coupon abc123 for first time customers only
    if ($discount_coupon->fields['coupon_code'] == 'abc123') {
      global $db;
      $chk_group = $db->Execute("select orders_id from " . TABLE_ORDERS . " where customers_id = '" . $_SESSION['customer_id'] . "'");
      if ($chk_group->RecordCount() > 0) {
        $foundvalid = false;
      }
    }
// eof: coupon abc123 for first time customers only

        if (!$foundvalid) {
          $this->clear_posts();
        }

First, set that the coupon is valid, then do the two tests and only worry about setting the coupon as invalid based on the IF conditions ...

If neither are valid, the the coupon is valid, if either the group is valid or the coupon is abc123 and there is a previous order, the the coupon would not processes ...

See if that works better ...

The reason for the change is, the first condition on the Customer Groups is to stop ALL coupons from happening for a customer in a group ... the second one is to only stop a specific coupon from a customer with a previous order and not stop the customer for using other coupons that might be valid ...

15 Feb 2012, 16:07
#13
gokeypa avatar

gokeypa

New Zenner

Join Date:
Sep 2011
Posts:
86
Plugin Contributions:
0

Re: Blocking usage of Group Discount & Discount Coupons

Ok,

trying it today,

I am still a little worried about at what line of the ot_coupon.php I should be inserting this new code though.

15 Feb 2012, 16:16
#14
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Blocking usage of Group Discount & Discount Coupons

The first part, I gave you the whole function credit_selection so that you can just replace that with the new code ...

The second one, look for the existing code:

        if (!$foundvalid) {
          $this->clear_posts();
        }

and place the new code in RED above it ...

15 Feb 2012, 18:52
#15
gokeypa avatar

gokeypa

New Zenner

Join Date:
Sep 2011
Posts:
86
Plugin Contributions:
0

Re: Blocking usage of Group Discount & Discount Coupons

Ok, here is what I did.

I went into the adim coupon, and added abc123 with the 10% discount.

I copied the code exaclly as you had it in the example.

I am confused by the following statment "*Then for blocking the coupon abc123 from customers with previous orders go to the function collect_posts and add the test *"

the coupon works but it does not stop me an existing user from using it. I do not know if this matters but I added the COWAO, and I try making the purchase without logging in.

15 Feb 2012, 19:01
#16
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Blocking usage of Group Discount & Discount Coupons

Might be my fault, change the IF from:

    if ($discount_coupon->fields['coupon_code'] == 'abc123') {

to read:

    if ($dc_check == 'abc123') {

I just noticed the variable to check changed in that function ...

15 Feb 2012, 19:10
#17
gokeypa avatar

gokeypa

New Zenner

Join Date:
Sep 2011
Posts:
86
Plugin Contributions:
0

Re: Blocking usage of Group Discount & Discount Coupons

I made the change, but I might still be doing something wrong, because the code still let me the excisting customer use the discount.

15 Feb 2012, 19:19
#18
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Blocking usage of Group Discount & Discount Coupons

What version Zen Cart are you running?

Are you able to test without the COWAO? :unsure:

15 Feb 2012, 19:28
#19
gokeypa avatar

gokeypa

New Zenner

Join Date:
Sep 2011
Posts:
86
Plugin Contributions:
0

Re: Blocking usage of Group Discount & Discount Coupons

I am running 1.3.9, I can either login or turn off COWAO.

I am still a little confused by the following statment

"Then for blocking the coupon abc123 from customers with previous orders go to the function collect_posts and add the test"

I will try turning COWAO off first.

15 Feb 2012, 19:36
#20
gokeypa avatar

gokeypa

New Zenner

Join Date:
Sep 2011
Posts:
86
Plugin Contributions:
0

Re: Blocking usage of Group Discount & Discount Coupons

Ok,

When i login it does NOT let me use the new coupon. :D

Now do you think there is a way to make this work with out having them login, My boss "WIFE" who's buisness it is, does not want to force everyone to have an account to make a purchase.