Author Topic: [SOLVED] Problem calculating % of costs with COD (cash on delivery)  (Read 5133 times)

goretex34

  • Beginner
  • *
  • Posts: 37
    • Zeesl web design · diseño web Zeesl
I needed to calculate the total cost of COD (Cash On Delivery) (3% in my case)
of the Big Total (including Transport & VAT & Fees).

For example, an order of 129€ + 7€ (shipping) = 136€ (VAT included) we should have to add 4,08€, so the total will be 140,08€ .
(that's 3% of the total to pay)
Before my hack, it calculated 3,28€ (3% of 109,32 € (129€ without VAT 18%))


I've tried lots of things (LOTS and LOTS and LOTS), and finally I did:

ps_checkout.php (around line 1780):
original code:
Code: [Select]
if( $subtotal === '') {
$subtotal = $this->get_order_subtotal( $vars );  
}
new code:
Code: [Select]
if( $subtotal === '') {
$subtotal = $this->get_order_total( $vars ) + $this->get_rate( $vars );
}
else{
$subtotal = $this->get_order_total( $vars );
if ($vendor_freeshipping > 0){
$subtotal += $this->get_rate( $vars );
}
}


Added a new function in ps_checkout.php (I put it just before get_payment_discount() function):
Code: [Select]
/**************************************************************************
** name: get_rate()
** created by: goretex34@hotmail.com
** description:  Get the Shipping Rate from the string shipping_rate_id
** a string like "standard_shipping%7CPostf%C3%B6rskott%7CPostf%C3%B6rskott+max+0.250+kg%7C75.00%7C100"
** a string like "standard_shipping%7CNACEX%7CEspa%C3%B1a+y+Portugal%7C7.00%7C1", where we have to extract "7.00" (4th param)
** parameters: array
** returns: Shipping Rate
***************************************************************************/
  function get_rate( &$d ) {
      
 $shipping_rate_id = vmGet($_REQUEST,"shipping_rate_id");
 $zone_arr = explode("|", urldecode(urldecode($shipping_rate_id)) );
 $order_shipping = $zone_arr[3];
 
 return $order_shipping;
  }



In both ro_basket.php and basket.php I added one line to define $vars as a global variable:

original code:
Code: [Select]
mm_showMyFileName( __FILE__ );

require_once(CLASSPATH. 'ps_product.php' );

modified code:
Code: [Select]
mm_showMyFileName( __FILE__ );
global $vars;

require_once(CLASSPATH. 'ps_product.php' );

 ;D  :)  :D  :D  :D  ;D

After 4 days working hard I've found my solution, and I wanted to post i here hoping it helps somebody.

CHEERS!
------------------------------------
www.Zeesl.com  @Zeesl
www.chartconsulting.net @chartcon
@goretex34

guida125

  • Beginner
  • *
  • Posts: 11
Re: [SOLVED] Problem calculating % of costs with COD (cash on delivery)
« Reply #1 on: April 22, 2011, 20:55:36 pm »
Hey goretex,

Great work and thanks for charing! Do yuo think this solutions helps me?

The transport taxs in my vm1.1.8 simply dont display! i have different taxes set, but all display 0 (free of charge)

I can´t find solutions in this forum!

Regards!
Guida

erikanet

  • Beginner
  • *
  • Posts: 1
first of all thanks for the code goretex34! It was very usefull!
I made a little change to your code to display the correct % also on the Checkout (my virtuemart 1.1.5 only displays the correct % in "please select a Payment Method")
Here it is!

Original code (in ro_basket.php file around the 166th line):
Code: [Select]
$payment_discount = $ps_checkout->get_payment_discount($payment_method_id, $total);
New code:
Code: [Select]
$payment_discount = $ps_checkout->get_payment_discount($payment_method_id, '');

schilpfire

  • Beginner
  • *
  • Posts: 2
I just set it up in the shippingmodule Shipvalue.

In the backend, you can set uo the standard shipping costs, and the percentage of the total value. For me, it works fine.

When people select 'Rembours', the amount that will be charged is the total of the order + €15,00 + 1% of the total. So with an order of €100,- (incl VAT 19%), the shipping rate will be charged as 100+15+1= €116,-

REMARK: Set up the base shipping cost without VAT. So in my case, the value is 15/1.19=12.6050. In your case of 18%VAT, 7/1.18=5.9322