Post by arosesiej » Wed Sep 23, 2015 11:07 pm

What kind of information can I pull from $this->session->data?

I know that data is an array, but what sub-arrays lie within data? Can't find any real documentation on this?

Also, what would be the variables that contain a customer's(logged in or not) country, region, post code if they entered it into the "Estimate Shipping" on Cart page? I notice that it gets carried over to the Checkout page.

How can I access these?

New member

Posts

Joined
Thu Jun 25, 2015 8:52 pm

Post by Johnathan » Thu Sep 24, 2015 12:46 am

The format and structure of $this->session->data changes from version to version, so the easiest way is just to print it out so you can see it. I usually do something like this in the /catalog/controller/common/header.php file:

Code: Select all

echo '<!--'; print_r($this->session->data); echo '-->'; 
That will hide it from the rendered HTML, but still show it in the source, so you can see what the session variables are on a given page.

Image Image Image Image Image


User avatar
Administrator

Posts

Joined
Fri Dec 18, 2009 3:08 am


Post by arosesiej » Thu Sep 24, 2015 1:09 am

Okay, thank you.

Now, what array is the customer's postal code, region, and country stored in? Is that something that gets cleared or is it saved for the session?

New member

Posts

Joined
Thu Jun 25, 2015 8:52 pm

Post by Johnathan » Thu Sep 24, 2015 11:25 pm

It's different depending on your version, so the best way to tell is just to add that code and then look for the data in there. I believe in the latest versions it's usually something like:

Code: Select all

$this->session->data['shipping_country_id']
$this->session->data['shipping_zone_id']
$this->session->data['shipping_postcode']

Image Image Image Image Image


User avatar
Administrator

Posts

Joined
Fri Dec 18, 2009 3:08 am


Post by straightlight » Sun Oct 04, 2015 9:55 pm

Take note that the payment_ versus shipping_ also implies into the session data in order to capture the country, zone and postcode.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by power7714 » Wed Feb 15, 2017 2:09 pm

Does printing the session variables like this still work with version 2.3?

Newbie

Posts

Joined
Thu Feb 02, 2017 12:09 pm

Post by Johnathan » Thu Feb 16, 2017 12:20 am

It works in all versions. The session data variable has been consistent since OpenCart 1.4, at the very least:

$this->session->data

Image Image Image Image Image


User avatar
Administrator

Posts

Joined
Fri Dec 18, 2009 3:08 am


Post by storm-cloud » Thu Jul 05, 2018 9:30 am

Johnathan wrote:
Thu Sep 24, 2015 12:46 am
The format and structure of $this->session->data changes from version to version, so the easiest way is just to print it out so you can see it. I usually do something like this in the /catalog/controller/common/header.php file:

Code: Select all

echo '<!--'; print_r($this->session->data); echo '-->'; 
That will hide it from the rendered HTML, but still show it in the source, so you can see what the session variables are on a given page.
I cannot seem to print out the session data for 'agree'. Whenever I use the above method, all the session data is printed but the 'agree' data is missing.

In catalog/controller/checkout/payment_method.php there is a check for this:

Code: Select all

if (isset($this->session->data['agree'])) {
I am looking to conditionally set this session data depending on the products are in the cart. However, I would need to first see what data is set and where it is set. Can anyone help?

Active Member

Posts

Joined
Wed Feb 22, 2012 8:07 am

Post by straightlight » Thu Jul 05, 2018 9:46 am

That would be in your catalog/controller/checkout/confirm.php file around:

Code: Select all

// Validate minimum quantity requirements.
where you could add your own if statement:

Code: Select all

if (isset($this->session->data['agree'])) {
			// Your condition statement here.
		}

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: No registered users and 23 guests