Page 2 of 2 FirstFirst 12
Results 11 to 17 of 17
  1. #11
    Join Date
    Sep 2008
    Posts
    22
    Plugin Contributions
    0

    Idea or Suggestion 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
    Code:
          $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:
    Code:
          // 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;

  2. #12
    Join Date
    Sep 2008
    Posts
    22
    Plugin Contributions
    0

    Default 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
    Code:
          // 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'];
          if ( isset($no_discount_id) ) {
            $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;
          }

  3. #13
    Join Date
    Mar 2011
    Posts
    78
    Plugin Contributions
    0

    Default 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.

  4. #14
    Join Date
    Sep 2008
    Posts
    22
    Plugin Contributions
    0

    Default 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:

    Code:
          // 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'];
          $no_discount_id2 = $db->Execute("select categories_id from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_name = 'NO DISCOUNT 2'")->fields['categories_id'];
          if ( isset($no_discount_id) || isset($no_discount_id2) ) {
            $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;
          }

  5. #15
    Join Date
    Jul 2012
    Posts
    16,718
    Plugin Contributions
    17

    Default Re: Exclude items from the Group Pricing Discount

    Quote Originally Posted by gsh68 View Post
    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).
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  6. #16
    Join Date
    Mar 2011
    Posts
    78
    Plugin Contributions
    0

    Default Re: Exclude items from the Group Pricing Discount

    Quote Originally Posted by llemberg View Post
    I haven't tested this, but it might work to just check for your multiple NO DISCOUNT categories. Try the changes in blue:

    Code:
          // 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'];
          $no_discount_id2 = $db->Execute("select categories_id from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_name = 'NO DISCOUNT 2'")->fields['categories_id'];
          if ( isset($no_discount_id) || isset($no_discount_id2) ) {
            $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.

  7. #17
    Join Date
    Mar 2011
    Posts
    78
    Plugin Contributions
    0

    Default 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?

 

 
Page 2 of 2 FirstFirst 12

Similar Threads

  1. ZC 1.5 Group Pricing is Doubling the Discount
    By independenteasel in forum Managing Customers and Orders
    Replies: 0
    Last Post: 15 Aug 2013, 09:18 PM
  2. group pricing exclude some master categories
    By count in forum Discounts/Coupons, Gift Certificates, Newsletters, Ads
    Replies: 0
    Last Post: 20 Jan 2013, 11:42 PM
  3. v150 Exclude already discounted items from Group discounts
    By Defkon1 in forum Discounts/Coupons, Gift Certificates, Newsletters, Ads
    Replies: 0
    Last Post: 2 Sep 2012, 08:35 AM
  4. v139h Exclude category or product from group discount
    By abcisme in forum Discounts/Coupons, Gift Certificates, Newsletters, Ads
    Replies: 0
    Last Post: 10 Aug 2012, 02:51 PM
  5. Exclude attributes from discounting in online group pricing
    By danwebman in forum All Other Contributions/Addons
    Replies: 0
    Last Post: 27 Jan 2012, 08:02 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR