Forums / Discounts/Coupons, Gift Certificates, Newsletters, Ads / Percentage discount based on order total?

Percentage discount based on order total?

Views: 4,315

Results 1 to 16 of 16
7 Feb 2011, 8:37 AM
#1
joyjoy avatar

joyjoy

Totally Zenned

Join Date:
Sep 2010
Posts:
611
Plugin Contributions:
0

Percentage discount based on order total?

Hi, is there a way to create a percentage discount based on an order total? I'm using a modified version of the priority handling add on. My goal is to offer customers a discount based on payment method. If they opt to pay with a bank transfer they would receive a discount.

I've to compare the price sensitive discount but because that add on calculates automatically I can't figure it out. I would need this discount only added if the customer selects this payment method a the payment screen.

Thank you.

7 Feb 2011, 11:54 AM
#3
joyjoy avatar

joyjoy

Totally Zenned

Join Date:
Sep 2010
Posts:
611
Plugin Contributions:
0

Re: Percentage discount based on order total?

Hi Kobra,

Thank you for the response. I have tried to work this one out, but I can't figure out how to modify it to fit my needs.

For this particular add on the discount will be automatically calculated as soon as the discount criteria is met(order total). What I would like to have is the discount applied only when the option is selected through the payment screen.

The add on "Priority Handling" works perfectly but it only offers an across the board percentage discount or increment discounts (ie.$25 off for every $100 spent). I'm need to create a percentage discount based on order total (ie. 10% off for orders up to $200; 15% for orders up to $500, etc.) Same idea as the Price Sensitive Discount though.

Thank you again.

7 Feb 2011, 8:29 PM
#4
joyjoy avatar

joyjoy

Totally Zenned

Join Date:
Sep 2010
Posts:
611
Plugin Contributions:
0

Re: Percentage discount based on order total?

Hey anyone out there know how I'd create this sort of discount? It should only be calculated when the discount box is selected - not automatically.

Trying to combine the discount function of "Price Sensitive Discount" and "Handling Fee" mod. Thank you.

8 Feb 2011, 2:55 AM
#5
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: Percentage discount based on order total?

Think you need to expand upon your original post title

What is is that you want to happen
What trigers it? When
Where will it happen in the progression

Where will the check box be presented?

Do not undrstand combining the handling fee??

Please expand

Zen-Venom Get Bitten

8 Feb 2011, 2:58 AM
#6
joyjoy avatar

joyjoy

Totally Zenned

Join Date:
Sep 2010
Posts:
611
Plugin Contributions:
0

Re: Percentage discount based on order total?

The check box is presented in the payment screen. Right now I use priority handling mod and it works this way. You check the option and your payment method and on the following screen the fee/discount is added.

8 Feb 2011, 3:01 AM
#7
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: Percentage discount based on order total?

What about the rest??

Zen-Venom Get Bitten

8 Feb 2011, 3:12 AM
#8
joyjoy avatar

joyjoy

Totally Zenned

Join Date:
Sep 2010
Posts:
611
Plugin Contributions:
0

Re: Percentage discount based on order total?

I don't want to combined the handling fee. Lets try this again...I think I found a mod that may be easier for me to alter. Its the payment method fee mod? This would work perfectly but I only have two options for the discount/fee. A flat discount($10 for every $100) or a percentage discount. what I need is the percentage discount based on subtotal.

DoesThat make sense?

8 Feb 2011, 3:18 AM
#9
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: Percentage discount based on order total?

Lets try this again...
what I need is the percentage discount based on subtotal.
Contribution I referenced
This Contrib gives your customers a variable discount based on the order SUBTOTAL.
So lets try this again...
What is wrong with it and

What
Where
When

is it not "fitting your needs"

Zen-Venom Get Bitten

8 Feb 2011, 4:11 AM
#10
joyjoy avatar

joyjoy

Totally Zenned

Join Date:
Sep 2010
Posts:
611
Plugin Contributions:
0

Re: Percentage discount based on order total?

Okay, the mod that you recommended does the calculations that I want to achieve but it applies the discount automatically based on subtotal, which is not what I want.

