Post by arthur » Sat Nov 11, 2017 2:43 am

Hello. I'd like to show Free shipping message in checkout/cart.tpl just under the main table. Postage is not included. Please see my code example below. I need to get $total somehow.

Code: Select all

<?php 
//$total = 120;
$sum = (100-$total);	  
if ($total >= 100) {
echo "Your are eligable for FREE SHIPPING"; }
else { 
echo  "To be eligable for free shipping you need to buy for ".$sum." more"; 
}	  
?>
OpenCart v2.3.0.2

New member

Posts

Joined
Wed Oct 25, 2017 2:14 am

Post by DigitCart » Sat Nov 11, 2017 12:42 pm

Hi,
try this:

Code: Select all

$this->cart->getTotal();
//or
$this->cart->getSubTotal();

My Extensions / DigitCart


User avatar
Active Member
Online

Posts

Joined
Thu Jun 22, 2017 5:32 pm


Post by arthur » Sat Nov 11, 2017 4:03 pm

DigitCart wrote:
Sat Nov 11, 2017 12:42 pm
Hi,
try this:

Code: Select all

$this->cart->getTotal();
//or
$this->cart->getSubTotal();
These show me the following errors:
Notice: Undefined property: Template\PHP::$cart in ... template\checkout\cart.tpl on line 107
Fatal error: Call to a member function getSubTotal() on null in ... template\checkout\cart.tpl on line 107


Probably it's not enough to modify the .tpl file only.

New member

Posts

Joined
Wed Oct 25, 2017 2:14 am

Post by DigitCart » Sat Nov 11, 2017 4:16 pm

Yes,
You must use them in controller.
controller:

Code: Select all

$data['cart_total'] = $this->cart->getTotal();
view:

Code: Select all

<?php echo $cart_total; ?>

My Extensions / DigitCart


User avatar
Active Member
Online

Posts

Joined
Thu Jun 22, 2017 5:32 pm


Post by arthur » Sat Nov 11, 2017 4:36 pm

DigitCart wrote:
Sat Nov 11, 2017 4:16 pm
Yes,
You must use them in controller.
controller:

Code: Select all

$data['cart_total'] = $this->cart->getTotal();
view:

Code: Select all

<?php echo $cart_total; ?>
It works ;D Thank you once again.

New member

Posts

Joined
Wed Oct 25, 2017 2:14 am

Post by DigitCart » Sat Nov 11, 2017 5:12 pm

You're welcome.

My Extensions / DigitCart


User avatar
Active Member
Online

Posts

Joined
Thu Jun 22, 2017 5:32 pm


Post by mupcku » Mon Aug 20, 2018 7:39 pm

Do you have any idea why i still cant get my cart total on tpl page? Im using 2.1.0.1

https://wedeom.bg
Image


Active Member

Posts

Joined
Tue Jan 24, 2017 8:12 pm

Post by nightwing » Wed Sep 30, 2020 10:16 pm

Hi DigitCart, I got this to show on my product page, however, how do I allow it to show comma to separate values. Also how do we convert on currency change? (As currently this only reflects in the default currency.)
Thanks
DigitCart wrote:
Sat Nov 11, 2017 5:12 pm
You're welcome.

Regards,
Nightwing
Access to my Free Extensions: https://www.opencart.com/index.php?rout ... =nightwing


Active Member

Posts

Joined
Tue Nov 05, 2019 11:08 pm


Post by blackseabreathe2 » Sat May 15, 2021 8:53 pm

//$this->cart->getSubTotal()
//and
//$this->cart->getTotal()

fortunately it returns totals NOT including coupons


Posts

Joined
Sat Mar 27, 2021 7:34 pm

Post by faizanyasn » Sun May 16, 2021 12:02 pm

You just need minor tweaking

Use cart total function:

Code: Select all

$order_total = $this->cart->getTotal();
so the overall code will be

Code: Select all

<?php 
$total = $this->cart->getTotal();
if ($total > 100) {
echo "Your are eligable for FREE SHIPPING"; 
}
else { 
echo  "To be eligable for free shipping you need to buy for ".$sum." more"; 
}	  
?>

For further assistance for Opencart Development you can reach me out at
http://asktofaizan.com/ocd.php | http://asktofaizan.com | http://alliancedigitals.com


Newbie

Posts

Joined
Tue Jan 12, 2021 2:28 pm

Post by OSWorX » Sun May 16, 2021 3:58 pm

faizanyasn wrote:
Sun May 16, 2021 12:02 pm
You just need minor tweaking
and so on ..
Whoever may find this page, the above advice is completely wrong!
Whenever you have to define or set variables, do it inside the controller, assign a variable and use that later in the view!

That's simply what and why it is called MVC > Model View Controller.
Never mix php code with html in your templates - is an old (and outdated) technique used in the bginning of the 20th century.

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Guru Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by faizanyasn » Sun May 23, 2021 11:05 pm

OSWorX wrote:
Sun May 16, 2021 3:58 pm
faizanyasn wrote:
Sun May 16, 2021 12:02 pm
You just need minor tweaking
and so on ..
Whoever may find this page, the above advice is completely wrong!
Whenever you have to define or set variables, do it inside the controller, assign a variable and use that later in the view!

That's simply what and why it is called MVC > Model View Controller.
Never mix php code with html in your templates - is an old (and outdated) technique used in the bginning of the 20th century.
I guess you are new to oc or may be more as student, obviously above code should me inside of the controller was just giving them idea how it will work

For further assistance for Opencart Development you can reach me out at
http://asktofaizan.com/ocd.php | http://asktofaizan.com | http://alliancedigitals.com


Newbie

Posts

Joined
Tue Jan 12, 2021 2:28 pm

Post by OSWorX » Sun May 23, 2021 11:32 pm

faizanyasn wrote:
Sun May 23, 2021 11:05 pm
OSWorX wrote:
Sun May 16, 2021 3:58 pm
faizanyasn wrote:
Sun May 16, 2021 12:02 pm
You just need minor tweaking
and so on ..
Whoever may find this page, the above advice is completely wrong!
Whenever you have to define or set variables, do it inside the controller, assign a variable and use that later in the view!

That's simply what and why it is called MVC > Model View Controller.
Never mix php code with html in your templates - is an old (and outdated) technique used in the bginning of the 20th century.
I guess you are new to oc or may be more as student, obviously above code should me inside of the controller was just giving them idea how it will work
It seems you are a funny guy.
Checking the date you registered here, your signature "For further assistance for Opencart Development .." and the answer you are giving, I would suggest not to use this novice.

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Guru Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria
Who is online

Users browsing this forum: No registered users and 3 guests