How to use Register logic for Custom Checkout Model ?

Posted: March 12, 2019 at 9:18 PM Quote #224953
Is it possible to extend/override some class like RegisterModel , in a different class CheckoutModel , so form for user to input would be in different place, not http://localhost/register but in http://localhost/onepagecheckout.
But the logic behind it should be calculated in RegisterModel class !


If something like that is already implemented somewhere , where do i look ?

I stuck on
 
        [CheckAccessPublicStore(true)]
        public virtual IActionResult Register(RegisterModel model, string returnUrl, bool captchaValid)
        {
        }
// thats the logic i want to use

But from Checkout Page, should i make a an Ajax post to http://localhost/register/ with data that i formed in my custom register form(inside checkout page), otherwise i can't seems to use IActionResult Register , as it invokes when corresponded url is being set. And if the result in ajax has redirect url to RegisterResult , i can pass it on my form ?

I hope i explained it clear.
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: March 13, 2019 at 12:30 PM Quote #225000
kingdocum wrote:
Is it possible to extend/override some class like RegisterModel , in a different class CheckoutModel , so form for user to input would be in different place, not http://localhost/register but in http://localhost/onepagecheckout.
But the logic behind it should be calculated in RegisterModel class !


If something like that is already implemented somewhere , where do i look ?

I stuck on
 
        [CheckAccessPublicStore(true)]
        public virtual IActionResult Register(RegisterModel model, string returnUrl, bool captchaValid)
        {
        }
// thats the logic i want to use

But from Checkout Page, should i make a an Ajax post to http://localhost/register/ with data that i formed in my custom register form(inside checkout page), otherwise i can't seems to use IActionResult Register , as it invokes when corresponded url is being set. And if the result in ajax has redirect url to RegisterResult , i can pass it on my form ?

I hope i explained it clear.


I am assuming you try to do it from plugin. You can create a model inherited from Register Model like

 public partial class ExtendedRegisterModel : RegisterModel


Then change your model factory and controller to ExtendedRegisterModel, add new items to your model factory and change the model on your view as ExtendedRegisterModel
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Dia [email protected]

Please vote for my comment if it is helpful for you.
Posted: March 13, 2019 at 1:13 PM Quote #225001
dianoche wrote:
Is it possible to extend/override some class like RegisterModel , in a different class CheckoutModel , so form for user to input would be in different place, not http://localhost/register but in http://localhost/onepagecheckout.
But the logic behind it should be calculated in RegisterModel class !


If something like that is already implemented somewhere , where do i look ?

I stuck on
 
        [CheckAccessPublicStore(true)]
        public virtual IActionResult Register(RegisterModel model, string returnUrl, bool captchaValid)
        {
        }
// thats the logic i want to use

But from Checkout Page, should i make a an Ajax post to http://localhost/register/ with data that i formed in my custom register form(inside checkout page), otherwise i can't seems to use IActionResult Register , as it invokes when corresponded url is being set. And if the result in ajax has redirect url to RegisterResult , i can pass it on my form ?

I hope i explained it clear.

I am assuming you try to do it from plugin. You can create a model inherited from Register Model like

 public partial class ExtendedRegisterModel : RegisterModel


Then change your model factory and controller to ExtendedRegisterModel, add new items to your model factory and change the model on your view as ExtendedRegisterModel

Thank you, and i'm not doing it from the plugin, the idea here is to create new forms inside One Page Checkout model/page like so - .


That's inside Views\Checkout\OnePageCheckout.cshtml
form asp-route="Register" asp-route-returnurl="@Url.RouteUrl("Register")" method="post" id="register-form">
                            <input asp-for="FirstName" />
                            <nop-required />
                            <span asp-validation-for="FirstName"></span>
                            <input asp-for="LastName" />
                            <nop-required />
                            <span asp-validation-for="LastName"></span>
                            <div class="inputs">
                                <label asp-for="Email" asp-postfix=":"></label>
                                <input asp-for="Email" />
                                <nop-required />
                                <span asp-validation-for="Email"></span>
                            </div>

                            <input asp-for="Password" />

                            <input asp-for="ConfirmPassword" />
                            <input type="submit" id="register-button" class="button-1 register-next-step-button" value="@T("Account.Register.Button")" name="register-button" />

                        </form>


And i was actually able to use, it send the data to the CustomerController
        public virtual IActionResult Register(RegisterModel model, string returnUrl, bool captchaValid)


But it also redirect me to the register page, if i alter that and redirect back to checkout, i don't receive the ModelState Dictionary error's for checkoutpage if they are.

I was actually thinking to use ajax redirect, but i don't know how to pass the form to
public virtual IActionResult Register(RegisterModel model

And i'm not sure if ajax response would be set with the ModelState Dictionary Data, for handling errors.

Damn seems i'm stuck...
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: March 14, 2019 at 10:32 AM Quote #225061
Then you can add items to your customer entity, register model and update PrepareRegisterModel in Customer Model factory and update your view or alternatively you can create another entity and model and return both of the models in your view as @model Tuple<Model1, Model2> , make sure you add tuplel heplers in your controller and return to view as tuple as well.
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Dia [email protected]

Please vote for my comment if it is helpful for you.
Premium support services
  • Dedicated premium support services provided by core developers are intended for persons who run mission critical websites, work on projects with tight deadlines, or want to get dedicated support.
Professional services
  • Want to open a new store? Want to take your store to the next level? Need a custom extension? We can customize nopCommerce to fit your store perfectly. Request a quote to get started.