Developer forum

Forum » Development » Manual discount on last page of checkout

Manual discount on last page of checkout

Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hi there,

I am building a custom discount provider that a Sales rep can use to enter a custom discount value and then click Add (which posts back the cart form). My provider then grabs a field from the form, converts it to a number and then adds an order line with the discount value. The issue I am having is that the UI for this happens on the last page of the checkout. and the order is then completed automatically. What I like instead is for the checkout to remain on the same page. I tried manually setting StepNum on the order but that doesn't seem to work. I now have the following that uses redirects to handle this:

 

public override void ProcessOrder(Order order)
{
  if (!UserHelper.GetCurrentUser().IsInSalesGroup())
  {
    return;
  }
  var needsRedirect = true;
  var value = GetValueFromForm();

  if (value == null)
  {
    needsRedirect = false;
    value = GetValueFromOrder(order);
  }
  if (value != null && value > 0)
  {
    AddDiscountOrderLine(order, value.Value);
  }
  if (needsRedirect)
  {
    HttpContext.Current.Response.Redirect(HttpContext.Current.Request.Url.ToString(), true);
  }
}

 

This tries to get the value from the form. If it exists, it adds the order value and then performs a redirect to self. It also stores the value on the order for later use. If it doesn't exist, I get it from the order instead (where it was stored previously) and don't redirect (as this happens on the reload of the page or at a later stage).

I am thinking to store the value in session instead of on the order, but the main concept should remain the same.

 

Does this approach make sense? Any downsides or improvements that you could think of?

 

Thanks,

Imar


Replies

 

You must be logged in to post in the forum