Post by upl8t » Wed Aug 15, 2012 5:18 am

I have both digital and shipped products on a recent opencart based site.

Shipped products are correctly charging shipping.

Digital download products, when they are the only thing in the cart, are correctly not charging shipping.

When a cart has BOTH shipped products and digital downloads in the same order the cart is incorrectly adding shipping to all products including the digital download products.

Does anyone know what's causing this and how to solve it?

New member

Posts

Joined
Fri Aug 03, 2012 7:36 pm

Post by Johnathan » Wed Aug 15, 2012 9:19 pm

Sounds like your shipping method is not calculating correctly. What shipping method are you using? It has to be smart enough to take into account only products that require shipping.

Image Image Image Image Image


User avatar
Administrator

Posts

Joined
Fri Dec 18, 2009 3:08 am


Post by upl8t » Wed Aug 15, 2012 9:26 pm

Hi Johnathan... It's the standard Per Item shipping module.

New member

Posts

Joined
Fri Aug 03, 2012 7:36 pm

Post by upl8t » Fri Aug 17, 2012 12:45 am

I've done some searching and it appears the shipping total is calculated using the total product count times the per unit shipping amount.

Can anyone comfirm that shipping is calculated from $this->cart->countProducts()

If this is the case it means the core cart module is missing the method to count the number of shipping products only... and accordingly is then incorrectly charging shipping on digital products when they're in an order that contains both digital and shipped products.

Any idea how to get the count of non-digital products only?

New member

Posts

Joined
Fri Aug 03, 2012 7:36 pm

Post by OpenCart Addons » Fri Aug 17, 2012 2:30 am

The problem is the countProducts() call doesn't check if the product requires shipping or not.

countProducts() function

Code: Select all

public function countProducts() {
		$product_total = 0;
			
		$products = $this->getProducts();
			
		foreach ($products as $product) {
			$product_total += $product['quantity'];
		}		
					
		return $product_total;
	}
If you wanted to exclude downloads, in the file catalog/model/shipping/item.php

Add

Code: Select all

$shipping_quantity = 0;
foreach ($this->cart->getProducts() as $product) {
if ($product['shipping']) {
$shipping_quantity += $product['quantity'];
}
}
After

Code: Select all

if ($status) {
Then replace

Code: Select all

'cost'         => $this->config->get('item_cost') * $this->cart->countProducts(),
With

Code: Select all

'cost'         => $this->config->get('item_cost') * $shipping_quantity,

Canada's Leading Expert In OpenCart Development & Certified OpenCart Development Partner Image


User avatar
Active Member

Posts

Joined
Thu Nov 24, 2011 10:51 am
Location - Canada

Post by upl8t » Fri Aug 17, 2012 6:07 am

Thanks for a such a detailed writeup! I'm going to put this in tonight. I'll let you know how it works out.

New member

Posts

Joined
Fri Aug 03, 2012 7:36 pm

Post by upl8t » Fri Aug 17, 2012 10:44 pm

Thanks OpenCart Addons

Works perfectly. The only thing that's now wrong is the value on the estimate shipping popup. I need to find where that is and make the same change so it's calculating from $shipping_quantity

New member

Posts

Joined
Fri Aug 03, 2012 7:36 pm

Post by Johnathan » Sat Aug 18, 2012 12:55 am

This really should be fixed in the shipping file, and not the system file, since the system's countProducts() function could be used elsewhere (and would result in a wrong count for non-shipping code). Try this instead:

Code: Select all

IN:
/catalog/model/shipping/item.php

REPLACE:
$quote_data['item'] = array(
    'code'         => 'item.item',
    'title'        => $this->language->get('text_description'),
    'cost'         => $this->config->get('item_cost') * $this->cart->countProducts(),

WITH:
$number_of_items = 0;
foreach ($this->cart->getProducts() as $product) {
    if ($product['shipping']) $number_of_items += $product['quantity'];
}
$quote_data['item'] = array(
    'code'         => 'item.item',
    'title'        => $this->language->get('text_description'),
    'cost'         => $this->config->get('item_cost') * $number_of_items,
Or just use my Item-Based Shipping extension, which counts them correctly. ;D

Image Image Image Image Image


User avatar
Administrator

Posts

Joined
Fri Dec 18, 2009 3:08 am


Post by OpenCart Addons » Sat Aug 18, 2012 2:57 am

The modification I suggested was mentioned to be applied to the actual shipping file and not the system file.

I would advise against changing the system files if it can be avoided as you will end up getting unwanted results elsewhere on your site.


Cheers,
Joel.

Canada's Leading Expert In OpenCart Development & Certified OpenCart Development Partner Image


User avatar
Active Member

Posts

Joined
Thu Nov 24, 2011 10:51 am
Location - Canada

Post by Johnathan » Sat Aug 18, 2012 5:40 am

My mistake, I missed the second part of your post. Joel's second modification will work as well.

Image Image Image Image Image


User avatar
Administrator

Posts

Joined
Fri Dec 18, 2009 3:08 am

Who is online

Users browsing this forum: No registered users and 20 guests