Developer forum

Forum » Development » OrderTemplateExtender issue with template tags and rendering

OrderTemplateExtender issue with template tags and rendering

Remi Muller
Reply
  Hi Guys,
FYI this a follow up on thread: http://developer.dynamicweb-cms.com/forum.aspx?PID=48&ThreadID=27975

Since Version: 19.2.5.2 the behavior of the OrderTemplateExtender is somewhat broken. Let me explain.

public override void ExtendTemplate(Dynamicweb.Templatev2.Template template, TemplateExtenderRenderingState renderingState)
{
if (renderingState == TemplateExtenderRenderingState.Before)
{
if (this.OrderLine.Quantity > 10)
{
this.OrderLine.Quantity = 9;
this.OrderLine.Save();

Dynamicweb.eCommerce.Frontend.Cart.CartCatch.SaveCart();

template.SetTag("Ecom:Order.CartQuantityMaxed", "Max nr of products is reached");
}
}
}


What happens now:
- the max on the orderline is stil working fine
- The template tag is not rendered anymore

I think this is cause by the "Render twice template issue".(see note "Render twice - a bug?" of Morten, http://developer.dynamicweb-cms.com/forum.aspx?PID=48&ThreadID=27975)
When debugging you will see:
- 1st PageTemplateExtender is rendered
- 2nd time the "Cart template" is rendered.

I am able to fix this if the code is only executed when template tag Ecom:Order.CartQuantityMaxed exists.
public override void ExtendTemplate(Dynamicweb.Templatev2.Template template, TemplateExtenderRenderingState renderingState)
{
if (template.Html.Contains("Ecom:Order.CartQuantityMaxed") && renderingState == TemplateExtenderRenderingState.Before)
{
if (this.OrderLine.Quantity > 10)
{
this.OrderLine.Quantity = 9;
this.OrderLine.Save();

Dynamicweb.eCommerce.Frontend.Cart.CartCatch.SaveCart();

template.SetTag("Ecom:Order.CartQuantityMaxed", "Max nr of products is reached");
}
}
}

Please note that i am forced to use "template.Html.Contains" instead of template.TagExists.
This is a bug right?
If you debug:
- 1st PageTemplateExtender is rendered
- 2nd time the "Cart template" is rendered: This when the template object Tags collection is empty.
Can someone get this fixed?

And please investigate/evaluate if there are other possible issues with this case.
- for example when setting a template tag when the PageTemplateExtender is rendered should this tag be available in the "Cart template"?

Kind regards,
Remi

Replies

 

You must be logged in to post in the forum