Post by logicalinsanity » Sat Jul 24, 2010 4:25 am

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.


Posts

Joined
Sat Jul 24, 2010 3:22 am

Post by JAY6390 » Sat Jul 24, 2010 4:36 am

Nice modification. Have you considered turning it into a proper shipping module?

Image


User avatar
Guru Member

Posts

Joined
Wed May 26, 2010 11:47 pm
Location - United Kingdom

Post by logicalinsanity » Sat Jul 24, 2010 5:21 am

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.


Posts

Joined
Sat Jul 24, 2010 3:22 am

Post by JAY6390 » Sat Jul 24, 2010 5:23 am

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

Image


User avatar
Guru Member

Posts

Joined
Wed May 26, 2010 11:47 pm
Location - United Kingdom
Who is online

Users browsing this forum: No registered users and 3 guests