Post by myaskro » Sat Jun 06, 2020 9:23 pm

I am requested to make an extension for opencart version 2.2 that allow the customers to checkout as guest by default (without giving them an option to checkout as guest or register an account). And if the customer completes all the checkout steps and land on order success page only then he should be given an option to create an account by providing a password only if he so desired. (i.e he doesn't need to re-type all fields he typed to checkout as guest again just to create an account on the store, instead he only need to provide the password to access the account and other fields should be fetched from data he already entered during checkout as guest)

And if he doesn't want to create an account he can leave it as it is without typing any password and his order should be treated as complete but as a guest though.

any idea how to implement this?

If I use $this->customer->addCustomer($data) function then I can create an accountbut my concern is how to pass guest data to this function on thank you page /order success page?

I will really appreciate if any great master can help me with it.

Newbie

Posts

Joined
Fri Mar 29, 2019 2:16 am

Post by OSWorX » Sat Jun 06, 2020 10:00 pm

Please tell us first, which OpenCart exactly you use - too many differences between, specially in the 2.x branch!
Second, simple hand-over those data as session object.

Custom Development | Individuelle Entwicklung | Support & Bugfixes

Image Image Image


User avatar
Guru Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by myaskro » Sat Jun 06, 2020 10:42 pm

OSWorX wrote:
Sat Jun 06, 2020 10:00 pm
Please tell us first, which OpenCart exactly you use - too many differences between, specially in the 2.x branch!
Second, simple hand-over those data as session object.
Thanks for taking out time to reply me.

1. Opencart Version is 2.2.0.0

2. simple hand-over those data as session object.
I am understanding that the guest data I can store in session object and use that on order success page. But are there any pre-built functions in opencart that I can use. Can you please provide me some details as I'm working on oc for the first time.

Thanks once again.

Disclaimer : I do understand MVC and have looked around some basic extension code. So guide me further in this respect.

Newbie

Posts

Joined
Fri Mar 29, 2019 2:16 am

Post by OSWorX » Sun Jun 07, 2020 12:59 am

myaskro wrote:
Sat Jun 06, 2020 9:23 pm
I am requested to make an extension for opencart version 2.2 ..
I understood that in the way that you are creating a new extension.
Am I not right?

Anyway, in the controller checkout/success you have already the session object (array) with all you need.
Inside this controller you have to create a session array e.g. $this->session->data['guest_register'] (or how you want to name it) and add there all you need.
E.g. the data from the variable $this->session->data['guest'] holds most of that you need (e.g. name. email, address, etc.).

Add in this controller the values into the variables you want to display in the success page, e.g. an Button "Register" (or something else).

If now the Guest clicks on that Button a function (via ajax - has to added also in the success page) in a new controller (e.g. catalog/controller/module/guest_register) is called, where you receive the session data and all the logic to register the guest.
Delete now the session data and return a success message (via json).

Viola - done.
Simple, easy and could be easily added via 10 lines OCMod.

p.s.: best would be if you create a simple module instead of a OCMod where you can en-/disable this function at any time without editing the code again!
If done this way, you could also assign this module via the Layout function (see Menu - I guess 2.2. has this already) to the success page.

Custom Development | Individuelle Entwicklung | Support & Bugfixes

Image Image Image


User avatar
Guru Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by myaskro » Mon Jun 08, 2020 12:53 pm

OSWorX wrote:
Sun Jun 07, 2020 12:59 am
myaskro wrote:
Sat Jun 06, 2020 9:23 pm
I am requested to make an extension for opencart version 2.2 ..
I understood that in the way that you are creating a new extension.
Am I not right?

Anyway, in the controller checkout/success you have already the session object (array) with all you need.
Inside this controller you have to create a session array e.g. $this->session->data['guest_register'] (or how you want to name it) and add there all you need.
E.g. the data from the variable $this->session->data['guest'] holds most of that you need (e.g. name. email, address, etc.).

Add in this controller the values into the variables you want to display in the success page, e.g. an Button "Register" (or something else).

If now the Guest clicks on that Button a function (via ajax - has to added also in the success page) in a new controller (e.g. catalog/controller/module/guest_register) is called, where you receive the session data and all the logic to register the guest.
Delete now the session data and return a success message (via json).

Viola - done.
Simple, easy and could be easily added via 10 lines OCMod.

p.s.: best would be if you create a simple module instead of a OCMod where you can en-/disable this function at any time without editing the code again!
If done this way, you could also assign this module via the Layout function (see Menu - I guess 2.2. has this already) to the success page.

Thanks a lot man, you really saved me a lot of trouble.

1 - Yes, you are right. I'm indeed creating an extension.

2- With your help, I was able to provide user an option to register on order success page by filling in a two line form (i.e for password and confirm password) and click register button if so desired.

3 - Now I am looking to transfer that order from guest to the newly created account any idea how to implement that? I believe I've to update oc_order table customer_id field from "0" with the newly created customer id. Am I right with this logic? What would be an elegant way to achieve it any pre-built functions that can assist me? More important, do I need to update some other tables as well to keep the account functionality same?

4 - I want to create the extension in such a way that I don't have to modify core files as per client request. I was thinking to use ocmod to add session array in success.php page and remaning logic I was planning to put in my module_customname.php file. But you suggest that I should write the code to create session on success.php itself? What's the elegant way to avoid changing core files and achieve it with minimum code?

Thanks again for your help man. I really appreciate your effort. Thanks a ton.

Newbie

Posts

Joined
Fri Mar 29, 2019 2:16 am

Post by OSWorX » Mon Jun 08, 2020 3:40 pm

myaskro wrote:
Mon Jun 08, 2020 12:53 pm
3 - Now I am looking to transfer that order from guest to the newly created account any idea how to implement that? I believe I've to update oc_order table customer_id field from "0" with the newly created customer id. Am I right with this logic? What would be an elegant way to achieve it any pre-built functions that can assist me? More important, do I need to update some other tables as well to keep the account functionality same?

4 - I want to create the extension in such a way that I don't have to modify core files as per client request. I was thinking to use ocmod to add session array in success.php page and remaning logic I was planning to put in my module_customname.php file. But you suggest that I should write the code to create session on success.php itself? What's the elegant way to avoid changing core files and achieve it with minimum code?

Thanks again for your help man. I really appreciate your effort. Thanks a ton.
Was a pleasure - while I do not like to read something ' .. for a client ..' which means you get paid and get here help for free.

About your new extension, I see a way to achieve that.

In general, never adjust an existing database table.
There is a clear statement from the OpenCart Owner not to do so!
Think of the possibility to publish that extension also for other in future (for example).
Also if you make an update.

Instead of that create a new table.
Call it customer_termporary.
Add all what you want and need in that table from the success page - before the session data is deleted.
But send the new record id with a session to the success page.
There you have the new 2 Buttons - if Guest clicks "Register" call the controller of the new extension with that id and transfer the data from that table to the correct tables and delete the temporary table via an ajax call.

Adding the requirded code in the the success.php is done by an 1-liner via OCMod.
Or better by an event - then you do not need any OCMod.

You could also create a success template and call this instead of the original.
This way you do not need to adjust the wether the success controller nor the success page.

Doing so you are independent and compatible for all OC versions > 2.3.x

Custom Development | Individuelle Entwicklung | Support & Bugfixes

Image Image Image


User avatar
Guru Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by myaskro » Wed Jun 10, 2020 1:38 pm

OSWorX wrote:
Mon Jun 08, 2020 3:40 pm
myaskro wrote:
Mon Jun 08, 2020 12:53 pm
3 - Now I am looking to transfer that order from guest to the newly created account any idea how to implement that? I believe I've to update oc_order table customer_id field from "0" with the newly created customer id. Am I right with this logic? What would be an elegant way to achieve it any pre-built functions that can assist me? More important, do I need to update some other tables as well to keep the account functionality same?

4 - I want to create the extension in such a way that I don't have to modify core files as per client request. I was thinking to use ocmod to add session array in success.php page and remaning logic I was planning to put in my module_customname.php file. But you suggest that I should write the code to create session on success.php itself? What's the elegant way to avoid changing core files and achieve it with minimum code?

Thanks again for your help man. I really appreciate your effort. Thanks a ton.
Was a pleasure - while I do not like to read something ' .. for a client ..' which means you get paid and get here help for free.

About your new extension, I see a way to achieve that.

In general, never adjust an existing database table.
There is a clear statement from the OpenCart Owner not to do so!
Think of the possibility to publish that extension also for other in future (for example).
Also if you make an update.

Instead of that create a new table.
Call it customer_termporary.
Add all what you want and need in that table from the success page - before the session data is deleted.
But send the new record id with a session to the success page.
There you have the new 2 Buttons - if Guest clicks "Register" call the controller of the new extension with that id and transfer the data from that table to the correct tables and delete the temporary table via an ajax call.

Adding the requirded code in the the success.php is done by an 1-liner via OCMod.
Or better by an event - then you do not need any OCMod.

You could also create a success template and call this instead of the original.
This way you do not need to adjust the wether the success controller nor the success page.

Doing so you are independent and compatible for all OC versions > 2.3.x
"Was a pleasure - while I do not like to read something ' .. for a client ..' which means you get paid and get here help for free."

Not like that man, I'm just an employee in a firm that develop website solutions. I am not going to get money out of it. I will only be paid the salary that's it.

I would have not asked here, but I hope that's what the community is about. We help each other when they need without expecting money from them. In fact, I too reply on stackoverflow constantly to people who don't understand things that I do. This is how this programming community operate.

Thanks again for your help dear, but being just an employee with no share in client's payment I don't have the luxury to do paid consultation with experts. If you wouldn't help me, I had to do trial and errors hundreds of time just to keep my job save. That's how our lives are as a programmer.

Newbie

Posts

Joined
Fri Mar 29, 2019 2:16 am

Post by OSWorX » Wed Jun 10, 2020 2:53 pm

myaskro wrote:
Wed Jun 10, 2020 1:38 pm
.. I'm just an employee in a firm that develop website solutions. I am not going to get money out of it. I will only be paid the salary that's it.
Maybe not you directly, but the company you are working for and pay your salary.
And they pay you based on your knowledge.
myaskro wrote:
Wed Jun 10, 2020 1:38 pm
.. but being just an employee with no share in client's payment I don't have the luxury to do paid consultation with experts. If you wouldn't help me, I had to do trial and errors hundreds of time just to keep my job save. That's how our lives are as a programmer.
Guess you got the job because you told them that your are a "programmer" .. aren't you?
And correct, ".. our lives are as a programmer .. " I gave you basically allright the complete solution for your queston.

If you are now not able to continue with that, either your are not a "programmer", have the wrong job - or have to pay someone else to do it for you.
So please do not "whine" here around - thx.

Custom Development | Individuelle Entwicklung | Support & Bugfixes

Image Image Image


User avatar
Guru Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by myaskro » Wed Jun 10, 2020 3:26 pm

OSWorX wrote:
Wed Jun 10, 2020 2:53 pm
myaskro wrote:
Wed Jun 10, 2020 1:38 pm
.. I'm just an employee in a firm that develop website solutions. I am not going to get money out of it. I will only be paid the salary that's it.
Maybe not you directly, but the company you are working for and pay your salary.
And they pay you based on your knowledge.
myaskro wrote:
Wed Jun 10, 2020 1:38 pm
.. but being just an employee with no share in client's payment I don't have the luxury to do paid consultation with experts. If you wouldn't help me, I had to do trial and errors hundreds of time just to keep my job save. That's how our lives are as a programmer.
Guess you got the job because you told them that your are a "programmer" .. aren't you?
And correct, ".. our lives are as a programmer .. " I gave you basically allright the complete solution for your queston.

If you are now not able to continue with that, either your are not a "programmer", have the wrong job - or have to pay someone else to do it for you.
So please do not "whine" here around - thx.
You getting the wrong idea man.

I'm not complaining about my job. I was explaining it to you only because I was surprised by your remark that you are getting help for free.

I asked for help because I needed it, if you are not willing to help then you shouldn't come forward. Simply ignore my post that's it. If I had money to invest I'll do it but I didn't come here to ask for paid help. That's not what forums are about.

Anyways, no offense but if you think like that please ignore my future posts. I don't want to upset you by taking your help for free and getting salary for it.

Newbie

Posts

Joined
Fri Mar 29, 2019 2:16 am

Post by Ragsdale778 » Wed Oct 14, 2020 2:32 pm

Thanks for the information keep suggesting such informative post regarding customer checkout as guest but provide them an option to type password and create account if desired on order success please share some more related content keep suggesting post like this mygreatlakes

Newbie

Posts

Joined
Wed Oct 14, 2020 2:28 pm
Who is online

Users browsing this forum: No registered users and 7 guests