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.
Re: Blocking usage of Group Discount & Discount Coupons
It might be better to write it this way for that function:
Code:
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 ...
Code:
// 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 ...
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.
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:
Code:
if (!$foundvalid) {
$this->clear_posts();
}
and place the new code in RED above it ...
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.
Re: Blocking usage of Group Discount & Discount Coupons
Might be my fault, change the IF from:
Code:
if ($discount_coupon->fields['coupon_code'] == 'abc123') {
to read:
Code:
if ($dc_check == 'abc123') {
I just noticed the variable to check changed in that function ...
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.
Re: Blocking usage of Group Discount & Discount Coupons
What version Zen Cart are you running?
Are you able to test without the COWAO? :unsure:
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.
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.