Zen Cart Logo
Forums / Discounts/Coupons, Gift Certificates, Newsletters, Ads / Exclude items from the Group Pricing Discount

Exclude items from the Group Pricing Discount

Views: 21,397

Results 1 to 17 of 17
15 Jul 2011, 11:00 AM
#1
merseyray avatar

merseyray

New Zenner

Join Date:
Jul 2011
Location:
Southport
Posts:
11
Plugin Contributions:
0

Exclude items from the Group Pricing Discount

Hi everyone, this is my first post.
I am currently setting up my first zencart site.
Im making pretty good progress, but I have a problem.

I have set up the group pricing to allow a % discount on items, however, I want to know if there is any module/php alteration to exclude items marked as "OEM" in the manufacturer option, or only allow items marked "Compatible" in the manufacturer option.

I have got the Online Group Pricing module by Toni installed (To show the discount on each item instead of the cart), so please take this into account if I have to replace core files.

Many thanks

Ray

v1.3.9h

22 Jul 2011, 5:01 PM
#2
merseyray avatar

merseyray

New Zenner

Join Date:
Jul 2011
Location:
Southport
Posts:
11
Plugin Contributions:
0

Re: Exclude items from the Group Pricing Discount

Surely somebody knows how to do this ? :huh:

I sort of know what I want it to do, but dont know how about doing it.

I think this may work....

Create an extra field somewhere in the database called "excludefromsales", and assign it to a checkbox next to either, the manufacturer or the item.

Then in the functions_prices.php or html_output.php, or both files, a function that does something like....

"if excludefromsales = 0 {do this with discount applied}
else
{do this without discount applied}"

I know it is probably simple for some of you guys, but without a lot of trial and error, its not something simple for me :frusty:

Thanks in advance for any help.

24 Jul 2011, 7:44 PM
#3
mvstudio avatar

mvstudio

Zen Follower

Join Date:
Apr 2008
Posts:
447
Plugin Contributions:
1

Re: Exclude items from the Group Pricing Discount

very interested in this as well... i've tried many codes and nothing seems to work :no::no:

26 Jul 2011, 3:30 PM
#4
merseyray avatar

merseyray

New Zenner

Join Date:
Jul 2011
Location:
Southport
Posts:
11
Plugin Contributions:
0

Re: Exclude items from the Group Pricing Discount

I think the perfect guy to help on this would be Toni, the creator of the online group mod.

I have got this far, I have added a session variable named "$customer_manufacturer_group" and done the "if" statement similar to my first post.
This does remove the discount, but on all products, and not just those in my category number 6.

Can anybody help ?

My additions are in green below.

} else {
session_start();
$_SESSION['customer_group_id'] = array();
$_SESSION['customer_group_id']['customer_id'] = $customer_id;
$_SESSION['customer_group_id']['group_id'] = $customer_group_id;
$_SESSION['customer_group_id']['discount'] = $customer_group_percentage;
$_SESSION['customer_group_id']['method'] = $customer_group_method;
$_SESSION['manufacturers']['manufacturers_id'] = $customer_manufacturer_group;
}
}

switch($customer_group_method) {
case 1:
if ($customer_manufacturer_group =6) {
$display_normal_price = round($display_normal_price,4) * $qty;
return $display_normal_price;}
else
{
$display_normal_price = round($display_normal_price * (1 - ($customer_group_percentage/100)),4) * $qty;
return $display_normal_price;}
break;

case 2:
$display_normal_price = round($display_normal_price / (1 + ($customer_group_percentage/100)),4) * $qty;
return $display_normal_price;
break;

default:
// regular price
$display_normal_price = round($display_normal_price,4) * $qty;
return $display_normal_price;
break;
}

26 Jul 2011, 7:41 PM
#5
mvstudio avatar

mvstudio

Zen Follower

Join Date:
Apr 2008
Posts:
447
Plugin Contributions:
1

Re: Exclude items from the Group Pricing Discount

