1

I'm developing an extension for opencart 2.3. I want to retrieve the order Id when a customer comes to checkout/success page. This is my code in the extension?

if(isset($this->request->get['route']) && $this->request->get['route'] == "checkout/success")
{
  if (isset($this->session->data['order_id']) && (!empty($this->session->data['order_id']))) 
     { $order_id = $this->session->data['order_id']; ... }
}

I know this doesn't work because I saw this code unset($this->session->data['order_id']); in \catalog\controller\checkoutsuccess.php.

can anybody help me about this without touching to main document of opencart?

Maher
  • 2,517
  • 1
  • 19
  • 32
Tim Rosi
  • 13
  • 2

1 Answers1

0

I have a free vqMod extension that does this very thing. It's at https://www.opencart.com/index.php?route=marketplace/extension/info&extension_id=18125

Note: To use vqMod extensions, you must first install vqMod for OpenCart. Details and instructions available here: https://github.com/vqmod/vqmod/wiki/Installing-vQmod-on-OpenCart

You have to save off this value before it gets cleared (as you noted) and then you can display it later. That's what my mod does.

Logic:

<file name="catalog/language/en-gb/checkout/success.php">
        <operation info="Add language string">

                <search position="after"><![CDATA[
                // Text
                ]]></search>

                <add><![CDATA[
                $_['text_order']   = 'Your order ID is %s.';
                ]]></add>

        </operation>
</file>
<file name="catalog/controller/checkout/success.php">
        <operation info="Save Order ID">

                <search position="after"><![CDATA[
                 if (isset($this->session->data['order_id'])) {
                ]]></search>

                <add><![CDATA[
                $this->session->data['last_order_id'] = $this->session->data['order_id'];
                ]]></add>

        </operation>
</file>
<file name="catalog/controller/checkout/success.php">
        <operation info="Output Order ID">

                <search position="before"><![CDATA[
                $data['button_continue']
                ]]></search>

                <add><![CDATA[
                $data['text_message'] .= sprintf($this->language->get('text_order'),  $this->session->data['last_order_id']);
                ]]></add>

        </operation>
</file>
Scott C Wilson
  • 19,102
  • 10
  • 61
  • 83
  • It has been tested with the default template. If your template is different, you will have to adjust it. Also be sure to clear your mods.cache and vqcache when testing a vqMod. – Scott C Wilson Jun 21 '17 at 10:16
  • Remember too: a vqMod is just a plain text set of changes to apply to some files. So you can try directly making those changes to your files and testing (rather than installing the vqMod) to see what needs to be done with your theme/file/other changes, etc. to make it work. – Scott C Wilson Jun 21 '17 at 11:05