I want the discount to be applied ONLY when a particular payment method is used. This mod found here: http://www.numinix.com/zen-cart-modules/taxes-order-totals/payment-module-fee does what I need...but it only offers a specific percentage discount (i.e. 25% across the board) or a flat rate discount (i.e. $10). I want it to calculate a tiered percentage discount, just like the way the price sensitive mod works (i.e. 10%:$100, 15%:$200, etc.).

This mod that is referenced calculates automatically without having to worry about the check box option.

8 Feb 2011, 6:59 PM
#11
joyjoy avatar

joyjoy

Totally Zenned

Join Date:
Sep 2010
Posts:
611
Plugin Contributions:
0

Re: Percentage discount based on order total?

Anyone else wanna take a look at this? I know the thread is uber confusing...please let me know if you need further clarification. Thank you.

9 Feb 2011, 12:01 AM
#12
joyjoy avatar

joyjoy

Totally Zenned

Join Date:
Sep 2010
Posts:
611
Plugin Contributions:
0

Re: Percentage discount based on order total?

Here are the two mods I have:

PRICE SENSITIVE DISCOUNT

<?php
/*

>>> Rabatt ab xxx Bestellwert 1.0
Modifiziert von Maleborg für Zencart

Weitere Credits
<<<<<<< ot_lev_discount.php
  $Id: ot_lev_discount.php,v 1.0 2002/04/08 01:13:43 hpdl Exp $
=======
  $Id: ot_lev_discount.php,v 1.3 2002/09/04 22:49:11 wilt Exp $
  $Id: ot_lev_discount.php,v 2.4 2006/02/28 12:10:01 maniac101 Exp $
modified to calc discount correctly when tax is included in discount
>>>>>>> 2.4

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2002 osCommerce

  Released under the GNU General Public License
*/

  class ot_lev_discount {
    var $title, $output;

    function ot_lev_discount() {
      $this->code = 'ot_lev_discount';
      $this->title = MODULE_LEV_DISCOUNT_TITLE;
      $this->description = MODULE_LEV_DISCOUNT_DESCRIPTION;
      $this->enabled = MODULE_LEV_DISCOUNT_STATUS;
      $this->sort_order = MODULE_LEV_DISCOUNT_SORT_ORDER;
      $this->include_shipping = MODULE_LEV_DISCOUNT_INC_SHIPPING;
      $this->include_tax = MODULE_LEV_DISCOUNT_INC_TAX;
      $this->calculate_tax = MODULE_LEV_DISCOUNT_CALC_TAX;
      $this->table = MODULE_LEV_DISCOUNT_TABLE;
//      $this->credit_class = true;
      $this->output = array();
    }

    function process() {
      global $order, $ot_subtotal, $currencies, $db;
      $od_amount = $this->calculate_credit($this->get_order_total());
      if ($od_amount>0) {
      $this->deduction = $od_amount;
      $this->output[] = array('title' => $this->title . ':',
                              'text' => '-' . $currencies->format($od_amount),
                              'value' => $od_amount);
    $order->info['total'] = $order->info['total'] - $od_amount;
    if ($this->sort_order < $ot_subtotal->sort_order) {
      $order->info['subtotal'] = $order->info['subtotal'] - $od_amount;
    }
}
    }
     
   
  function calculate_credit($amount) {
    global $order;
    $od_amount=0;
    $table_cost = split("[:,]" , MODULE_LEV_DISCOUNT_TABLE);
    for ($i = 0; $i < count($table_cost); $i+=2) {
          if ($amount >= $table_cost[$i]) {
            $od_pc = $table_cost[$i+1];
          }
        }
// Calculate tax reduction if necessary
    if($this->calculate_tax == 'true') {
// Calculate main tax reduction
      $tod_amount = round($order->info['tax']*10)/10*$od_pc/100;
      $order->info['tax'] = $order->info['tax'] - $tod_amount;
// Calculate tax group deductions
      reset($order->info['tax_groups']);
      while (list($key, $value) = each($order->info['tax_groups'])) {
        $god_amount = round($value*10)/10*$od_pc/100;
        $order->info['tax_groups'][$key] = $order->info['tax_groups'][$key] - $god_amount;
      }  
    }
    $od_amount = round($amount*10)/10*$od_pc/100;
//    $od_amount = $od_amount + $tod_amount;
// maniac101 above line was adding tax back into discount incorrectly for me
    return $od_amount;
  }


  function get_order_total() {
    global  $order, $cart, $db;
    $order_total = $order->info['total'];
// Check if gift voucher is in cart and adjust total
//    $products = $cart -> get_products();
    for ($i=0; $i<sizeof($products); $i++) {
      $t_prid = zen_get_prid($products[$i]['id']);
      $gv_query = $db->Execute("select products_price, products_tax_class_id, products_model from " . TABLE_PRODUCTS . " where products_id = '" . $t_prid . "'");
      //$gv_result = zen_db_fetch_array($gv_query);
      if (ereg('^GIFT', addslashes($gv_result['products_model']))) { 
        $qty = $cart->get_quantity($t_prid);
        $products_tax = zen_get_tax_rate($gv_result['products_tax_class_id']);
        if ($this->include_tax =='false') {
           $gv_amount = $gv_result['products_price'] * $qty;
        } else {
          $gv_amount = ($gv_result['products_price'] + zen_calculate_tax($gv_result['products_price'],$products_tax)) * $qty;
        }
        $order_total=$order_total - $gv_amount;
      }
    }
    if ($this->include_tax == 'false') $order_total=$order_total-$order->info['tax'];
    if ($this->include_shipping == 'false') $order_total=$order_total-$order->info['shipping_cost'];
    return $order_total;
  }   
    
    
    
    function check() {
	  global $db;
      if (!isset($this->check)) {
        $check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_LEV_DISCOUNT_STATUS'");
        $this->check = $check_query->RecordCount();
      }

      return $this->check;
    }

    function keys() {
      return array('MODULE_LEV_DISCOUNT_STATUS', 'MODULE_LEV_DISCOUNT_SORT_ORDER','MODULE_LEV_DISCOUNT_TABLE', 'MODULE_LEV_DISCOUNT_INC_SHIPPING', 'MODULE_LEV_DISCOUNT_INC_TAX','MODULE_LEV_DISCOUNT_CALC_TAX');
    }

    function install() {
      global $db;
      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Display Total', 'MODULE_LEV_DISCOUNT_STATUS', 'true', 'Do you want to enable the Order Discount?', '6', '1','zen_cfg_select_option(array(\'true\', \'false\'), ', now())");
      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_LEV_DISCOUNT_SORT_ORDER', '50', 'Sort order of display.', '6', '2', now())");
      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function ,date_added) values ('Include Shipping', 'MODULE_LEV_DISCOUNT_INC_SHIPPING', 'false', 'Include Shipping in calculation', '6', '3', 'zen_cfg_select_option(array(\'true\', \'false\'), ', now())");
      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function ,date_added) values ('Include Tax', 'MODULE_LEV_DISCOUNT_INC_TAX', 'true', 'Include Tax in calculation.', '6', '4','zen_cfg_select_option(array(\'true\', \'false\'), ', now())");
      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function ,date_added) values ('Calculate Tax', 'MODULE_LEV_DISCOUNT_CALC_TAX', 'true', 'Re-calculate Tax on discounted amount.', '6', '5','zen_cfg_select_option(array(\'true\', \'false\'), ', now())");
      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Discount Percentage', 'MODULE_LEV_DISCOUNT_TABLE', '100:7.5,250:10,500:12.5,1000:15', 'Set the price breaks and discount percentages', '6', '6', now())");
    }

    function remove() {
      $keys = '';
      $keys_array = $this->keys();
      for ($i=0; $i<sizeof($keys_array); $i++) {
        $keys .= "'" . $keys_array[$i] . "',";
      }
      $keys = substr($keys, 0, -1);

      global $db;
      $db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key in (" . $keys . ")");
    }
  }
