Jump to content
Latest News: (loading..)

Recommended Posts

this is how it works, once applied the discount code it's stored in the order and will not be cleared.

 

If the user leaves the field blank and presses the button Apply, and then he wants to remove the discount.

Discount must be erased.

This is logical.

Edited by spidometrs

No outside url's in signatures allowed - thanks

Share this post


Link to post
Share on other sites

@@spidometrs, yes, but the add-on exists and works like this since years. I didn't create it, me and Tsimi just updated an existing version.
But, I understand your point of view. We will see if we can update it with this feature.
 
 
@@Tsimi shall we give this a try??
 
 
rgds
Rainer

Edited by raiwa

Share this post


Link to post
Share on other sites

I don't see why someone would insert a discount code and then would want to remove it again before going into the checkout process. Makes no sense to me.

 

We would do this because we test things but a regular customer wouldn't do that I think.

Share this post


Link to post
Share on other sites

I don't see why someone would insert a discount code and then would want to remove it again before going into the checkout process. Makes no sense to me.

 

We would do this because we test things but a regular customer wouldn't do that I think.

 

 

I would agree...I can see adding a different coupon code but removing it completely is not apt to happen.

 

Dan

Share this post


Link to post
Share on other sites

@@spidometrs, meanwhile, the discount can be removed entering a wrong code and apply again.

 

How to to explain it to the customer?

There are general rules on the Internet: if the field is empty - everything has to be removed.

This is not true?

 

I do not insist.

I'm just saying my opinion.


No outside url's in signatures allowed - thanks

Share this post


Link to post
Share on other sites

All,

I found a strange bug. The discount code I setup was a free shipping discount. The site has the

flate rate shipping module installed. It also has the free shipping turnned on at the order total

level within the admin -> Modules -> Order Totals -> Shipping and that is set to $130.00.

 

We had the 3.8 version of discount codes installed. I just upgraded to the latest 4.1 version

after discovering this issue. However, the upgrade did not resolve the issue as I had hoped.

 

The use case: For all test cases: Created a free shipping discount code called 1234.

Test 1 - The shopping cart has an item that is less than the flat rate shipping fee and there is

sales tax being applied and no discount code being applied (attachement: Discount not applied.jpg).

This works as expected.

 

Test 2 - The shopping cart has an item that is less than the flat rate shipping fee and a sales

tax (same product and etc. from test case 1) however, this time the free shipping discount was

entered during the check out process (attachement: Discount applied.jpg). Note: the caculation,

the sale tax is missing, the discount was applied to the product price and the total is the

difference between the flat rate shipping cost and product price.

 

Test 3 - Removed the product in the shopping cart from test case 1 & 2 and replaced it for a

higher price product that exceeded the flat rate shipping amount. The 1234 Free Shipping discount

code was applied and everything worked as expected. (attachement: Discount Correct.jpg)

 

Items I have tried:

- upgrade from 3.8 to 4.1 versions

- multiple free shipping discount codes

- attempt to turn-off order total discount within Modules -> Order Totals -> Shipping

- several test with products that were under the flat rate shipping with a free shipping

discount code(s).

 

Looking for suggestion on how to trace this issue out or if someone has or knows of the solution

to resolve it. BTW: We are running BS version of OSC.

 

Thanks in advance for your help

post-336713-0-46067800-1479869248_thumb.jpg

post-336713-0-50419200-1479869632_thumb.jpg

post-336713-0-02512700-1479870430_thumb.jpg

Share this post


Link to post
Share on other sites

@@nbkvh1i

 

Hi Ed

 

can you please try the following.

 

open your .../includes/modules/order_total/ot_discount.php file and look for this code around line 162-164

                    if ($discount > $order->info['subtotal']) {
                      $discount = $order->info['subtotal'];
                    }

...and replace that with this

                    if ($discount > $order->info['shipping_cost']) {
                      $discount = $order->info['shipping_cost'];
                    }
Edited by Tsimi

Share this post


Link to post
Share on other sites

@@Tsimi

 

I don't have those lines in my .../includes/modules/order_total/ot_discount.php file. I did install the latest from 4.1.

 

------------------------------------

 

Here is the entire $check['shipping'] section of my file (lines 79-199)

if (!empty($check['products_id']) || !empty($check['categories_id']) || !empty($check['manufacturers_id'])) {

 

$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'];

}

}

 

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 = $this->format_raw(($products_discount * ($order->products[$i]['tax'] / 100)));

$order->info['total'] -= $tax_correction;

} else {

$tax_correction = $this->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;

}

}

 

$order->info['total'] -= $discount;

 

} 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 = 0;

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 = $this->format_raw($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 (!empty($order_tax)) {

$order->info['tax'] = $order_tax;

} else {

$order->info['total'] -= $discount;

}

}

