How to use Register logic for Custom Checkout Model ?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
5 年 前
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.
5 年 前
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
5 年 前
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...
5 年 前
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 topic was automatically closed 365 days after the last reply. New replies are no longer allowed.