Zen Cart Logo
Forums / Discounts/Coupons, Gift Certificates, Newsletters, Ads / Applying dollar amount to quantities of 2

Applying dollar amount to quantities of 2

Views: 1,786

Results 1 to 7 of 7
2 Jul 2015, 5:19 PM
#1
keyconn avatar

keyconn

New Zenner

Join Date:
Apr 2015
Location:
Pennsylvania, USA
Posts:
21
Plugin Contributions:
0

Applying dollar amount to quantities of 2

Hello,

I have a client that wants to run a $1 off 2 packages of cookies. I have created the coupon and set the minimum order amount to the total of 2 packages of cookies ($13.90). I have restricted all categories and products this would not be applied to.

I am testing the coupon to see if it works with a client ordering 2, 3, 4, or any combination of packages. It is applying the discount correctly if I order 2, 4, 6, and so forth. However, it is applying a discount of $.50 to single packages as well. Example, I ordered 5 cookies and the discount is showing as $2.50.

Is there any way to prevent this discount from being applied to a single package in the scenarios I mentioned above?

Thank you.

2 Jul 2015, 5:48 PM
#2
keyconn avatar

keyconn

New Zenner

Join Date:
Apr 2015
Location:
Pennsylvania, USA
Posts:
21
Plugin Contributions:
0

Re: Applying dollar amount to quantities of 2

UPDATE: I misunderstood my client. This is not how she wants to use the coupon. My apologies. The question may come up in the future so if anyone wants to answer that would be great.

COUPON: My clients wants to have $1 off applied to the first 2 packages ordered, period. They they order 3, 4, 5 and so forth, only $1 gets deducted. Any ideas on how to make that work?

Here is the ironic part: On the old coupon code it would work that way if I used dollar amount instead of percentage amount. Since the code was fixed it now applies the discount universally using dollar amount or percentages.

Thank you in advance, and my apologies for the confusion.

2 Jul 2015, 6:09 PM
#3
ajeh avatar

ajeh

Oba-san

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

Re: Applying dollar amount to quantities of 2

So now you want that Discount Coupon to be $1 or $2 but not increase to over the $2, correct?

2 Jul 2015, 6:21 PM
#4
keyconn avatar

keyconn

New Zenner

Join Date:
Apr 2015
Location:
Pennsylvania, USA
Posts:
21
Plugin Contributions:
0

Re: Applying dollar amount to quantities of 2

No. My apologies for the confusion.

The client wants the coupon to be applied to the first 2 qualifying packages purchased. So if 3 or more are ordered, only $1.00 will be deducted from the order.

The offer is $1 off 2 packages.

3 Jul 2015, 10:56 PM
#5
ajeh avatar

ajeh

Oba-san

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

Re: Applying dollar amount to quantities of 2

Have you an URL to the Category of Products that this Discount Coupon is for?

Are ALL Products in the Category qualifying Products?

7 Jul 2015, 4:25 PM
#7
ajeh avatar

ajeh

Oba-san

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

Re: Applying dollar amount to quantities of 2

To make it so this one Discount Coupon will work when there are 2 or more Products from this 1 category in the cart, you could make the following customizations ...

Add a new file:
/includes/functions/extra_functions/functions_coupon_check.php

that contains the code:

<?php
if (!function_exists('in_cart_product_total_quantity_category')) {
  function in_cart_product_total_quantity_category($category_id) {
    $products = $this->get_products();
//echo '<pre>'; echo print_r($products); echo '</pre>';
    $in_cart_product_quantity = 0;
    for ($i=0, $n=sizeof($products); $i<$n; $i++) {
      if ($products[$i]['category'] == $category_id) {
        $in_cart_product_quantity += $products[$i]['quantity'];
      }
    } // end FOR loop
    return $in_cart_product_quantity;
  }
}

if (!function_exists('in_cart_product_total_quantity_category_sub')) {
  function in_cart_product_total_quantity_category_sub($category_id) {
    $chk_cart_quantity = 0;
    if (zen_has_category_subcategories($category_id)) {
      $subcategories_array = array();
      $chk_cat = $category_id; // parent categories_id
      zen_get_subcategories($subcategories_array, $chk_cat);
      for ($i=0, $n=sizeof($subcategories_array); $i<$n; $i++ ) {
        $chk_cart_quantity += in_cart_product_total_quantity_category($subcategories_array[$i]);
      }
    } else {
      $chk_cart_quantity = in_cart_product_total_quantity_category($category_id);
    }
    return $chk_cart_quantity;
  }
}

These funtions are used to count how many Products are in a cart from a Category ...

Then, edit a clean copy of:
/includes/modules/order_total/ot_coupon.php

and add the code in RED around line 212:

[B]// bof: coupon COOKIES on 2 Products
if ($dc_check == 'COOKIES') {
  $cookies_cat_id = 67;
  $chk_cookies_count = in_cart_product_total_quantity_category_sub($cookies_cat_id);
  if ($chk_cookies_count < 2) {
    $foundvalid = false;
  }
}
// eof: coupon COOKIES on 2 Products
[/B]
        if (!$foundvalid) {
          $this->clear_posts();
        }

Set this line:

[B]  $cookies_cat_id = 67;
[/B]

to be the categories_id for the COOKIE category that you want for this Discount Code ...

Then, set the Discount Coupon code on this line:

[B]if ($dc_check == 'COOKIES') {
[/B]

to match your Discount Coupon code for this coupon so that the test runs only for this Discount Coupon to make sure that there are at least quantity 2 of the Cookie Products in the Cart, before it will give the $1.00 Discount ...