Inhalte aufrufen

Profilbild

Add new Checkout Step

Checkout

  • Bitte melden Sie sich an, um eine Antwort zu verfassen.
3 Antworten zu diesem Thema

#1 llegrand

llegrand

    Newbie

  • Members
  • Punkt
  • 5 Beiträge

Geschrieben: 31 May 2018 - 14:57

Hi,

 

I try to implement a new Checkout step "Dimensions", between "PaymentMethod" and "Confirm" steps.

 

I implemented views and models, and modified the CheckoutController.

 

In the CheckoutControler, I add 2 Methods "Dimensions" and "SelectDimentions" (based on "PaymentMethod" and "SelectPaymentMethod").

public ActionResult Dimensions()
{
	CheckoutDimensionsModel model = new CheckoutDimensionsModel();
	return View(model);
}

[HttpPost, ActionName("Dimensions")]
[FormValueRequired("nextstep")]
public ActionResult SelectDimensions(CheckoutDimensionsModel model)
{
	if (ModelState.IsValid)
	{
		return RedirectToAction("Confirm");
	}

	//If we got this far, something failed, redisplay form
	return View(model);
	
}

The new step is present when I try to order a Product, the "Next" button works fine and calls well the SelectDimensions method.

But in the SelectDimensions method, the model (received as parameter) seems to be empty (the constructor is called just before).

 

Testing steps for Dimensions :

- Display web page in browser

- Hits VisualStudio breakpoint on "Dimensions()" in CheckoutController, which calls CheckoutDimensionsModel constructor

- Enter some value and click "Next" on web page

- Hits VisualStudio breakpoint on "SelectDimensions(CheckoutDimensionsModel model)" in CheckoutController, which calls CheckoutDimensionsModel constructor
- The model in "SelectDimensions(CheckoutDimensionsModel model)" contains nothing

 

When analysing the way it works with the similar step PaymentMethod, it seems the constructor of the Model is also called, but right after, the model recover values entered in the view.

The only difference between this is that SmartModelBinder.BindModel is called from out of hell !

 

 

Testing steps for ShippingAddress :

- Display web page in browser

- Hits VisualStudio breakpoint on "ShippingAddress()" in CheckoutController, which calls CheckoutShippingAddressModel constructor

- Enter some value and click "Next" on web page

- Hits VisualStudio breakpoint on "NewShippingAddress(CheckoutShippingAddressModel model)" in CheckoutController, which calls CheckoutShippingAddressModel constructor

- Hits VisualStudio breakpoint on "BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)" in SmartModelBinder, which seems to properly initialize entered values
- The model in "NewShippingAddress(CheckoutShippingAddressModel model)" contains entered values

 

Not easy to discribe this, and really not easy to understand why it doesn't works.

Some help will be gracefull.



#2 Marcus Gesing

Marcus Gesing

    SmartStore AG

  • Administrators
  • 3801 Beiträge

Geschrieben: 01 June 2018 - 10:32

Add a "FormCollection form" parameter to SelectDimensions and check whether it contains name-value pairs for your view model properties.
If not, check your view and compare it with PaymentMethod.cshtml with regard to "#nextstep logic" (see line 96 and 98).
 
I do not recommend to change CheckoutController for this task. It's better to use a widget or an action filter for it.

Marcus Gesing

Smartstore AG


#3 llegrand

llegrand

    Newbie

  • Members
  • Punkt
  • 5 Beiträge

Geschrieben: 01 June 2018 - 14:04

FormCollection contains key-value pairs... but not my model.

 

I know I should use widgets... I should spend some time to make it properly. ;)

 



#4 llegrand

llegrand

    Newbie

  • Members
  • Punkt
  • 5 Beiträge

Geschrieben: 01 June 2018 - 14:32

Found it ! :rolleyes:

 

Model binding was wrong due to use of a List as property and wrong HtmlFieldPrefix  for this list in the View.

 

HtmlFieldPrefix should be "Dimensions[" + index + "]" to be properly binded to "Dimensions" list of my Model.

 

Thanks for your help, FormCollection gives me the right way to understand my mistake.




Auch markiert mit einem oder mehrerer dieser Schlüsselwörter: Checkout