Zen Cart Logo
Forums / Discounts/Coupons, Gift Certificates, Newsletters, Ads / Different Quantity Discounts for customers from Group Pricing?

Different Quantity Discounts for customers from Group Pricing?

Locked

Views: 8,198

Results 1 to 7 of 7
This thread is locked. New replies are disabled.
26 Feb 2008, 11:29 PM
#1
pe7er avatar

pe7er

New Zenner

Join Date:
Apr 2007
Location:
Nijmegen, Netherlands
Posts:
44
Plugin Contributions:
0

Different Quantity Discounts for customers from Group Pricing?

How can I accomplish different Quantity Discounts for Group Pricing customers?

I have Zen Cart 1.3.7 and for some products I use Quantity Discount (Admin > Catalog > Products Price Manager)
and I assigned some customers to Group Pricing (Admin > Customers > Group Pricing).

A product is listed for all customers as:
Qty Discounts Off Price
1-5: €20.00 (normal price)
6-10: €15.00
11-20: €10.00

Customers who are assigned to Group Pricing receive 10% discount.
I am looking for a way that customers who are logged in and assigned to the 10% discount Group Pricing will get a different Quantity Discount, e.g.:
1-5: €20.00 (normal price)
6-10: €17.50
11-20: €15.00
(and 10% off the total price, which is accomplished by using Group Pricing)

The Quantity discounts above are just an example.
In the shop they will differ for every product.

Is it possible or do I need a modification?

26 Feb 2008, 11:50 PM
#2
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,693
Plugin Contributions:
56

Re: Different Quantity Discounts for customers from Group Pricing?

pe7er:

...
Is it possible or do I need a modification?

You need a modification.

27 Feb 2008, 1:41 AM
#3
pe7er avatar

pe7er

New Zenner

Join Date:
Apr 2007
Location:
Nijmegen, Netherlands
Posts:
44
Plugin Contributions:
0

Re: Different Quantity Discounts for customers from Group Pricing?

Thanks for your fast answer!

In what file is the "Discount Value" specified?
I looked in \admin\products_price_manager.php and found the table name
TABLE_PRODUCTS_DISCOUNT_QUANTITY

Should I make a modification in:
\admin\includes\functions\general.php
or in
\admin\includes\functions\functions_prices.php
in 1.3.7, line 1186:
$discounted_price = $check_amount - ($check_amount * ($products_discounts_query->fields['discount_price']/100));

I use Discount Prices of discount type "percentage",
and the customers from the Group Price should get half of the quantity discount.
Can I use the following:

 //check if current customer is part of a certain (customers_group_pricing) group pricing (zen_group_pricing -> 1) category
$gpcheck = $db->Execute("select count(*) as count from " . TABLE_CUSTOMERS . " where customers_id = '".$order->customer['customers_id']."' AND customers_group_pricing = '1'; ");
if ($gpcheck->fields['count'] >0){ 
//customer is part of Group Price ID "1"
//some statement where the Discount Value is multiplied by 50%
$discounted_price = $check_amount - ($check_amount * (($products_discounts_query->fields['discount_price']/100)/2));
}else{
$discounted_price = $check_amount - ($check_amount * ($products_discounts_query->fields['discount_price']/100));
}
//end modification
10 Mar 2008, 11:52 PM
#4
pe7er avatar

pe7er

New Zenner

Join Date:
Apr 2007
Location:
Nijmegen, Netherlands
Posts:
44
Plugin Contributions:
0

Re: Different Quantity Discounts for customers from Group Pricing?

To give customers who are in a certain customer group pricing group (customers_group_pricing = 1)
only half (0.5) the regular quantity discount, I modified to following files:

\includes\modules\products_quantity_discounts.php
This file will display the quantity discount at the product information page.
Just above the code

