Page 1 of 1

Percentage based shipping

Posted: Sat Jun 20, 2009 7:29 am
by mchaggis
Alright, I have some programming experience but virtually none with PHP, other than what I've picked up playing with opencart. I want to change my flat rate shipping module into a percentage based module with a minimum. This doesnt seem like it should be too terribly hard to accomplish. From what I can see poking around flat.php, it gets the cost here:

Code: Select all

'cost'         => $this->config->get('flat_cost'),
so I'm thinking change it to something like

Code: Select all

'cost'         => $with_percent,
and define the $with_percent variable something like this

Code: Select all

if ( $sub_total <= 70 ) {
	$with_percent = 10
} else {
	$with_percent = $sub_total * .15
}
so that if the order is under 70 bucks, it charges ten dollars shipping, if it's above, it charges 15%.
problems:
- i'm sure this syntax is nothing close to right
- not entirely sure how to access $sub_total
Any help turning this thought-dump into usable code would be much appreciated.

Re: Percentage based shipping

Posted: Sat Jun 20, 2009 8:05 am
by Qphoria
mchaggis wrote:

Code: Select all

if ( $sub_total <= 70 ) {
	$with_percent = 10
} else {
	$with_percent = $sub_total * .15
}
You're pretty close.

Try:

Code: Select all

$sub_total = $this->cart->getSubtotal();
if ( $sub_total <= 70 ) {
	$with_percent = 10;
} else {
	$with_percent = $sub_total * .15;
}

Re: Percentage based shipping

Posted: Sat Jun 20, 2009 10:20 am
by Qphoria
You also might be interested in my zone shipping plus module that supports subtotal, weight, and itemcount calculations. And static amounts as well as percentages for the cost.
http://forum.opencart.com/viewtopic.php?f=13&t=4502