Post by supak111 » Mon May 13, 2024 9:11 am

I've looked through so much code and still can't figure out why OC3 only remembers: zip code, state, country, between guest checkout and register checkout BUT NOT first/last name, email, telephone, address

Can anyone explain to me what code makes it only remember those but not: first/last name, email, telephone, address?

What I mean is:
~go to checkout, in STEP-1 chose GUEST,
~in STEP-2 fillout everything and click CONTINUE.
~Now you are in STEP-3 or STEP-4, now go back to STEP-1 and change to REGISTER ACCOUNT and click CONTINUE
~Now in STEP-2 for register account you will see it only remembered: zip code, state, country, BUT NOT first/last name, email, telephone, address

WHY? I guess I'm too dumb to figure it out after 2 hours
.

~ OC 3.0.3.2 and OCmods only ~


User avatar
Active Member

Posts

Joined
Fri Feb 13, 2015 12:09 pm

Post by straightlight » Mon May 13, 2024 9:31 am

supak111 wrote:
Mon May 13, 2024 9:11 am
I've looked through so much code and still can't figure out why OC3 only remembers: zip code, state, country, between guest checkout and register checkout BUT NOT first/last name, email, telephone, address

Can anyone explain to me what code makes it only remember those but not: first/last name, email, telephone, address?

What I mean is:
~go to checkout, in STEP-1 chose GUEST,
~in STEP-2 fillout everything and click CONTINUE.
~Now you are in STEP-3 or STEP-4, now go back to STEP-1 and change to REGISTER ACCOUNT and click CONTINUE
~Now in STEP-2 for register account you will see it only remembered: zip code, state, country, BUT NOT first/last name, email, telephone, address

WHY? I guess I'm too dumb to figure it out after 2 hours
.
It looks like you're still using OC v3.0.3.2, according to your signature. Have you tried the latest OC v3.0.3.9 or OC v3.2.0.0 release to see if the issue could be replicated?

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 supak111 » Mon May 13, 2024 10:31 am

It looks like you're still using OC v3.0.3.2, according to your signature. Have you tried the latest OC v3.0.3.9 or OC v3.2.0.0 release to see if the issue could be replicated?
I've tested what I wrote above on other peoples OC websites different versions of OC3 and it's the same. OC is made to only remember ZIP, STATE, COUNTRY. It clears the other fields and I want to know what code is making it only remember those 3 and not the rest.

Try it yourself if you have an OC website

~ OC 3.0.3.2 and OCmods only ~


User avatar
Active Member

Posts

Joined
Fri Feb 13, 2015 12:09 pm

Post by softmonke » Mon May 13, 2024 12:17 pm

If you select the "Register Account" option, the controller "catalog/controller/checkout/register.php" is loaded, whereas for "Guest Checkout", the controller "catalog/controller/checkout/guest.php" is loaded.

In "guest.php', you can see that the address fields are stored in:

Code: Select all

$this->session->data['payment_address']
and

Code: Select all

$this->session->data['shipping_address']
But the customer details (first name, last name, email, telephone) are stored in:

Code: Select all

$this->session->data['guest']
In "register.php", you can also see that it only checks if "postcode", "country_id", and "zone_id" exist in the "shipping_address" session array, and then proceeds to retrieve those values if they exist. For instance, the below code is found in "register.php":

Code: Select all

if (isset($this->session->data['shipping_address']['postcode'])) {
	$data['postcode'] = $this->session->data['shipping_address']['postcode'];
} else {
	$data['postcode'] = '';
}
which retrieves the "postcode" value from the "shipping_address" session array to display them in the fields at checkout on the frontend.

So what you could do is to add your own code to check if the other required data is available via "shipping_address" or "payment_address" and "guest" stored in the session array, and assign them to the "$data" variable so that you can display them in the fields in "register.twig".

Also, it doesn't actually clear the fields, it just doesn't access the fields stored in the session to display them. If you go to "Guest Checkout" and fill up all the fields and proceed to Step 4, then back to Step 1 and select "Register Account", and then back to "Guest Checkout" again, you can see that the original values filled up in the fields are all appearing - so the fields aren't actually cleared - you just need to access them from the session array. Hope that helps!