$display_price = zen_get_products_base_price($products_id_current);
$display_specials_price = zen_get_products_special_price($products_id_current, true);
$disc_cnt = 1;
$quantityDiscounts = array();
$columnCount = 0;
```I included:
  
//modification by pe7er
//check if current customer is part of a certain (customers_group_pricing) group pricing (zen_group_pricing -> 1) category
$gpcheck = $db->Execute("select count(*) as count from " . TABLE_CUSTOMERS . " where customers_id = '".$_SESSION['customer_id']."' AND customers_group_pricing = '1'; ");
if ($gpcheck->fields['count'] >0){
  $distri_discount = 0.5; // the customers in this price group get 50% of the quantity discount
}else{
  $distri_discount = 1; // other customers will receive the full quantity discount
}// end modification.

= $display_price - (($products_discounts_query->fields['discount_price'] *$distri_discount)/100);

= $display_price - ($display_price * (($products_discounts_query->fields['discount_price'] *$distri_discount)/100));

This file calculates the quantity prices.

Just AFTER:

$display_specials_price = zen_get_products_special_price($product_id, true);
I added:
//modification by pe7er
//check if current customer is part of a certain (customers_group_pricing) group pricing (zen_group_pricing -> 1) category
$gpcheck = $db->Execute("select count(*) as count from " . TABLE_CUSTOMERS . " where customers_id = '".$_SESSION['customer_id']."' AND customers_group_pricing = '1'; ");
if ($gpcheck->fields['count'] >0){
$distri_discount = 0.5;
}else{
$distri_discount = 1;
} // end modification.

($products_discounts_query->fields['discount_price'])/100);

(($distri_discount * $products_discounts_query->fields['discount_price'])/100));

28 Sep 2008, 11:15 PM
#5
r_nato avatar

r_nato

New Zenner

Join Date:
Aug 2008
Posts:
41
Plugin Contributions:
0

Re: Different Quantity Discounts for customers from Group Pricing?

Thanks for your post, I had a similar (but not exactly the same) issue.

Our store has price groups for every product. These price groups are actually determined by a multiplier of the product's cost to the seller. Furthermore, some products have quantity pricing as well!

I have not yet dared to change both the admin and the store to calculate the displayed price based on a base price * multiplier; however I was able to adapt the store (which has the price groups mod) to display quantity pricing based on the price group.

I took Pe7er's code above, tweaked it a bit to suit my store. However I noticed that the shopping cart does not display the correct quantity pricing nor does it show the correct subtotal. I am adding this post to help others correct that.

There are two places where you need to change or add code:

  • store/includes/modules/pages/shopping_cart/header_php.php
  • store/includes/classes/shopping_cart.php

store/includes/modules/pages/shopping_cart/header_php.php

If you have an un-modded header_php.php, on line 141 is:

$productsPrice = $currencies->display_price($products[$i]['final_price'], zen_get_tax_rate($products[$i]['tax_class_id']), $products[$i]['quantity']) . ($products[$i]['onetime_charges'] != 0 ? '<br />' . $currencies->display_price($products[$i]['onetime_charges'], zen_get_tax_rate($products[$i]['tax_class_id']), 1) : '');

just before this line, add the following:

  // MOD ADJUST 'productsPriceEach' IF THERE IS QUANTITY PRICING FOR THIS PRODUCT

  $prodQ = $products[$i]['quantity'];
  $prodPE = $products[$i]['final_price'];
  $prodID = $products[$i]['id'];
  if ($prodQ > 1) {  // don't bother if quantity == 1
    $sql = "select discount_qty as dq from " . TABLE_PRODUCTS_DISCOUNT_QUANTITY . " where products_id = '" . $prodID . "' order by discount_qty asc";
    $dqCheck = $db->Execute($sql);
    $count = $dqCheck->RecordCount();
    $key = 0;
    $dqCheckArray = array();
    while (!$dqCheck->EOF) {
      $dqCheckArray[$key] = $dqCheck->fields['dq'];
      $dqCheck->MoveNext();
      $key++;
      }
    if ($count > 0 && $prodQ >= $dqCheckArray[0]) { // if there are quantity discounts AND if the product quantity is at least as large as the lowest qty discount level
      for($x=0;$x<$count;$x++) { // first let's get the base price which applies to this quantity
        if ($x < ($count - 1) && $prodPE >= $dqCheckArray[$x] && $prodPE < $dqCheckArray[($x+1)]) { // if the quantity is >= this qty discount level but < the next higher qty discount level
            $key = $x;
            }
        elseif ($x == ($count-1)) { // if the quantity is >= the highest qty discount level, use that one
          $key = $x;
          }
        }
      $dqVal = $dqCheckArray[$key]; // select the value for the correct qty disc level in the table
      $sql = "select discount_price as dp from " . TABLE_PRODUCTS_DISCOUNT_QUANTITY . " where products_id = '" . $prodID . "' and discount_qty = '" . $dqVal . "'";
      $dp = $db->Execute($sql);
      $discPrice = $dp->fields['dp']; // yay, now we have the base price to work with
      $sql = "select customers_group_pricing as cgp from " . TABLE_CUSTOMERS . " where customers_id = '" . $_SESSION['customer_id'] . "'";
      $cgpid = $db->Execute($sql);
      $custGP = $cgpid->fields['cgp'];
      $sql = "select group_percentage as gp from ". TABLE_GROUP_PRICING . " where group_id = '" . $custGP . "'";
      $cgppct = $db->Execute($sql);
      $gpPct = $cgppct->fields['gp']; // yay, now we have the percentage by which to multiply the base price
      
      $products[$i]['final_price'] = $gpPct * $discPrice; // now, was that so hard? ;-)
      }
    }

// END MOD

store/includes/classes/shopping_cart.php

Now we want to change the 'calculate' function of the class 'shopping cart'. Strangely, the subtotal for the shopping cart is calculated not by adding up the product price * quantity for each item in your basket, at least not using the figures you see individually listed in your shopping cart! Instead it is calculated completely separately! So you need to change the shopping cart class with code which is similar to that above, but not exactly the same.

If you have an group pricing modded shopping_cart.php like me, find line 639:

if($customers_group) 

and on my line 649 is the closing bracket for a series of if... elseif... statements which look like this (again, this is in my file, YMMV):

if($customers_group == GROUP_PRICE_PER_ITEM1 && $product->fields['products_group_a_price'] != 0) {
            $products_price = $product->fields['products_group_a_price'];
          } elseif($customers_group == GROUP_PRICE_PER_ITEM2 && $product->fields['products_group_b_price'] != 0) {
            $products_price = $product->fields['products_group_b_price'];
          } elseif($customers_group == GROUP_PRICE_PER_ITEM3 && $product->fields['products_group_c_price'] != 0) {
            $products_price = $product->fields['products_group_c_price'];
          } elseif($customers_group == GROUP_PRICE_PER_ITEM4 && $product->fields['products_group_d_price'] != 0) {
            $products_price = $product->fields['products_group_d_price'];
          }

replace that entire block of code - including the opening 'if' statement and the closing bracket - with this:

if($customers_group) {
          if ($product->fields['products_discount_type'] != '0') {
            if ($qty > 1) {  // don't bother if quantity == 1
              $sql = "select discount_qty as dq from " . TABLE_PRODUCTS_DISCOUNT_QUANTITY . " where products_id = '" . $prid . "' order by discount_qty asc";
              $dqCheck = $db->Execute($sql);
              $count = $dqCheck->RecordCount();
              $key = 0;
              $dqCheckArray = array();
              while (!$dqCheck->EOF) {
                $dqCheckArray[$key] = $dqCheck->fields['dq'];
                $dqCheck->MoveNext();
                $key++;
                }
              if ($count > 0 && $qty >= $dqCheckArray[0]) { // if there are quantity discounts AND if the product quantity is at least as large as the lowest qty discount level
                for($x=0;$x<$count;$x++) { // first let's get the base price which applies to this quantity
                  if ($x < ($count - 1) && $prodPE >= $dqCheckArray[$x] && $prodPE < $dqCheckArray[($x+1)]) { // if the quantity is >= this qty discount level but < the next higher qty discount level
                    $key = $x;
                    }
                  elseif ($x == ($count-1)) { // if the quantity is >= the highest qty discount level, use that one
                    $key = $x;
                    }
                  }
                $dqVal = $dqCheckArray[$key]; // select the value for the correct qty disc level in the table
                $sql = "select discount_price as dp from " . TABLE_PRODUCTS_DISCOUNT_QUANTITY . " where products_id = '" . $prid . "' and discount_qty = '" . $dqVal . "'";
                $dp = $db->Execute($sql);
                $discPrice = $dp->fields['dp']; // yay, now we have the base price to work with
                $sql = "select group_percentage as gp from ". TABLE_GROUP_PRICING . " where group_id = '" . $product->fields['products_discount_type'] . "'";
                $cgppct = $db->Execute($sql);
                $gpPct = $cgppct->fields['gp']; // yay, now we have the percentage by which to multiply the base price
      
                $products_price = $gpPct * $discPrice; // now, was that so hard? ;-)
                }
              }
            }
          else {
            if($customers_group == GROUP_PRICE_PER_ITEM1 && $product->fields['products_group_a_price'] != 0) {
              $products_price = $product->fields['products_group_a_price'];
              }
            elseif($customers_group == GROUP_PRICE_PER_ITEM2 && $product->fields['products_group_b_price'] != 0) {
              $products_price = $product->fields['products_group_b_price'];
              }
            elseif($customers_group == GROUP_PRICE_PER_ITEM3 && $product->fields['products_group_c_price'] != 0) {
              $products_price = $product->fields['products_group_c_price'];
              }
            elseif($customers_group == GROUP_PRICE_PER_ITEM4 && $product->fields['products_group_d_price'] != 0) {
              $products_price = $product->fields['products_group_d_price'];
              }
            }
          }

if you did it right, the line after the last closing curly bracket above should read "// adjusted count for free shipping"

if anyone else finds this useful I would love to know about it. I put in several hours on getting this to work!!!

in bocca al lupo...

30 Sep 2008, 2:32 PM
#6
r_nato avatar

r_nato

New Zenner

Join Date:
Aug 2008
Posts:
41
Plugin Contributions:
0

Re: Different Quantity Discounts for customers from Group Pricing?

... also be sure to read this thread if you have installed the group product pricing mod, or your shopping cart totals will not be correct.

19 Jul 2009, 10:28 AM
#7
thenax avatar

thenax

New Zenner

Join Date:
Jun 2009
Posts:
67
Plugin Contributions:
0

Re: Different Quantity Discounts for customers from Group Pricing?

pe7er:

To give customers who are in a certain customer group pricing group (customers_group_pricing = 1)
only half (0.5) the regular quantity discount, I modified to following files:

\includes\modules\products_quantity_discounts.php
This file will display the quantity discount at the product information page.
Just above the code

$display_price = zen_get_products_base_price($products_id_current);
$display_specials_price = zen_get_products_special_price($products_id_current, true);
$disc_cnt = 1;
$quantityDiscounts = array();
$columnCount = 0;

>   
> ```
    //modification by pe7er
    //check if current customer is part of a certain (customers_group_pricing) group pricing (zen_group_pricing -> 1) category
    $gpcheck = $db->Execute("select count(*) as count from " . TABLE_CUSTOMERS . " where customers_id = '".$_SESSION['customer_id']."' AND customers_group_pricing = '1'; ");
    if ($gpcheck->fields['count'] >0){
      $distri_discount = 0.5; // the customers in this price group get 50% of the quantity discount
    }else{
      $distri_discount = 1; // other customers will receive the full quantity discount
    }// end modification.
