Order total value and order id in Opencart

OpenCart is designed with feature rich, easy to use, search engine friendly and with a visually appealing interface.

There is vast collection of extensions to fulfill basic and frequently required operations. But main problem is that most of the extensions are of paid version, and most of the developers and client don’t want to pay for some extensions.

Opencart Ecommerce

Here I have mention some of the frequently asked question by many developers and clients, i.e :

  • How to add total value  and order id in order confirmation page of opencart?

  • How to add conversion tracking code in opencart with conversion code?

So here, I have mention some easy solution of above problems, for  that you don’t have to pay anything to anyone.

Just get FTP access of your website and then keep a backup site or minimum those pages which you are going to upload.

The problem here is that on success page all the order data is already unset (deleted) from session variables. That is why we won’t be able to show those order details directly on the order confirmation page.

Look into catalog/controller/checkout/success.php and change the beginning of the index() function, code will look like :

public function index() {
    if (isset($this->session->data['order_id'])) {
        $this->cart->clear();

        unset($this->session->data['shipping_method']);
        unset($this->session->data['shipping_methods']);
        unset($this->session->data['payment_method']);
        unset($this->session->data['payment_methods']);
        unset($this->session->data['guest']);
        unset($this->session->data['comment']);
        unset($this->session->data['order_id']);    
        unset($this->session->data['coupon']);
        unset($this->session->data['reward']);
        unset($this->session->data['voucher']);
        unset($this->session->data['vouchers']);
    }   

    $this->language->load('checkout/success');

Now you have to add few lines of code in the above code

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();

        unset($this->session->data['shipping_method']);
        unset($this->session->data['shipping_methods']);
        unset($this->session->data['payment_method']);
        unset($this->session->data['payment_methods']);
        unset($this->session->data['guest']);
        unset($this->session->data['comment']);
        unset($this->session->data['order_id']);    
        unset($this->session->data['coupon']);
        unset($this->session->data['reward']);
        unset($this->session->data['voucher']);
        unset($this->session->data['vouchers']);
    }   

    $this->language->load('checkout/success');

Now you have the order_id and cart’s total values stored in template variables, so just use them in your success.tpl ( catalog/view/theme/[YOUR THEME]/template/common/success.tpl).

<!--?php if($order_id) { ?-->
Your order id is: <!--?php echo $order_id; ?-->
Total Amount is:<!--?php echo $total; ?-->
<!--?php } ?-->

Note : It is working fine for me, there might be some issue as per version or customization of opencart. If you are facing any problem, you can put some word to us.

9 thoughts on “Order total value and order id in Opencart

  1. I really want to say thank you because this post help me implement conversion code in opencart with conversion value.
    I also want to rectify something.
    In the above code you have add some new lines

    $this->data['order_id'] = 0;
    $this->data['total'] = 0;

    and

    $this->data['order_id'] = $this->session->data['order_id'];
    $this->data['total'] = $this->cart->getTotal();

    sometime it throws some warning.But if we modify these lines as below ,everything will work fine.

    $data['order_id'] = 0;
    $data['total'] = 0;

    and

    $data['order_id'] = $this->session->data['order_id'];
    $data['total'] = $this->cart->getTotal();

    I also looked on your other posts, those are really awesome and help, I really appreciate your writing.

      1. Hello,
        Thank you for the info. I am trying to do the conversion for Facebook;
        Can I still use these codes stipulated for Opencart 3 –
        $data[‘order_id’] = 0;
        $data[‘total’] = 0;
        and
        $data[‘order_id’] = $this->session->data[‘order_id’];
        $data[‘total’] = $this->cart->getTotal();

  2. Pingback:How to add Google Analytics in Opencart | Notes on Click

  3. Thanks for this article, all these instruction helped me implement conversion tracking code.
    this is really Sweet website, super layout, very clean and utilise genial.

  4. Great info and right to the point. I don’t know if this is actually the best place to ask but do you guys have any ideea where to get some professional writers? Thank you 🙂

  5. Pingback:How to add Google Analytics in Opencart | Notes On Click

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.