Post by Cue4cheap » Tue Nov 30, 2021 1:26 pm

OC2.3.0.2
I have made a copy of the COD module, named OD2, and it works as a different payment module.
Now here is the issue I am running into. I have a limited group of products and each purchaser gets a specific code that I need to display on the checkout success page.
I created the variable in the COD2 controller file using

Code: Select all

$data['displaycustcode'] = 'H085aJG7Hrqj29';
I can then see it on the cod2.tpl page using echo $displaycustcode;
So I know it is set.
But when I process the order and do the same echo $displaycustcode; on the success page it isn't there.
I also tried in the cod2 controller file

Code: Select all

$this->session->data['displaycustcode'] = 'H085aJG7Hrqj29';
But still not there on the success tpl page.
Can anyone please tell me WHAT am I missing?
Thank you,
Mike

cue4cheap not cheap quality


Expert Member

Posts

Joined
Fri Sep 20, 2013 4:45 am

Post by thekrotek » Tue Nov 30, 2021 2:52 pm

The session variable should work. Either you're doing something wrong or session is lost somehow.

Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com


User avatar
Expert Member

Posts

Joined
Sun Jul 03, 2016 12:24 am


Post by pprmkr » Tue Nov 30, 2021 3:37 pm

Setting variable in paymentmethod is the way:

Code: Select all

$this->session->data['displaycustcode'] = 'H085aJG7Hrqj29';
And then in catalog/controller/checkout/success.php:

Code: Select all

	if (isset($this->session->data['displaycustcode']) {
		$data['displaycustcode'] = $this->session->data['displaycustcode'];
	} else {
		$data['displaycustcode'] = false;
In catalog/view/template/default/common/success.tpl:

Code: Select all

<?php if($displaycustcode) echo $displaycustcode; ?>

User avatar
Active Member
Online

Posts

Joined
Sat Jan 08, 2011 11:05 pm
Location - Netherlands

Post by Cue4cheap » Wed Dec 01, 2021 12:49 am

Thank you for the replies but I am still going in circles....
Since copying the cod files could cause issues and I am on my test environment I put the changes into the original COD file. Same result.
BTW the test environment works in every way just trying to do this doesn't work.

In the cod.php controller file I put in both:

Code: Select all

$this->session->data['displaycustcode'] = 'H085aJG7Hrqj29';
$data['displaycustcode'] = 'H085aJG7Hrqj29';
Then in the cod.tpl I echo out:

Code: Select all

<?php
echo $this->session->data['displaycustcode'] . 'session';
echo $displaycustcode ;
?>
The first one only shows "session" with errors in the log of
Undefined property: Template\PHP::$session in /catalog/view/theme/default/template/extension/payment/cod.tpl on line 4
Trying to get property 'data' of non-object in /catalog/view/theme/default/template/extension/payment/cod.tpl on line 4
Trying to access array offset on value of type null in /catalog/view/theme/default/template/extension/payment/cod.tpl on line 4

The echo $displaycustcode shows the H085aJG7Hrqj29.

One more shoot for this attempt I put into the cod.tpl file:

Code: Select all

var_dump($this->data); 
var_dump($this->session->data);
The $this->data dumps all the variables
the $this->session->data gives me NULL

So it is a defined and understood variable but not in the session???

BTW I also did the $this->session->data in the live store and it also is null. This can't be as the live store has orders process and has proper display on the success page.
So confused.....
Mike

cue4cheap not cheap quality


Expert Member

Posts

Joined
Fri Sep 20, 2013 4:45 am

Post by Cue4cheap » Wed Dec 01, 2021 1:25 am

Ok!!!!!!

I've given up for today. I will wipe my test environment and start again tomorrow after I take care of the business. So odd I can't dump the session wtih var_dump($this->session->data); but I am convinced my code is accurate so I am going to start fresh as this doesn't make any sense.

Mike

cue4cheap not cheap quality


Expert Member

Posts

Joined
Fri Sep 20, 2013 4:45 am

Post by Cue4cheap » Wed Dec 01, 2021 5:48 am

Something was certainly messed up with my clone of my website. Recloned it and now $this->session->data['displaycustcode'] = 'H085aJG7Hrqj29'; worked.
Now back to where I was yesterday
Mike

cue4cheap not cheap quality


Expert Member

Posts

Joined
Fri Sep 20, 2013 4:45 am
Who is online

Users browsing this forum: No registered users and 73 guests