What file are you editing??
Everywhere I looked mentions to edit ot_group_pricing.php and edit the deductions portion. I've tried but I'm not able to make it work :no:

  function calculate_deductions($order_total) {
    global $db, $order;
    $od_amount = array();
    $orderTotal = $this->get_order_total();
    $orderTotalTax = $orderTotal['tax'];
    $group_query = $db->Execute("select customers_group_pricing from " . TABLE_CUSTOMERS . " where customers_id = '" . (int)$_SESSION['customer_id'] . "'");
    if ($group_query->fields['customers_group_pricing'] != '0') {
      $group_discount = $db->Execute("select group_name, group_percentage from " . TABLE_GROUP_PRICING . "
                                      where group_id = '" . (int)$group_query->fields['customers_group_pricing'] . "'");
      $gift_vouchers = $_SESSION['cart']->gv_only();
      $discount = ($order_total - $gift_vouchers) * $group_discount->fields['group_percentage'] / 100;
      $od_amount['total'] = round($discount, 2);
      $ratio = $od_amount['total']/$order_total;
      /**
       * when calculating the ratio add some insignificant values to stop divide by zero errors
       */
      switch ($this->calculate_tax) {
        case 'None':
          if ($this->include_tax) {
            reset($order->info['tax_groups']);
            foreach ($order->info['tax_groups'] as $key=>$value) {
              $od_amount['tax_groups'][$key] = $order->info['tax_groups'][$key] * $ratio;
            }
          }
27 Jul 2011, 10:39 AM
#6
merseyray avatar

merseyray

New Zenner

Join Date:
Jul 2011
Location:
Southport
Posts:
11
Plugin Contributions:
0

Re: Exclude items from the Group Pricing Discount

Ill have a look in that file later on today.
Ive been editing the includes/functions/functions_prices.php file.

Im having trouble setting the variable "$customer_manufacturer_group"

Ive added this green text below the existing black text

$_SESSION['customer_group_id']['method'] = $customer_group_method;
$_SESSION['manufacturers']['manufacturers_id'] = $product_manufacturer_group;
}

and trying to echo the result to the screen, but i can seem to get this to work :frusty:

10 Aug 2012, 1:29 PM
#7
abcisme avatar

abcisme

Zen Follower

Join Date:
Jun 2006
Posts:
298
Plugin Contributions:
0

Re: Exclude items from the Group Pricing Discount

Did anyone ever figure this out?

6 Mar 2018, 2:50 PM
#8
hairydog avatar

hairydog

Zen Follower

Join Date:
Sep 2006
Posts:
165
Plugin Contributions:
0

Re: Exclude items from the Group Pricing Discount

Seems to me that there is a fundamental error in the logic in the question.

The Group discount works on the order total, so there are three possiblities:

  1. The order has no "excluded" items, so the group discount should be applied
  2. The order is entirely made up of "excluded" items, so no groupd discount is available
  3. The order has some "excluded" and some not "excluded". What happens then?

Or have I missed something?

16 May 2018, 6:57 PM
#9
digitalshadow avatar

digitalshadow

Totally Zenned

Join Date:
Mar 2009
Posts:
616
Plugin Contributions:
0

Re: Exclude items from the Group Pricing Discount

EXACTLY this, in example 3, discount needs to be on a per product basis not order total.

hairydog:

Seems to me that there is a fundamental error in the logic in the question.

The Group discount works on the order total, so there are three possiblities:

  1. The order has no "excluded" items, so the group discount should be applied
  2. The order is entirely made up of "excluded" items, so no groupd discount is available
  3. The order has some "excluded" and some not "excluded". What happens then?

Or have I missed something?

16 May 2018, 8:20 PM
#10
hairydog avatar

hairydog

Zen Follower

Join Date:
Sep 2006
Posts:
165
Plugin Contributions:
0

Re: Exclude items from the Group Pricing Discount

DigitalShadow:

EXACTLY this, in example 3, discount needs to be on a per product basis not order total.That means calculating the price on a per-item basis, and it is no longer an order total discount.

12 Jul 2021, 7:49 PM
#11
llemberg avatar

llemberg

New Zenner

Join Date:
Sep 2008
Posts:
22
Plugin Contributions:
0

Re: Exclude items from the Group Pricing Discount

I have come up with a way to eliminate some items from a group_discount using the Order Total discount. It requires editing a core file, which I am generally opposed to, but it is working for us, satisfying an important requirement for our store.

I am using Zen Cart v1.5.7c

  1. Create a category NO DISCOUNT
  2. Make NO DISCOUNT the master category for all items you wish to eliminate from group discounts.
  3. Create links of your NO DISCOUNT items to the categories where you want the items to appear.
  4. Disable the NO DISCOUNT category so it is not visible to customers, but leave all items in that category Active.
  5. In /includes/modules/order_total/ot_group_pricing.php, lines 93, 94 and 95, you will see
      $discount = ($orderTotal['total'] - $gift_vouchers) * $group_discount->fields['group_percentage'] / 100;
//      echo "discout = $discount<br>";
      $od_amount['total'] = round($discount, 2);

Add this after line 93 and before line 95:

      // Remove NO DISCOUNT items from the discount calculation
      $products_in_cart = $_SESSION['cart']->get_product_id_list(); // Get a list of the products_id's that are in the cart
      $no_discount_id = $db->Execute("select categories_id from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_name = 'NO DISCOUNT'")->fields['categories_id']; // Get the id of the NO DISCOUNT category
      $prod_ids = explode(',', $products_in_cart); // split string returned by get_product_id_list() into array
      $discountTotal = $orderTotal['total']; // Assume everything gets a discount
      foreach($prod_ids as $this_id) //loop over the products_ids that are in the cart
      {
        $products_id = strtok($this_id, ':'); // Remove linked item portion of $this_id
        $master_categories_id = $db->Execute("select master_categories_id from " . TABLE_PRODUCTS . " where products_id = $products_id")->fields['master_categories_id']; // Get the master_categories_id of this cart item
        if ( $master_categories_id == $no_discount_id ) { // This item does not get a discount
          $qty_in_cart = $_SESSION['cart']->get_quantity($this_id); // How many of this item are in the cart?
          $price = $db->Execute("select products_price from " . TABLE_PRODUCTS . " where products_id = $products_id")->fields['products_price']; // Get the price of this item
          $discountTotal = $discountTotal - ($qty_in_cart * $price); // Subtract this item's price from the total amount to be discounted
        }
      } 
      // Recalculate the discount without the NO DISCOUNT items
      $discount = ($discountTotal - $gift_vouchers) * $group_discount->fields['group_percentage'] / 100;
12 Jul 2021, 9:16 PM
#12
llemberg avatar

llemberg

New Zenner

Join Date:
Sep 2008
Posts:
22
Plugin Contributions:
0

Re: Exclude items from the Group Pricing Discount

Looks like I pasted in an incomplete block of code in my previous post and missed the time limit for editing the post. You need to check that you actually have a NO DISCOUNT category, so the code added to /includes/modules/order_total/ot_group_pricing.php should be

      // Remove NO DISCOUNT items from the discount calculation
      $no_discount_id = $db->Execute("select categories_id from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_name = 'NO DISCOUNT'")->fields['categories_id'];
      [B]if ( isset($no_discount_id) ) {[/B]
        $products_in_cart = $_SESSION['cart']->get_product_id_list(); // Get a list of the products_id's that are in the cart
        $prod_ids = explode(',', $products_in_cart); //split string returned by get_product_id_list() into array
        $discountTotal = $orderTotal['total']; // Assume everything gets a discount
        foreach($prod_ids as $this_id) //loop over the products_ids
        {
          $products_id = strtok($this_id, ':'); // Remove linked item portion of $this_id
          $master_categories_id = $db->Execute("select master_categories_id from " . TABLE_PRODUCTS . " where products_id = $products_id")->fields['master_categories_id'];
          if ( $master_categories_id == $no_discount_id ) { // This item does not get a discount
            $qty_in_cart = $_SESSION['cart']->get_quantity($this_id); // How many of this item are in the cart?
            $price = $db->Execute("select products_price from " . TABLE_PRODUCTS . " where products_id = $products_id")->fields['products_price'];
            $discountTotal = $discountTotal - ($qty_in_cart * $price); // Subtract this item from the total amount to be discounted
          }
        [B]}[/B] 
        // Recalculate the discount without the NO DISCOUNT items
        $discount = ($discountTotal - $gift_vouchers) * $group_discount->fields['group_percentage'] / 100;
      }
10 Sep 2022, 7:32 PM
#13
gsh68 avatar

gsh68

Zen Follower

Join Date:
Mar 2011
Posts:
103
Plugin Contributions:
0

Re: Exclude items from the Group Pricing Discount

This is very promising.
I've tested it on my 1.57c dev site and it works.

Anyone have any idea how to change the code above for more non-discount categories? Due to the size/shape of certain products I have written custom shipping modules that use the master_categories_id to include or exclude the product.
This means that I can't link all the products I want into one NO DISCOUNT master category as they do not all use the same shipping options. As it is right now there are 5 categories in use - I can get that down to 2 for this purpose.

Adding a NO DISCOUNT 2 category and modifying the above would make it a lot easier for me to set this up instead of modifying 14 shipping modules to use the products_id for 30+ products.

10 Sep 2022, 9:33 PM
#14
llemberg avatar

llemberg

New Zenner

Join Date:
Sep 2008
Posts:
22
Plugin Contributions:
0

Re: Exclude items from the Group Pricing Discount

I haven't tested this, but it might work to just check for your multiple NO DISCOUNT categories. Try the changes in blue:

      // Remove NO DISCOUNT items from the discount calculation
      $no_discount_id = $db->Execute("select categories_id from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_name = 'NO DISCOUNT'")->fields['categories_id'];
      [B]$no_discount_id2 = $db->Execute("select categories_id from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_name = 'NO DISCOUNT 2'")->fields['categories_id'];[/B]
      if ( isset($no_discount_id)[B] || isset($no_discount_id2)[/B] ) {
        $products_in_cart = $_SESSION['cart']->get_product_id_list(); // Get a list of the products_id's that are in the cart
        $prod_ids = explode(',', $products_in_cart); //split string returned by get_product_id_list() into array
        $discountTotal = $orderTotal['total']; // Assume everything gets a discount
        foreach($prod_ids as $this_id) //loop over the products_ids
        {
          $products_id = strtok($this_id, ':'); // Remove linked item portion of $this_id
          $master_categories_id = $db->Execute("select master_categories_id from " . TABLE_PRODUCTS . " where products_id = $products_id")->fields['master_categories_id'];
          if ( $master_categories_id == $no_discount_id ) { // This item does not get a discount
            $qty_in_cart = $_SESSION['cart']->get_quantity($this_id); // How many of this item are in the cart?
            $price = $db->Execute("select products_price from " . TABLE_PRODUCTS . " where products_id = $products_id")->fields['products_price'];
            $discountTotal = $discountTotal - ($qty_in_cart * $price); // Subtract this item from the total amount to be discounted
          }
        } 
        // Recalculate the discount without the NO DISCOUNT items
        $discount = ($discountTotal - $gift_vouchers) * $group_discount->fields['group_percentage'] / 100;
      }
11 Sep 2022, 3:50 AM
#15
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Exclude items from the Group Pricing Discount

gsh68:

This is very promising.
I've tested it on my 1.57c dev site and it works.

Anyone have any idea how to change the code above for more non-discount categories? Due to the size/shape of certain products I have written custom shipping modules that use the master_categories_id to include or exclude the product.
This means that I can't link all the products I want into one NO DISCOUNT master category as they do not all use the same shipping options. As it is right now there are 5 categories in use - I can get that down to 2 for this purpose.

Adding a NO DISCOUNT 2 category and modifying the above would make it a lot easier for me to set this up instead of modifying 14 shipping modules to use the products_id for 30+ products.

The above does a search of categories to identify those that should be excluded, a similar approach could be done against whatever category to then find all product that are linked to that category. The function: zen_get_categories_products_list will return an array where the products_id are the key to that array. I wouldn't trust the resultant value of that key's value though because of the way the assignment is performed. But if the products_id is in the array key list, then it is in that initial category (or its children depending on how you request the search to occur).

12 Sep 2022, 7:59 PM
#16
gsh68 avatar

gsh68

Zen Follower

Join Date:
Mar 2011
Posts:
103
Plugin Contributions:
0

Re: Exclude items from the Group Pricing Discount

llemberg:

I haven't tested this, but it might work to just check for your multiple NO DISCOUNT categories. Try the changes in blue:

  // Remove NO DISCOUNT items from the discount calculation
  $no_discount_id = $db->Execute("select categories_id from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_name = 'NO DISCOUNT'")->fields['categories_id'];
  [B]$no_discount_id2 = $db->Execute("select categories_id from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_name = 'NO DISCOUNT 2'")->fields['categories_id'];[/B]
  if ( isset($no_discount_id)[B] || isset($no_discount_id2)[/B] ) {
    $products_in_cart = $_SESSION['cart']->get_product_id_list(); // Get a list of the products_id's that are in the cart
    $prod_ids = explode(',', $products_in_cart); //split string returned by get_product_id_list() into array
    $discountTotal = $orderTotal['total']; // Assume everything gets a discount
    foreach($prod_ids as $this_id) //loop over the products_ids
    {
      $products_id = strtok($this_id, ':'); // Remove linked item portion of $this_id
      $master_categories_id = $db->Execute("select master_categories_id from " . TABLE_PRODUCTS . " where products_id = $products_id")->fields['master_categories_id'];
      if ( $master_categories_id == $no_discount_id ) { // This item does not get a discount
        $qty_in_cart = $_SESSION['cart']->get_quantity($this_id); // How many of this item are in the cart?
        $price = $db->Execute("select products_price from " . TABLE_PRODUCTS . " where products_id = $products_id")->fields['products_price'];
        $discountTotal = $discountTotal - ($qty_in_cart * $price); // Subtract this item from the total amount to be discounted
      }
    } 
    // Recalculate the discount without the NO DISCOUNT items
    $discount = ($discountTotal - $gift_vouchers) * $group_discount->fields['group_percentage'] / 100;
  }

Thanks - will test it out when I get some free time.
17 Nov 2022, 9:56 AM
#17
gsh68 avatar

gsh68

Zen Follower

Join Date:
Mar 2011
Posts:
103
Plugin Contributions:
0

Re: Exclude items from the Group Pricing Discount

So far I haven't needed to set a second excluded category.
However today I've just noticed one slight issue with this method. If a product in the No Discount cat is set as a featured product the breadcrumb shows NO DISCOUNT as it is the parent category.
Is there a way to show the subcategory in the breadcrumb?