Jump to content

[SOLVED] BIG BIG PROBLEM with voucher partial use - remaining voucher value is wrong


vicbg

Recommended Posts

PROBLEM SEEN ON PrestaShop 1.6.0.11

 

Hello everyone.

There is something really wrong here that I wish to fix asap cause it could be loosing me (possible you as well) lots of money.
The case is this:

Voucher for EUR 200 is created., with partial use enabled

Customer fills cart with EUR 120.

After checkout, for which the customer pays EUR 0, logically, PS creates a new voucher.

Here is the catch. The new voucher should be of value EUR 80.
HOWEVER, PS creates the new voucher with value EUR 120 = exactly the amount of the order.

There is something completely reversed here and I would really appreciate if people have ideas what could be wrong.


P.S. for extra clarity, I give you a possible scenario of the problem:
Voucher code THOUSANDOFF for USD 1000, partial use ON

1st Order = $999

- new voucer THOUSANDOFF2 is created automatically for USD 999

2nd Order = $998

- new voucer blah bla for USD 998

 

3d order = $997 etc etc etc ... it would be the scam of the century.

 

Edited by vicbg (see edit history)
Link to comment
Share on other sites

Absolutely correct.

 

Inspection of 1.6.0.11 code in classes/PaymentModule.php shows that the calculation of the value of the new voucher is incorrect:

// Set the new voucher value                      
if ($voucher->reduction_tax)                      
{                                                 
    $voucher->reduction_amount = $order->total_products_wt - $total_reduction_value_ti;

It's setting the amount of the new voucher using the total value of the order!

 

Compare this with code from 1.6.1.6 where the partial reduction works correctly:

// Set the new voucher value                      
if ($voucher->reduction_tax) {                    
    $voucher->reduction_amount = ($total_reduction_value_ti + $values['tax_incl']) - $order->total_products_wt;

Here it's using the value of the current voucher and subtracting the order total.

 

If you want to patch your own system open classes/PaymentModule.php and find line 536. Replace the red lines with blue lines:

 

// Set the new voucher value                                                  
if ($voucher->reduction_tax)                                                  
{                                                                             
    $voucher->reduction_amount = $order->total_products_wt - $total_reduction_value_ti;
   
$voucher->reduction_amount = ($total_reduction_value_ti + $values['tax_incl']) - $order->total_products_wt;
                                                                              
    // Add total shipping amout only if reduction amount > total shipping     
    if ($voucher->free_shipping == 1 && $voucher->reduction_amount >= $order->total_shipping_tax_incl)
        $voucher->reduction_amount -= $order->total_shipping_tax_incl;        
}                                                                             
else                                                                          
{                                                                             
    $voucher->reduction_amount = $order->total_products - $total_reduction_value_tex;
    $voucher->reduction_amount = ($total_reduction_value_tex + $values['tax_excl']) - $order->total_products;

Edited by JeredBolton (see edit history)
  • Like 1
Link to comment
Share on other sites

Absolutely correct.

 

Inspection of 1.6.0.11 code in classes/PaymentModule.php shows that the calculation of the value of the new voucher is incorrect:

// Set the new voucher value                      
if ($voucher->reduction_tax)                      
{                                                 
    $voucher->reduction_amount = $order->total_products_wt - $total_reduction_value_ti;

It's setting the amount of the new voucher using the total value of the order!

 

Compare this with code from 1.6.1.6 where the partial reduction works correctly:

// Set the new voucher value                      
if ($voucher->reduction_tax) {                    
    $voucher->reduction_amount = ($total_reduction_value_ti + $values['tax_incl']) - $order->total_products_wt;

Here it's using the value of the current voucher and subtracting the order total.

 

If you want to patch your own system open classes/PaymentModule.php and find line 536. Replace the red lines with blue lines:

 

// Set the new voucher value                                                  

if ($voucher->reduction_tax)                                                  

{                                                                             

    $voucher->reduction_amount = $order->total_products_wt - $total_reduction_value_ti;

    $voucher->reduction_amount = ($total_reduction_value_ti + $values['tax_incl']) - $order->total_products_wt;

                                                                              

    // Add total shipping amout only if reduction amount > total shipping     

    if ($voucher->free_shipping == 1 && $voucher->reduction_amount >= $order->total_shipping_tax_incl)

        $voucher->reduction_amount -= $order->total_shipping_tax_incl;        

}                                                                             

else                                                                          

{                                                                             

    $voucher->reduction_amount = $order->total_products - $total_reduction_value_tex;

    $voucher->reduction_amount = ($total_reduction_value_tex + $values['tax_excl']) - $order->total_products;

Thank you very much, Jered Bolton, for taking the time to check this.

I am going to make the changes straight away and will run tests to report back to you.

Cheers!

Edited by vicbg (see edit history)
Link to comment
Share on other sites

Absolutely correct.

 

Inspection of 1.6.0.11 code in classes/PaymentModule.php shows that the calculation of the value of the new voucher is incorrect:

// Set the new voucher value                      
if ($voucher->reduction_tax)                      
{                                                 
    $voucher->reduction_amount = $order->total_products_wt - $total_reduction_value_ti;

It's setting the amount of the new voucher using the total value of the order!

 

Compare this with code from 1.6.1.6 where the partial reduction works correctly:

// Set the new voucher value                      
if ($voucher->reduction_tax) {                    
    $voucher->reduction_amount = ($total_reduction_value_ti + $values['tax_incl']) - $order->total_products_wt;

Here it's using the value of the current voucher and subtracting the order total.

 

If you want to patch your own system open classes/PaymentModule.php and find line 536. Replace the red lines with blue lines:

 

// Set the new voucher value                                                  

if ($voucher->reduction_tax)                                                  

{                                                                             

    $voucher->reduction_amount = $order->total_products_wt - $total_reduction_value_ti;

    $voucher->reduction_amount = ($total_reduction_value_ti + $values['tax_incl']) - $order->total_products_wt;

                                                                              

    // Add total shipping amout only if reduction amount > total shipping     

    if ($voucher->free_shipping == 1 && $voucher->reduction_amount >= $order->total_shipping_tax_incl)

        $voucher->reduction_amount -= $order->total_shipping_tax_incl;        

}                                                                             

else                                                                          

{                                                                             

    $voucher->reduction_amount = $order->total_products - $total_reduction_value_tex;

    $voucher->reduction_amount = ($total_reduction_value_tex + $values['tax_excl']) - $order->total_products;

The medicine you gave mate works like a charm (and like it should do as a matter of fact)>

Thumbs up and thank you for your perfect solution.

 

This can now be marked as SOLVED with the kind help of Mr. Jared Bolton :)))  :)

Link to comment
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
×
×
  • Create New...