```and I changed (about 6 lines)
> ```
= $display_price - (($products_discounts_query->fields['discount_price'] *$distri_discount)/100);
```into
> ```
= $display_price - ($display_price * (($products_discounts_query->fields['discount_price'] *$distri_discount)/100));
```**\shop\includes\functions\functions_prices.php**
> This file calculates the quantity prices.
> 
> Just AFTER:
> ```
$display_specials_price = zen_get_products_special_price($product_id, true);
```I added:```
    //modification by pe7er
    //check if current customer is part of a certain (customers_group_pricing) group pricing (zen_group_pricing -> 1) category
    $gpcheck = $db->Execute("select count(*) as count from " . TABLE_CUSTOMERS . " where customers_id = '".$_SESSION['customer_id']."' AND customers_group_pricing = '1'; ");
    if ($gpcheck->fields['count'] >0){
      $distri_discount = 0.5;
    }else{
      $distri_discount = 1;
    }       // end modification.
```and I changed (about 6 lines):
> ```
($products_discounts_query->fields['discount_price'])/100);  
```into:
> ```
(($distri_discount * $products_discounts_query->fields['discount_price'])/100));

Hi..perhaps you can help me.
I have only one price group (1) that has 5% discount
how can I do to apply 5% if total order is max 200 Dollars, +50% (7.5%) if total order is max 600 Dollars and +100% (10%) if total orders is more than 600 dollars (only to group price 1)?

thank you very much