?>

PAYMENT MODULE FEE/DISCOUNT

<?php
/**
 * ot_total order-total module
 *
 * @package orderTotal
 * @copyright Copyright 2003-2007 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: ot_paymentmodulefee.php 2 2010-09-17 03:38:17Z numinix $
 */
  class ot_paymentmodulefee {
    var $title, $output;

    function ot_paymentmodulefee() {
      $this->code = 'ot_paymentmodulefee';
      $this->title = MODULE_ORDER_TOTAL_PAYMENTMODULEFEE_TITLE;
      $this->description = MODULE_ORDER_TOTAL_PAYMENTMODULEFEE_DESCRIPTION;
      $this->sort_order = MODULE_ORDER_TOTAL_PAYMENTMODULEFEE_SORT_ORDER;
      $this->payment_modules = explode(',', MODULE_ORDER_TOTAL_PAYMENTMODULEFEE_PAYMENT_MODULES); 
      $this->output = array();
    }

    function process() {
      global $order, $currencies;

      if (MODULE_ORDER_TOTAL_PAYMENTMODULEFEE_FEE_ALLOW == 'true') {
        switch (MODULE_ORDER_TOTAL_PAYMENTMODULEFEE_DESTINATION) {
          case 'national':
            if ($order->delivery['country_id'] == STORE_COUNTRY) $pass = true; break;
          case 'international':
            if ($order->delivery['country_id'] != STORE_COUNTRY) $pass = true; break;
          case 'both':
            $pass = true; break;
          default:
            $pass = false; break;
        }

        if (($pass == true) && in_array($_SESSION['payment'], $this->payment_modules)) {
          $charge_it = 'true';
          if ($charge_it == 'true') {
            $tax_address = zen_get_tax_locations();
            $tax = zen_get_tax_rate(MODULE_ORDER_TOTAL_PAYMENTMODULEFEE_TAX_CLASS, $tax_address['country_id'], $tax_address['zone_id']);
            $tax_description = zen_get_tax_description(MODULE_ORDER_TOTAL_PAYMENTMODULEFEE_TAX_CLASS, $tax_address['country_id'], $tax_address['zone_id']);
            $key = array_search($_SESSION['payment'], $this->payment_modules);
            $this->payment_fees = explode(',', MODULE_ORDER_TOTAL_PAYMENTMODULEFEE_FEE);
            $this->payment_fee = $this->payment_fees[$key]; 
// calculate from flat fee or percentage
            if (substr($this->payment_fee, -1) == '%') {
              $payment_module_fee = ($order->info['subtotal'] * ($this->payment_fee/100));
            } else {
              $payment_module_fee = $this->payment_fee;
            }


            $order->info['tax'] += zen_calculate_tax($payment_module_fee, $tax);
            $order->info['tax_groups']["$tax_description"] += zen_calculate_tax($payment_module_fee, $tax);
            $order->info['total'] += $payment_module_fee + zen_calculate_tax($payment_module_fee, $tax);
            if (DISPLAY_PRICE_WITH_TAX == 'true') {
              $payment_module_fee += zen_calculate_tax($payment_module_fee, $tax);
            }

            $this->output[] = array('title' => $this->title . ':',
                                    'text' => $currencies->format($payment_module_fee, true, $order->info['currency'], $order->info['currency_value']),
                                    'value' => $payment_module_fee);
          }
        }
      }
    }

    function check() {
	  global $db;
      if (!isset($this->_check)) {
        $check_query = "select configuration_value
                        from " . TABLE_CONFIGURATION . "
                        where configuration_key = 'MODULE_ORDER_TOTAL_PAYMENTMODULEFEE_STATUS'";

        $check_query = $db->Execute($check_query);
        $this->_check = $check_query->RecordCount();
      }

      return $this->_check;
    }

    function keys() {
      return array('MODULE_ORDER_TOTAL_PAYMENTMODULEFEE_STATUS', 'MODULE_ORDER_TOTAL_PAYMENTMODULEFEE_SORT_ORDER', 'MODULE_ORDER_TOTAL_PAYMENTMODULEFEE_FEE', 'MODULE_ORDER_TOTAL_PAYMENTMODULEFEE_FEE_ALLOW', 'MODULE_ORDER_TOTAL_PAYMENTMODULEFEE_PAYMENT_MODULES', 'MODULE_ORDER_TOTAL_PAYMENTMODULEFEE_DESTINATION', 'MODULE_ORDER_TOTAL_PAYMENTMODULEFEE_TAX_CLASS');
    }

    function install() {
      global $db;
      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('This module is installed', 'MODULE_ORDER_TOTAL_PAYMENTMODULEFEE_STATUS', 'true', '', '6', '1','zen_cfg_select_option(array(\'true\'), ', now())");
      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_ORDER_TOTAL_PAYMENTMODULEFEE_SORT_ORDER', '500', 'Sort order of display.', '6', '2', now())");
      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Allow Payment Module Fee', 'MODULE_ORDER_TOTAL_PAYMENTMODULEFEE_FEE_ALLOW', 'false', 'Do you want to allow payment module fees?', '6', '3', 'zen_cfg_select_option(array(\'true\', \'false\'), ', now())");
      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, date_added) values ('Payment Modules', 'MODULE_ORDER_TOTAL_PAYMENTMODULEFEE_PAYMENT_MODULES', 'paypalwpp,paypal', 'Enter the payment module codes separate by commas (no spaces)', '6', '4', '', now())");
      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, date_added) values ('Fee', 'MODULE_ORDER_TOTAL_PAYMENTMODULEFEE_FEE', '2%,5', 'For Percentage Calculation - include a % Example: 10%<br />For a flat amount just enter the amount - Example: 5 for $5.00', '6', '5', '', now())");
      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Attach Payment Module Fee On Orders Made', 'MODULE_ORDER_TOTAL_PAYMENTMODULEFEE_DESTINATION', 'both', 'Attach payment module fee for orders sent to the set destination.', '6', '6', 'zen_cfg_select_option(array(\'national\', \'international\', \'both\'), ', now())");
      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Tax Class', 'MODULE_ORDER_TOTAL_PAYMENTMODULEFEE_TAX_CLASS', '0', 'Use the following tax class on the payment module fee.', '6', '7', 'zen_get_tax_class_title', 'zen_cfg_pull_down_tax_classes(', now())");
    }

    function remove() {
	  global $db;
      $db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
    }
  }
?>

Here's how they both function.
PRICE SENSITIVE DISOUNT: offers a discount based on subtotal. This discount is automatically calculated and does not have any restrictions or any other trigger factors.

PAYMENT MODULE FEE/DISCOUNT: offers a discount based on a specified payment method.

What I am trying to acheive:
I want to use the payment module discount. This mod only offers two types of discounts to be set. Either a set percentage discount (i.e. 10%) or a tiered discount($10 off $100, $20 off $200, etc). I want to offer a tiered percentage discount (i.e. 10% off $100, 20% off $200, etc.) this is where the "PRICE SENSITIVE DISCOUNT MOD" comes in. That mod DOES have the tiered percentage discount option. I am trying to use THAT function on the "PAYMENT MODULE FEE MOD" but I don't know how to do this...

I'm trying to be as clear as possible. Can anyone help? Please?

9 Feb 2011, 8:21 AM
#13
joyjoy avatar

joyjoy

Totally Zenned

Join Date:
Sep 2010
Posts:
611
Plugin Contributions:
0

Re: Percentage discount based on order total?

No one? :blink:

9 Feb 2011, 6:41 PM
#14
joyjoy avatar

joyjoy

Totally Zenned

Join Date:
Sep 2010
Posts:
611
Plugin Contributions:
0

Re: Percentage discount based on order total?

Can anyone help? If any moderator reads this can I put this post in the other add ons category? It would also be relevant there...but I don't want to get in trouble for reposting.

10 Feb 2011, 12:20 AM
#15
swguy avatar

swguy

Administrator

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

Re: Percentage discount based on order total?

You're going to have to hire someone to do this work for you.

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.

10 Feb 2011, 12:23 AM
#16
joyjoy avatar

joyjoy

Totally Zenned

Join Date:
Sep 2010
Posts:
611
Plugin Contributions:
0

Re: Percentage discount based on order total?

Bummer! It seems like something that would be easy...hmmm..

You up for it? PM me?:bigups: