Page 1 of 1

MOD: Flat Shipping plus $x.xx per additional item

Posted: Sat Jul 24, 2010 4:25 am
by logicalinsanity
My apologies if someone already posted something like this, but I wanted to share a modification I made that allows you to charge a flat shipping rate for the first item and then $x.xx extra for each additional item. This is a modified version of my $1 shipping per additional item post, which dealt with specifically adding $1 per extra item. This solution allows you to specify something other than $1 for subsequent items:

1. Ensure Flat Rate Shipping is Enabled in 'Extensions > Shipping > Flat Rate' and you have the desired rate entered for shipping one item.

2. Next, open 'catalog > model > shipping > flat.php'

FIND:

Code: Select all

$quote_data = array();
 
REPLACE WITH:
(Change 2.00 to whatever amount you want to charge for each additional item shipped)

Code: Select all

$quote_data = array();

if($this->cart->countProducts() > 1)
{
    $custom_count = 2.00 *  ($this->cart->countProducts() - 1);
}
else
{
    $custom_count = 0;
}

 
FIND:

Code: Select all

'cost'         => $this->config->get('flat_cost'),
 
REPLACE WITH:

Code: Select all

'cost'         => $this->config->get('flat_cost') + $custom_count,
 
FIND:

Code: Select all

'text'         => $this->currency->format($this->tax->calculate($this->config->get('flat_cost'), $this->config->get('flat_tax_class_id'), $this->config->get('config_tax')))
 
REPLACE WITH:

Code: Select all

'text'         => $this->currency->format($this->tax->calculate($this->config->get('flat_cost') + $custom_count, $this->config->get('flat_tax_class_id'), $this->config->get('config_tax')))
 
What this does:

It will take your flat shipping rate and add a flat 2.00 dollar amount for each additional item in the cart. You can enter your own amount by changing 2.00 in the code above to whatever you want. Just make sure the value does not contain a dollar sign or any other symbol aside from the decimal. As always, be sure to make a backup of files before modifying them.

Re: MOD: Flat Shipping plus $x.xx per additional item

Posted: Sat Jul 24, 2010 4:36 am
by JAY6390
Nice modification. Have you considered turning it into a proper shipping module?

Re: MOD: Flat Shipping plus $x.xx per additional item

Posted: Sat Jul 24, 2010 5:21 am
by logicalinsanity
Thanks! Yesterday was my first time ever using OpenCart, so I haven't even looked into the custom module options yet. I'm doing this for a friend who needed an online shopping cart and haven't really delved into the full customization capabilities of the software.

Re: MOD: Flat Shipping plus $x.xx per additional item

Posted: Sat Jul 24, 2010 5:23 am
by JAY6390
Ah OK I see. I might make a free one that will do the same. Not made a shipping module yet so would be good practise