Jump to content

Recommended Posts

Just now, ArtcoInc said:

@Kevin.Dallas

The math looks right to me. 10% of $79.90 = $7.99

M

i was doing a .95 % instate of .10

can you help me on the product exclusion, upon selecting which product i need to exclude when i highlight the products and apply it still gives a discount on the excluded product

Share this post


Link to post
Share on other sites
15 minutes ago, Kevin.Dallas said:

i was doing a .95 % instate of .10

can you help me on the product exclusion, upon selecting which product i need to exclude when i highlight the products and apply it still gives a discount on the excluded product

ok it's working thank you

Share this post


Link to post
Share on other sites

happy holidays

I am trying to use this along with order editor, and have been somehow successful. 

I made some modification to the  process() function to simply return the discount like this 

     if (!empty($discount)) {
    //  $output[] = array('title' => (($shipping_discount == 'true')? TEXT_SHIPPING_DISCOUNT : TEXT_DISCOUNT) . (strpos($check['discount_values'], '%') ? ' ' . $check['discount_values'] . ' ' : '') . (!empty($order_info) ? ' (' . $discount_codes . ')' : '') . ':',
                           //     'text' => '<span style="color:#ff0000">' . $discount_formatted . '</span>',
                            //   'value' => -$discount);
    return $discount_formatted;

this returns the value of coupon correctly but it seems to deduct the $discount twice.

I was wondering why.

is it done on purpose because, this value get added to the total at a later date by the ot_discount?

or there is something wrong with my changes?

 

Share this post


Link to post
Share on other sites

Hello @hungryfrank,

I would recommend you to address this within the order editor support. It's very tricky to get it work correct with order editor.

Share this post


Link to post
Share on other sites

it is working perfectly.i had to make some minor changes in your function.

the only thing is that I think sometimes after you call this function this value gets added to the total again by the shop itself . sometime in the buying process. and you deduct it twice here to compensate for that. 

 

i

Share this post


Link to post
Share on other sites

Sorry I can't follow up this problem with the info you are giving.

52 minutes ago, hungryfrank said:

it is working perfectly.i had to make some minor changes in your function.

Which exact changes? only what you posted in the first message, or more?

52 minutes ago, hungryfrank said:

the only thing is that I think sometimes after you call this function this value gets added to the total again by the shop itself . sometime in the buying process. and you deduct it twice here to compensate for that.

Please elaborate with concrete examples. Where/when does it get added? in checkout_confirmation.php?

What do you mean by "sometimes", any rule for this?

Where is it deducted twice??

 

Try to check if it occurs due to your modification. If yes, apply your mod only for the order editor.

If ( basename($PHP_SELF) == 'order_editor.php') {
here your mod
} else {
original code
}

If it happens also with the original code, I mean it's inherit in the unmodified code, then post a concrete example which I can try to reproduce.

- all discount details

- payment module

- shipping module

- list of all order total amounts given in checkout_confirmation.php

 

 

Edited by raiwa

Share this post


Link to post
Share on other sites
  function process2() {
      global $order, $currencies, $currency, $customer_id, $discount,$discount_codes;
    // echo 'llll'.$discount_codes;
      $discount = 0;
      $subtotal_correction = 0;
      $tax_correction = 0;
      $shipping_discount = 'false';

      if (!empty($discount_codes)) {
        $check_query = tep_db_query("select count(*) as total, dc.number_of_use from discount_codes dc, customers_to_discount_codes c2dc where dc.discount_codes_id = c2dc.discount_codes_id and dc.discount_codes = '" . tep_db_input($discount_codes) . "' and c2dc.customers_id = '" . (int)$customer_id . "' group by c2dc.customers_id limit 1");
        if (tep_db_num_rows($check_query) == 0) {
          $check['number_of_use'] = 0;
        } else {
          $check = tep_db_fetch_array($check_query);
        }
        if (($check['number_of_use'] == 0 ? 1 : ($check['total'] < $check['number_of_use'] ? 1 : 0)) == 1) {
          $check_query = tep_db_query("select * from discount_codes where discount_codes = '" . tep_db_input($discount_codes) . "' and if(expires_date = '0000-00-00', date_format(date_add(now(), interval 1 day), '%Y-%m-%d'), expires_date) >= date_format(now(), '%Y-%m-%d') and minimum_order_amount <= " . $order->info['subtotal'] . " and status = '1' limit 1");
          if (tep_db_num_rows($check_query)) {
            $check = tep_db_fetch_array($check_query);
            $order_info = $check['order_info'];

            if (!empty($check['customers_id'])) {
              $customers = explode(',', $check['customers_id']);
            } else {
              $customers = array($customer_id);
            }

            if (!empty($check['newsletter'])) {
              $check_query_news = tep_db_query("select customers_newsletter from customers where customers_id = '" . (int)$customer_id . "'");
              $check_news = tep_db_fetch_array($check_query_news);
              $newsletter = $check_news['customers_newsletter'];
            }

            if (!empty($check['order_number'])) {
            	$check_query_order = tep_db_query("select count(*) as orders from orders where customers_id = '" . (int)$customer_id . "'");
            	$check_order = tep_db_fetch_array($check_query_order);
            	$orders = $check_order['orders']+1;
            	// Support for PWA guest orders BEGIN
            	if (tep_db_num_rows(tep_db_query("select * from information_schema.columns where table_schema='". DB_DATABASE . "' and table_name='orders' and column_name like 'customers_guest'")) == 1 ) {
            	  $check_query_mail = tep_db_query("select customers_email_address from customers where customers_id = '" . (int)$customer_id . "'");
            	  $check_mail = tep_db_fetch_array($check_query_mail);
            	  if (!empty($check_mail['customers_email_address'])) {
            	    $check_query_order_guest = tep_db_query("select count(*) as orders from orders where customers_email_address = '" . $check_mail['customers_email_address'] . "' and customers_guest = '1'");
            	    $check_order_guest = tep_db_fetch_array($check_query_order_guest);
            	    $orders = $orders + $check_order_guest['orders'];
            	  }
            	}
            	// Support for PWA guest orders END
            }

            if ( (empty($check['newsletter']) || $newsletter == 1) && (empty($check['order_number']) || $orders == $check['order_number']) ) {
              if (in_array($customer_id, $customers)) {
                if (!empty($check['products_id']) || !empty($check['categories_id']) || !empty($check['manufacturers_id']) || (int)$check['exclude_specials'] == 1) {

                  $products = array();
                  if (!empty($check['products_id'])) {
                    $products = explode(',', $check['products_id']);
                  } elseif (!empty($check['categories_id'])) {
                    $product_query = tep_db_query("select products_id from products_to_categories where categories_id in (" . $check['categories_id'] . ")" . (empty($check['excluded_products_id']) ? '' : " and products_id not in (" . $check['excluded_products_id'] . ")"));
                    while ($product = tep_db_fetch_array($product_query)) {
                      $products[] = $product['products_id'];
                    }
                  } elseif (!empty($check['manufacturers_id'])) {
                    $product_query = tep_db_query("select products_id from products where manufacturers_id in (" . $check['manufacturers_id'] . ")" . (empty($check['excluded_products_id']) ? '' : " and products_id not in (" . $check['excluded_products_id'] . ")"));
                    while ($product = tep_db_fetch_array($product_query)) {
                      $products[] = $product['products_id'];
                    }
                  } elseif ((int)$check['exclude_specials'] == 1) {
                    for ($i = 0, $n = sizeof($order->products); $i < $n; $i++) {
                      $products[] = $order->products[$i]['id'];
                    }
                  }

                  if ((int)$check['exclude_specials'] == 1) {
                    $specials = array();
                    $product_query = tep_db_query("select p.products_id from products p, specials s where p.products_id = s.products_id and s.status = '1' and ifnull(s.expires_date, now()) >= now()");
                    while ($product = tep_db_fetch_array($product_query)) {
                      $specials[] = $product['products_id'];
                    }
                    if (sizeof($specials) > 0) {
                      $products = array_diff($products, $specials);
                    }
                  }

                  if (empty($check['number_of_products'])) {
                    $k = PHP_INT_MAX;
                  } else {
                    $k = $check['number_of_products'];
                  }

                  for ($i = 0, $n = sizeof($order->products); $i < $n; $i++) {
                    if (in_array(tep_get_prid($order->products[$i]['id']), $products)) {
                      if ($k >= $order->products[$i]['qty']) {
                        $products_discount = $this->format_raw(strpos($check['discount_values'], '%') === false ? $check['discount_values'] * $order->products[$i]['qty'] : tep_add_tax($order->products[$i]['final_price'], $order->products[$i]['tax']) * str_replace('%', '', $check['discount_values']) / 100 * $order->products[$i]['qty']);
                        $k -= $order->products[$i]['qty'];
                      } else {
                        $products_discount = $this->format_raw(strpos($check['discount_values'], '%') === false ? $check['discount_values'] * $k : tep_add_tax($order->products[$i]['final_price'], $order->products[$i]['tax']) * str_replace('%', '', $check['discount_values']) / 100 * $k);
                        $k = 0;
                      }

                      if (!empty($order->products[$i]['tax'])) {
                        if (DISPLAY_PRICE_WITH_TAX != 'true') {
                          $tax_correction = $currencies->format_raw(($products_discount * ($order->products[$i]['tax'] / 100)));
                          $order->info['total'] -= $tax_correction;
                        } else {
                          $tax_correction = $currencies->format_raw($products_discount - $products_discount / (1.0 + $order->products[$i]['tax'] / 100));
                        }
                      }
                      $subtotal_correction +=  $order->products[$i]['final_price']; //use for tax calculation only products which have taxes
                      $order->info['tax'] -= $tax_correction;
                      $order->info['tax_groups'][$order->products[$i]['tax_description']] -= $tax_correction;
                      $discount += $products_discount;
                    }
                  }

                  // revert currency conversion to default currency
                  $order->info['total'] -= $currencies->format_raw($discount, true, $order->info['currency'], 1/$order->info['currency_value']);
                  
                  // format discount for output, do not apply currency conversion, product price already converted to order currency
                  $discount_formatted = $currencies->format($discount, false);
                  
                } elseif (!empty($check['orders_total'])) {
                  if ($check['orders_total'] == 2) {
                    $discount = (strpos($check['discount_values'], '%') === false ? $check['discount_values'] : $order->info['subtotal'] * str_replace('%', '', $check['discount_values']) / 100);
                    if ($discount > $order->info['subtotal']) {
                      $discount = $order->info['subtotal'];
                    }
                    $order_tax = $order->info['tax'];
                    if (DISPLAY_PRICE_WITH_TAX == 'true' &&  MODULE_ORDER_TOTAL_DISCOUNT_TAX_CALCULATION_EXCL == 'true' ) {
                      // find order subtotal excl. tax
                      $order_subtotal_excl = null;
                      for ($i = 0, $n = sizeof($order->products); $i < $n; $i++) {
                        $order_subtotal_excl += $order->products[$i]['qty'] * $order->products[$i]['final_price'];
                      } 
                      for ($i = 0, $n = sizeof($order->products); $i < $n; $i++) {
                        if (!empty($order->products[$i]['tax'])) {
                          $portion = ($order->products[$i]['qty'] * $order->products[$i]['final_price']) / $order_subtotal_excl;
                          $global_tax_correction = $discount * $portion;
                          $discount_excl = ($global_tax_correction / (1+$order->products[$i]['tax']/100));
                          $discount_tax = $global_tax_correction - $discount_excl;
                          // strip discount from order total
                          $order->info['total'] -= $currencies->format_raw($global_tax_correction);
                          // correct tax
                          if (!empty($discount_tax) && is_array($order->info['tax_groups']) && count($order->info['tax_groups']) > 0) {
                            foreach ($order->info['tax_groups'] as $key => $value) {
                              if ($key == $order->products[$i]['tax_description']) {
                               $order->info['tax_groups'][$key] -= $discount_tax;
                               $order->info['tax'] -= $discount_tax;
                              }
                            } // end for each tax group
                          } // if discount tax and tax groups
                        } // end if products tax
                      } // end products loop
                  } else {
                    for ($i = 0, $n = sizeof($order->products); $i < $n; $i++) {
                      if (!empty($order->products[$i]['tax'])) {
                        //here it gets complicate, we have to find the proportional part of the global discount for each product
                        $global_tax_correction = $order->products[$i]['qty']*(( $order->products[$i]['final_price']/$order->info['subtotal'])*$discount)+(($order->products[$i]['qty']* $order->products[$i]['final_price']/$order->info['subtotal'])*$discount) * ($order->products[$i]['tax'] / 100);
                        $order->info['total'] -= $global_tax_correction;
                      }
                    }
                  
                    if (is_array($order->info['tax_groups']) && count($order->info['tax_groups']) > 0) {
                      foreach ($order->info['tax_groups'] as $key => $value) {
                        if (!empty($value)) {
                          $order->info['tax_groups'][$key] = $this->format_raw(($order->info['subtotal'] - $discount) * ($value / $order->info['subtotal']));
                          $order_tax += $order->info['tax_groups'][$key];
                        }
                      }
                    }
                  }
                                    
                  if ( tep_not_null($order_tax)) {
                    $order->info['tax'] = $order_tax;
                  } else {
                    $order->info['total'] -= $discount;                  
                  }
                  
                }
                // format discount for output, apply currency conversion
                $discount_formatted = $currencies->format($discount, true, $order->info['currency'], $order->info['currency_value']);

                } elseif (!empty($check['shipping'])) { //.eof $check['orders_total']
                  $shipping_tax = 0;
                  if ($check['shipping'] == 2) {
                    $module = substr($GLOBALS['shipping']['id'], 0, strpos($GLOBALS['shipping']['id'], '_'));
                    if (tep_not_null($order->info['shipping_method'])) {
                      if ($GLOBALS[$module]->tax_class > 0) {
                        $shipping_tax = tep_get_tax_rate($GLOBALS[$module]->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
                      }
                    }
                	$discount = $order->info['shipping_cost'] * str_replace('%', '', strtolower($check['discount_values'])) / 100;
                    if ($discount > $order->info['shipping_cost']) {
                      $discount = $order->info['shipping_cost'];
                    }
                    if (DISPLAY_PRICE_WITH_TAX == 'true' && MODULE_ORDER_TOTAL_DISCOUNT_SORT_ORDER <= MODULE_ORDER_TOTAL_SHIPPING_SORT_ORDER ) $discount += tep_calculate_tax($discount, $shipping_tax);
                    $order_tax = 0;
                    if (is_array($order->info['tax_groups']) && count($order->info['tax_groups']) > 0) {
                      if ( MODULE_ORDER_TOTAL_DISCOUNT_SORT_ORDER <= MODULE_ORDER_TOTAL_SHIPPING_SORT_ORDER ) { // discount before shipping
                        foreach ($order->info['tax_groups'] as $key => $value) {
                          if (!empty($value)) {
                            if ($shipping_tax > 0) {
                              $order->info['tax_groups'][$key] = $currencies->format_raw(($order->info['subtotal'] - $discount) * ($value / $order->info['subtotal']));
                            } else {
                              $order->info['tax_groups'][$key] = $currencies->format_raw(($order->info['subtotal']) * ($value / $order->info['subtotal']));
                            }
                            $order_tax += $order->info['tax_groups'][$key];
                          }
                        }
                      } else { // shipping before discount
                        foreach ($order->info['tax_groups'] as $key => $value) {
                          if (!empty($value)) {
                            if ($shipping_tax > 0) {
                              $order->info['tax_groups'][$key] = $currencies->format_raw(($order->info['subtotal']) * (($value - tep_calculate_tax(((DISPLAY_PRICE_WITH_TAX == 'true')? $discount / (1 + $shipping_tax / 100) : $discount ), $shipping_tax)) / $order->info['subtotal']));
                            } else {
                              $order->info['tax_groups'][$key] = $currencies->format_raw(($order->info['subtotal']) * ($value / $order->info['subtotal']));
                            }
                            $order_tax += $order->info['tax_groups'][$key];
                          }
                        }
                      }
                    }
                    $order->info['total'] -= $discount;
                    if (DISPLAY_PRICE_WITH_TAX != 'true') $order->info['total'] -= tep_calculate_tax($order->info['shipping_cost'], $shipping_tax);
                    if (!empty($order_tax)) $order->info['tax'] = $order_tax;
                    $shipping_discount = 'true';
                  }
                  
                  // format discount for output, apply currency conversion
                  $discount_formatted = $currencies->format($discount, true, $order->info['currency'], $order->info['currency_value']);

                } //.eof $check['shipping']
                if ( MODULE_ORDER_TOTAL_DISCOUNT_SHOW_SHIPPING_DISCOUNTED == 'true' && $shipping_discount == 'true') {
                  $order->info['shipping_cost'] -= $discount;
                }
                
                if ( MODULE_ORDER_TOTAL_DISCOUNT_SORT_ORDER <= MODULE_ORDER_TOTAL_SUBTOTAL_SORT_ORDER ) { // discount before order subtotal
                  $order->info['subtotal'] -= $discount;
                }
              } // eof check newsletter and order number
            }
          }
        }
      }

      if (!empty($discount)) {
    //  $output[] = array('title' => (($shipping_discount == 'true')? TEXT_SHIPPING_DISCOUNT : TEXT_DISCOUNT) . (strpos($check['discount_values'], '%') ? ' ' . $check['discount_values'] . ' ' : '') . (!empty($order_info) ? ' (' . $discount_codes . ')' : '') . ':',
                           //     'text' => '<span style="color:#ff0000">' . $discount_formatted . '</span>',
                            //   'value' => -$discount);
//  tep_db_query("update orders_total SET 	value='".$discount."' where class='ot_discount' and orders_id='".(int)$oID."'");

    return $discount;
      }
    }

hi

I have managed to get the $discount (only for a basic discount code)

but it subtracts twice that amount from order_total

it updates the discount_codes table.

 


 

edit_orders.php

Share this post


Link to post
Share on other sites

the issue is that the function deducts twice as much as the actual discount.

this might be because at a later stage in the checkout process somehow the value of the discount is added again.

or it might be because of my modifications.

for example iff the value of the discount is $3 it shows that it is $3 at the end but somehow it deducted 6 from the total already

 

Edited by hungryfrank

Share this post


Link to post
Share on other sites
11 hours ago, hungryfrank said:

  function process2() {

 

It looks like you have duplicated the function or module. This would explain why you get the discount duplicated.

Instead to duplicate the function/module, do this:

global $PHP_SELF;

if ( basename($PHP_SELF) == 'order_editor.php') {
here your mod
} else {
here the original code
}

For further support on this, please post in the order editor support thread. This is primary an order editor problem, not a discount code issue.

Edited by raiwa

Share this post


Link to post
Share on other sites
We have this discount code setup, everything is working as it should.
 
But I have recently noticed a problem, we have a valid discount code setup to use as a one-time use only but we have found out that customers who pay using PayPal Pro (card payments) can use the code over and over again.
 
Please can someone help us fix this problem?
 
Thank you in advance.

 

 

Share this post


Link to post
Share on other sites
2 hours ago, pete2007 said:
We have this discount code setup, everything is working as it should.
 
But I have recently noticed a problem, we have a valid discount code setup to use as a one-time use only but we have found out that customers who pay using PayPal Pro (card payments) can use the code over and over again.
 
Please can someone help us fix this problem?
 
Thank you in advance.

Hello @pete2007,

The PayPal Pro module pypasses the standard checkout_process.php similar to the paypal standard module. It requires therefor a similar modification like that module to include the database update of the use of the discount coupon.

This is not yet implemented. I'll include it in the next update and let you know when if it is available. It would be great if you could do some beta testing because I do not use the PayPal Pro module myself. Let me know and I'll post the update here before releasing.

Best regards
Rainer

Share this post


Link to post
Share on other sites
On 1/18/2020 at 10:35 PM, spacegremlin said:

hi can someone tell me wich version i can download, or a link for the discount module

i have version osCommerce Online Merchant v2.3.4.1

 

thank you

This thread and App is only for the Phoenix and previous BS versions.

You can find the old Discount code for standard 2.2 and 2.3 Oscommerce vesions here:

Discount Codes for osC v2.3

Discount Code

Be aware that you probably will not get support any more for these versions.

Share this post


Link to post
Share on other sites

Sorry, you didn't mention BS:

Quote

i have version osCommerce Online Merchant v2.3.4.1

If you have BS then this is the right version:

Discount Codes BS

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×