Page 1 of 1

[How To] Sum of net prices and the net cost of Shipping

Posted: Wed Oct 31, 2012 11:59 pm
by zaja
Does anyone know how to configure sub total in cart/checkout in this way, I need the sum of net price of items and the net cost of shipping?

This is how Opencart now display this info now:

Image

But I need it displayed this way:

Image

Re: [How To] Sum of net prices and the net cost of Shipping

Posted: Thu Nov 01, 2012 12:11 am
by JAY6390
Place your shipping above the subtotal. Go to your EXTENSIONS > TOTALS in the admin and change the sort order of "Shipping" and "Subtotal" so the Shipping has a lower sort order value than the Subtotal

Re: [How To] Sum of net prices and the net cost of Shipping

Posted: Thu Nov 01, 2012 1:21 am
by zaja
JAY6390 wrote:Place your shipping above the subtotal. Go to your EXTENSIONS > TOTALS in the admin and change the sort order of "Shipping" and "Subtotal" so the Shipping has a lower sort order value than the Subtotal
Thanks, just tryed but this not work, Shipping ex VAT is still not added to Subtotal ex VAT:

Image

Re: [How To] Sum of net prices and the net cost of Shipping

Posted: Thu Nov 01, 2012 1:28 am
by JAY6390
OK, this is more of a hack than a proper solution, but will make the subtotal correct

Open

Code: Select all

/catalog/model/total/shipping.php
Find this line

Code: Select all

$total += $this->session->data['shipping_method']['cost'];
change it to

Code: Select all

// $total += $this->session->data['shipping_method']['cost'];  
Save that, then open

Code: Select all

/catalog/model/total/subtotal.php
Find this line

Code: Select all

$sub_total = $this->cart->getSubTotal();
After it on a new line put

Code: Select all

$subtotal += $this->session->data['shipping_method']['cost'];
And save. This is totally untested but should work in theory

Re: [How To] Sum of net prices and the net cost of Shipping

Posted: Thu Nov 01, 2012 3:04 am
by zaja
Great, it works! :)

Line to add in /catalog/model/total/subtotal.php must be:

Code: Select all

$sub_total += $this->session->data['shipping_method']['cost'];
Thank you! :good:

Re: [How To] Sum of net prices and the net cost of Shipping

Posted: Thu Nov 01, 2012 3:06 am
by JAY6390
Sorry yes that's correct :)

Re: [How To] Sum of net prices and the net cost of Shipping

Posted: Thu Nov 01, 2012 3:32 am
by zaja
I just noticed that this modification produces error on the top of the page:

Code: Select all

Notice: Undefined index: shipping_method in C:\xampp\htdocs\open154\catalog\model\subtotal.php on line 7 
Screenshot: http://screencast.com/t/uARZXc2a
This is how subtotal.php look:

Code: Select all

<?php
class ModelTotalSubTotal extends Model {
	public function getTotal(&$total_data, &$total, &$taxes) {
		$this->load->language('total/sub_total');
		
		$sub_total = $this->cart->getSubTotal();
		$sub_total += $this->session->data['shipping_method']['cost'];
		
		if (isset($this->session->data['vouchers']) && $this->session->data['vouchers']) {
			foreach ($this->session->data['vouchers'] as $voucher) {
				$sub_total += $voucher['amount'];
			}
		}
		
		$total_data[] = array( 
			'code'       => 'sub_total',
			'title'      => $this->language->get('text_sub_total'),
			'text'       => $this->currency->format($sub_total),
			'value'      => $sub_total,
			'sort_order' => $this->config->get('sub_total_sort_order')
		);
		
		$total += $sub_total;
	}
}
?>
Do you have any idea why this happening?

Re: [How To] Sum of net prices and the net cost of Shipping

Posted: Sat Nov 03, 2012 5:24 am
by zaja
Ok, this work for sub_total.php:

After:

Code: Select all

$sub_total = $this->cart->getSubTotal();
add:

Code: Select all

if ($this->cart->hasShipping() && isset($this->session->data['shipping_method'])) {
			$sub_total += $this->session->data['shipping_method']['cost'];
			}