Post by kaliyas » Tue Nov 11, 2014 9:11 pm

Greetings,

I am trying to get the total value of the order including shipping and discounts.
I have been using $this->cart->getTotal() and I am getting the value of the cart, but without the shipping and discounts.

What is the function i need to use or what should I edit to get the total value of the order.

Thanks

New member

Posts

Joined
Sat Dec 17, 2011 6:36 pm

Post by Johnathan » Wed Nov 12, 2014 12:09 am

$this->cart->getTotal() only includes the sub-total of the products + tax.

To get the actual total, you need to loop through all the Order Total extensions. Take a look at the /catalog/controller/checkout/confirm.php file to see how it does it.

Image Image Image Image Image


User avatar
Administrator

Posts

Joined
Fri Dec 18, 2009 3:08 am


Post by kaliyas » Thu Nov 13, 2014 2:07 am

Thanks Johnathan, but I found my problem is far to be solved.
I thought I had a porting with the subtotal, but I am back to zero again. When I echo the total in the success.tpl it echo 0.

This is what I have done so far. Opencart 1.5.5.1

catalog/controller/checkout/success.php

Code: Select all

public function index() {
    $this->data['order_id'] = 0; // <-- NEW LINE
    $this->data['total'] = 0; // <-- NEW LINE

    if (isset($this->session->data['order_id'])) {
        $this->data['order_id'] = $this->session->data['order_id']; // <-- NEW LINE
        $this->data['total'] = $this->cart->getTotal(); // <-- NEW LINE

        $this->cart->clear();
And in catalog/controller/checkout/success.tpl

Code: Select all


<?php if (isset($this->request->get['route']) && $this->request->get['route'] == 'checkout/success') { ?>

<!-- Facebook Conversion Code for TN Checkout -->
<script>(function() {
var _fbq = window._fbq || (window._fbq = []);
if (!_fbq.loaded) {
var fbds = document.createElement('script');
fbds.async = true;
fbds.src = '//connect.facebook.net/en_US/fbds.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(fbds, s);
_fbq.loaded = true;
}
})();
window._fbq = window._fbq || [];
window._fbq.push(['track', 'xxxx', {'value':'<?php echo $total; ?>','currency':'USD'}]);
</script>
<noscript><img height="1" width="1" alt="" style="display:none" src="https://www.facebook.com/tr?ev=xxxxx&cd[value]=0&cd[currency]=USD&noscript=1" /></noscript>

<?php } ?>
In the end user success code Im getting echo "0", not even the subtotal.
I have also tried to get the order ID, but it gives me 0 as well. If I delete $this->data['total'] = 0; I will get the subtotal value only one time, after that I gives me error: undefined variable.

Any ideas?

New member

Posts

Joined
Sat Dec 17, 2011 6:36 pm

Post by Johnathan » Fri Nov 14, 2014 12:24 am

Not sure...your code looks correct, so it seems like it should be working.

Note that the cart is cleared after a single load of the page, so it's only going to work for an order once. You'll need to place a new order every time, or comment out the code that clears the session data.

Beyond that, I'm not sure what to suggest, except to double-check that you don't have vQmod installed and something modifying that file. Perhaps someone else will see something that I've missed.

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 190 guests