Check out our ever-growing list of extensions for OpenCart here.
Some useful extensions for a better admin experience: Image File Manager ProDrag & Drop Sort Order

Reach out to us at hello@softmonke.com for your OpenCart web development needs or feedback for our extensions.


User avatar
Active Member

Posts

Joined
Tue May 23, 2023 4:42 am


Post by supak111 » Mon May 13, 2024 1:20 pm

That defiantly helps, it's exactly what I was looking at.
But when I try adding this to register.php it still doesn't remember the CITY for example

Code: Select all

if (isset($this->session->data['shipping_address']['city'])) {
       	$data['city'] = $this->session->data['shipping_address']['city'];
} else {
	$data['city'] = '';
}
This doesn't work either

Code: Select all

if (isset($this->session->data['payment_address']['city'])) {
	$data['city'] = $this->session->data['payment_address']['city'];
} else {
	$data['city'] = '';
}
PS I know the page is updating because when I comment-out code for ZIPcode it stops remembering the ZiPcode. this code:

Code: Select all

//if (isset($this->session->data['shipping_address']['postcode'])) {
//	$data['postcode'] = $this->session->data['shipping_address']['postcode'];
//} else {
//	$data['postcode'] = '';
//}
Last edited by supak111 on Mon May 13, 2024 1:53 pm, edited 2 times in total.

~ OC 3.0.3.2 and OCmods only ~


User avatar
Active Member

Posts

Joined
Fri Feb 13, 2015 12:09 pm

Post by supak111 » Mon May 13, 2024 1:46 pm

Just tried to make it remember the firstname with the code below by adding to register.php, but this doesn't work either. Am I missing some code?

Code: Select all

if (isset($this->session->data['guest']['firstname'])) {
	$data['firstname'] = $this->session->data['guest']['firstname'];
} else {
	$data['firstname'] = '';
}

~ OC 3.0.3.2 and OCmods only ~


User avatar
Active Member

Posts

Joined
Fri Feb 13, 2015 12:09 pm

Post by softmonke » Mon May 13, 2024 2:46 pm

supak111 wrote:
Mon May 13, 2024 1:46 pm
Just tried to make it remember the firstname with the code below by adding to register.php, but this doesn't work either. Am I missing some code?

Code: Select all

if (isset($this->session->data['guest']['firstname'])) {
	$data['firstname'] = $this->session->data['guest']['firstname'];
} else {
	$data['firstname'] = '';
}
Open up the template file "register.twig" and insert the firstname variable into the first name field's value attribute. For example, the following is the original first name field HTML:

Code: Select all

<input type="text" name="firstname" value="" placeholder="{{ entry_firstname }}" id="input-payment-firstname" class="form-control" />
so you should echo the variable in the value attribute like below:

Code: Select all

<input type="text" name="firstname" value="{{ firstname }}" placeholder="{{ entry_firstname }}" id="input-payment-firstname" class="form-control" />
If it's still not showing, you might want to debug further by logging the session array and checking if they are indeed set.

Check out our ever-growing list of extensions for OpenCart here.
Some useful extensions for a better admin experience: Image File Manager ProDrag & Drop Sort Order

Reach out to us at hello@softmonke.com for your OpenCart web development needs or feedback for our extensions.


User avatar
Active Member

Posts

Joined
Tue May 23, 2023 4:42 am


Post by supak111 » Mon May 13, 2024 7:56 pm

Got all the fields in register.php to populate, thank you very much for your help ツ @softmonke
.

~ OC 3.0.3.2 and OCmods only ~


User avatar
Active Member

Posts

Joined
Fri Feb 13, 2015 12:09 pm

Post by straightlight » Mon May 13, 2024 8:22 pm

supak111 wrote:
Mon May 13, 2024 7:56 pm
Got all the fields in register.php to populate, thank you very much for your help ツ @softmonke
.
Now that the issue has been solved, please add: [SOLVED] at the beginning of the subject line on your first post.

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 19 guests