Hello,
I'm new in the programming world and to opencart and I would like to know if there is any way to access the data of a variable that is placed in a file, from another file that could even be in another directory.
For example I am in the catalog/model/extension/payment/free_checkout.php file,
and I want to access a variable that is in catalog/model/journal3/checkout.php
What I'm trying to do is enabling/disabling free checkout on checkout page (by making it's status true or false), for orders that have a certain shipping method.
So I want have access to the shipping method, which I have saved in a variable in the second file in this example.
Sorry if the question is too newbie, and thank you for your time.
Assuming 3.0.x, have you tried? Where x is the code for the shipping method you want to check.
Code: Select all
if (isset($this->session->data['shipping_method']['code']) && $this->session->data['shipping_method']['code'] == 'x') {
// do something
}
Thanks for your reply,ADD Creative wrote: ↑Wed Jan 25, 2023 6:47 pmAssuming 3.0.x, have you tried? Where x is the code for the shipping method you want to check.Code: Select all
if (isset($this->session->data['shipping_method']['code']) && $this->session->data['shipping_method']['code'] == 'x') { // do something }
I'm running opencart 3.0.3.8.
The error in my case was that I was using data['shipping_code'].
It works now!
So the way to access a variable that I made in a file, is to store it inside the $data array ?
The files you mention will be two different requests, so you will need to store the variable in the session.
Be aware that it will stay for the life of the session unless unset. You may be best just to check the shipping code set in the session in the free_checkout.php.
Code: Select all
$this->session->data['my_var'] = 'something';
Oh I see..ADD Creative wrote: ↑Thu Jan 26, 2023 8:19 pm
Be aware that it will stay for the life of the session unless unset. You may be best just to check the shipping code set in the session in the free_checkout.php.
Is there a way to control how long the session will last?
Sessions do expire and you can adjust the time, but I don't see how that would help you.
It's for educational purposes and testing only..!ADD Creative wrote: ↑Fri Jan 27, 2023 7:12 pmSessions do expire and you can adjust the time, but I don't see how that would help you.
Session lifetime is controlled by a combination of the following. However, OpenCart 3.0.x work slightly differently as it has its own session handler, which you would have to fix the bugs in. You also have to remember every request will reset the session lifetime.
https://www.php.net/manual/en/session.c ... e-lifetime
https://www.php.net/manual/en/session.c ... axlifetime
https://www.php.net/manual/en/session.c ... e-lifetime
https://www.php.net/manual/en/session.c ... axlifetime
Who is online
Users browsing this forum: No registered users and 360 guests