Post by 68Thorby68 » Wed Feb 19, 2020 6:59 pm

Hi,
At the end of the checkout process, I have a number of tasks to complete to fulfill the banks requirements, and to do this i need to pass $this->session->data to a new page (controller). However, I've noticed the construct(s) that manage controllers understandably resets session data arrays and the like. Does anyone have a good solution for me to keep the entire $this->session->data array (or somthing similar) for use on another page?

Thanks.

Opencart 3.0.3.1
Default Theme
Single Store

New member

Posts

Joined
Tue Dec 17, 2019 9:02 pm

Post by thekrotek » Wed Feb 19, 2020 7:10 pm

Copy session data array to another array and use it as you wish.

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 68Thorby68 » Wed Feb 19, 2020 7:19 pm

Thanks thekrotek,
But unfortuantely given the stateless nature of PHP this will not work, a straight copy of the array will not be available for other pages.
I've tried using native $_SESSION, but it seems OC unsets this as well.

I was wondering if OC uses any specific named arrays that do not unset when a new page is called, for the specific purpose of passing data between pages?

New member

Posts

Joined
Tue Dec 17, 2019 9:02 pm

Post by thekrotek » Wed Feb 19, 2020 7:30 pm

Of course, I was talking about session array. Use it like $this->session->data['myarray'] = array(); and data will be kept until you unset them.

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 68Thorby68 » Wed Feb 19, 2020 8:51 pm

Many thanks thekrotek, I really appreciate you help.

I've just tested the suggested solution but unfortunately the something in OC appears to unset $this->session->data at this level, meaning all and any array associated with $this->session->data is unset.

For example..
in ControllerCheckoutPaymentMethod i can define
$this->session->data['checkoutData']=array('customer_id=>$this->session->data['customer_id']);
immdeiately before
$this->response->setOutput($this->load->view('checkout/payment_method', $data));

But once payment_method.twig is processed and a form post response calls

class ControllerCheckoutBankProcessing extends Controller {
public function index() {
print_r($this->session->data['checkoutData']);

I get the error "Notice: Undefined index: checkoutData in /mydomain/catalog/controller/checkout/bank_processing.php on line 4"

However if I print_r($this->session->data) a new session array has been constructed (i assume by the controller), not including ['checkoutData'] .

New member

Posts

Joined
Tue Dec 17, 2019 9:02 pm

Post by kestas » Wed Feb 19, 2020 9:29 pm

68Thorby68 wrote:
Wed Feb 19, 2020 8:51 pm
Many thanks thekrotek, I really appreciate you help.

I've just tested the suggested solution but unfortunately the something in OC appears to unset $this->session->data at this level, meaning all and any array associated with $this->session->data is unset.

For example..
in ControllerCheckoutPaymentMethod i can define
$this->session->data['checkoutData']=array('customer_id=>$this->session->data['customer_id']);
immdeiately before
$this->response->setOutput($this->load->view('checkout/payment_method', $data));

But once payment_method.twig is processed and a form post response calls

class ControllerCheckoutBankProcessing extends Controller {
public function index() {
print_r($this->session->data['checkoutData']);

I get the error "Notice: Undefined index: checkoutData in /mydomain/catalog/controller/checkout/bank_processing.php on line 4"

However if I print_r($this->session->data) a new session array has been constructed (i assume by the controller), not including ['checkoutData'] .
Should work. I have just checked this part of code. Just change line in red to:

Code: Select all

$this->session->data['checkoutData'] = array('customer_id'=>$this->session->data['customer_id']);

Custom OpenCart modules and solutions. You can write PM with additional questions... Extensions you can find here


Active Member

Posts

Joined
Tue Oct 12, 2010 2:23 am

Post by straightlight » Wed Feb 19, 2020 10:11 pm

Since you're looking to add a session data into the payment method, and that you're using OC v3.x releases, better to use events to accomplish this. Also take note that during API backward compatibility, you may not be able to retrieve a session data that's been initiated from the catalog-end as opposed to the admin-end.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Opencart.com Administrator / Quality Assurance Analyst / Programmer / Opencart Tester


Legendary Member

Posts

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

Post by 68Thorby68 » Wed Feb 19, 2020 10:16 pm

Many, many thanks Krotek,

I made the suggested changes but alas "no cigar".

On the bank process page (after setting the session data as suggested)
print_r($this->sesion-data['checkoutData']);
Notice: Undefined index: checkoutData in /mydomain/catalog/controller/checkout/bank_processing.php on line 5

print_r($this->sesion-data);
Array ( [language] => en-gb [currency] => GBP )

I'm not sure what is going on here as I cannot see where session is being unset and where new session is created. I'll have to trawl through the system folder and try and work out what is going on, especially as you have taken the time to test this yourself and seen it working.

If I find what was causing the problem in my install, and I find a fix, I will post here for others to experience.

Thank you again, I've taken ltos of your time.

New member

Posts

Joined
Tue Dec 17, 2019 9:02 pm

Post by Johnathan » Wed Feb 19, 2020 11:06 pm

Everyone is correct that the session is stored between all page and controller loading, so you should be able to use a variable/array like they describe. However, if that's not happening with your payment gateway then the URL is most likely being accessed by the payment method server, and not the original customer. That means it's not the same session, so the variable/array can't be passed between them. This is the most likely explanation for what's going on.

To work around that, you'll either need to (1) put the variable into the URL that the payment gateway visits, so you can retrieve it from the GET request, or (2) store the value in a custom database table or column, and load it based on the order_id or some other data that is shared across the two separate sessions. Both of those require some coding knowhow, so if you're not sure how to do those things I would recommend hiring someone to assist. If you need to find a developer, you can post a request in the OpenCart "Commercial Support" forum, which is checked by a number of OpenCart developers. You can also try checking out the OpenCart "Partners" area.

Image
Image Image Image Image


User avatar
Global Moderator

Posts

Joined
Fri Dec 18, 2009 3:08 am


Post by straightlight » Thu Feb 20, 2020 4:41 am

Added in FAQ.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Opencart.com Administrator / Quality Assurance Analyst / 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 17 guests