$shipping_discount = 'false';

} elseif (!empty($check['shipping'])) { //.eof $check['orders_total']

if ($check['shipping'] == 2) {

$discount = $order->info['shipping_cost'] * str_replace('%', '', strtolower($check['discount_values'])) / 100;

if ($discount > $order->info['subtotal']) {

$discount = $order->info['subtotal'];

}

$order_tax = 0;

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 = $this->format_raw($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 (!empty($order_tax)) {

$order->info['tax'] = $order_tax;

} else {

$order->info['total'] -= $discount;

}

$shipping_discount = 'true';

}

} //.eof $check['shipping']

Share this post


Link to post
Share on other sites

@@Tsimi

 

Sorry, Notepad++ search did a poor job of finding the string. I actually end up finding it in two different places within

the file. One at line 173 and another at 143. The one at line 173 seems to be within the shipping check. I will modify that

to the above and test.

 

Sorry again for missing it the first time.

Share this post


Link to post
Share on other sites

@@Tsimi
I did run the test 2 use case above after making the suggested change. It appears to be deducting the shipping cost
correctly now. However, the sales tax amount (around $0.50 for the test case) is missing, and the total is still deducting
an amount (I am assuming it is some percentage of the tax because of the amount but not the full amount). See the attached
image (Discount Code - Something Still Off.jpg) The Total should be 7.45 but the total in the use case is 6.58 (which is  $0.37 difference that does not match the tax amount). post-336713-0-75529300-1479942350_thumb.jpg

Share this post


Link to post
Share on other sites

@@nbkvh1i

 

So I installed a fresh copy of the Discount Codes BS 4.1 addon and applied the fix that I suggested above. You were right by the way it was around line 172-174 and not 162-163, my bad, sorry.

Here are the results that I got.

 

Normal without discount

 

post-27491-0-10395400-1479971812_thumb.jpg

 

With discount applied

 

post-27491-0-88360200-1479971846_thumb.jpg

 

With discount applied and product with higher price value than shipping

 

post-27491-0-52898300-1479972129_thumb.jpg

 

 

How does your tax setup look like? Tax Zones? Tax Classes? Tax Rates?

Did you add a tax class to the flat rate shipping?

Worst case try to uninstall your current Discount Codes addon and reinstall it directly from 4.1 without going through any upgrade.

 

Share this post


Link to post
Share on other sites

@@Tsimi

I did get the Sales Tax to show up by resetting the sort order in the admin -> Modules -> Order Total. Set the tax to be displayed just after subtotal prior to shipping and discounted values. Also moved the discount to be just above the total. So, now the tax amount is being displayed, but the total is still incorrect. 
 

How does your tax setup look like? Tax Zones? Tax Classes? Tax Rates?

   - For this test case, I only have one Tax Zone (North Carolina - NC Sales Tax) configured, one tax class (Taxable Goods), and

     one rate assigned to the zone and class. Only products are assigned a tax class.

  - I did change the address for the test customer to a non-zone defined address and it worked correctly. Let me know if think

     there is still something misconfigured on the tax set up

 

Did you add a tax class to the flat rate shipping?

   - No, it is not assigned to a tax class or zone.

 

Do you have "display prices with tax" set to true or false?

   - It is set to false for the product displays. Only in the check out is set to display tax. The sort order seemed to fix the display issue.

Edited by nbkvh1i

Share this post


Link to post
Share on other sites

@@nbkvh1i, @@Tsimi,

 

I gave it a try with different settings for tax and include tax to the shipping module.

The shipping discount part needed a overhaule for to get all correct calculated for all possible combinations.

It should work now even keeping the sort order like by default (discount = 2, tax = 3).

 

Please give it a try.

 

 

rgds

Rainer

Share this post


Link to post
Share on other sites

Just checked with the original version, changing sort order to discount = 3 and the first fix tsimi suggested (the fix is correct , but there are more changes needed):

                    if ($discount > $order->info['shipping_cost']) {
                      $discount = $order->info['shipping_cost'];
                    }

It solves calculations in some cases, but for example with no tax class for shipping and display prices with tax set to "false" I get wrong order total.

 

Although showing the discount module below the shipping if shipping discounts are used, looks more logic to me. I'll check my modified version now with this sort order.

Edited by raiwa

Share this post


Link to post
Share on other sites

All, Just had a thought, might want to consider working the sort/display order affecting the calculation. I could foresee someone needing to add on another module or add-on and the two could break each other.

Share this post


Link to post
Share on other sites

@@Tsimi, @@nbkvh1i,

 

This version should do it for both sort orders and all settings:

ot_discount.php

 

I tested as much as I could, but it would be good if you could do all possible hardcore test too.

 

I checked all the following with all combinations:

 

- sort order:

discount 2 shipping 3

shipping 2 discount 3

 

- display prices with tax:

true and false

 

- shipping module:

tax assigned and no tax assigned

 

- shipping discount:

50% and 100%

 

some test with normal order subtotal discount and sort order shipping 2 discount 3.

 

 

All seems to be good

 

rgds

Rainer

Share this post


Link to post
Share on other sites

@@raiwa

 

Just did a couple test runs and all looks good here.

What do you want to do with the version number inside the OT module?

$this->version = '4.1 BS';

change it to 4.2?

Share this post


Link to post
Share on other sites

@@raiwa

 

Just did a couple test runs and all looks good here.

What do you want to do with the version number inside the OT module?

$this->version = '4.1 BS';

change it to 4.2?

 

Yes, and the new alternative sort order added to the instructions.

Then it can be uploaded I guess.

 

rgds

Rainer

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

×