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?
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?
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?
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?
The problem is the countProducts() call doesn't check if the product requires shipping or not.
countProducts() function
If you wanted to exclude downloads, in the file catalog/model/shipping/item.php
Add
After
Then replace
With
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;
}
Add
Code: Select all
$shipping_quantity = 0;
foreach ($this->cart->getProducts() as $product) {
if ($product['shipping']) {
$shipping_quantity += $product['quantity'];
}
}
Code: Select all
if ($status) {
Code: Select all
'cost' => $this->config->get('item_cost') * $this->cart->countProducts(),
Code: Select all
'cost' => $this->config->get('item_cost') * $shipping_quantity,
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:
Or just use my Item-Based Shipping extension, which counts them correctly. 
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,

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.
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.
Who is online
Users browsing this forum: No registered users and 113 guests