Developer forum

Forum » Templates » TemplateTags() breaks the page

TemplateTags() breaks the page

Bjørn Kamfjord
Reply

Hey. The issue, when I try too put an @TemplateTags() in a product loop, it breaks the page, returning an ServerError page. With no templatetags the page works fine.

Ive tried putting the Template tag all over the template, it breaks no matter how i implement it, but if I put it in another template, as the Master.cshtml, all is well.

When I say the page works fine, that is not entirely true, since the VariantCombinations loop does not render, but the VariantGroup loop does...

The code:

@inherits Dynamicweb.Rendering.RazorTemplateBase<Dynamicweb.Rendering.RazorTemplateModel<Dynamicweb.Rendering.Template>>

@using CustomCode.Functions;

@MasterPageFile("Paragraph.cshtml")

@{
    var maxSize = 28;

    var userName = GetGlobalValue("Global:Extranet.UserName");
    var cartPageID = GetGlobalValue("Global:eCommerce.CartPageID");

    var productCatalogPageID = Ecom.GetPageIdByLink(Pageview.Area.Item["ProductCatalogPage"].ToString());
    var myPageID = Ecom.GetPageIdByLink(Pageview.Area.Item["MyPage"].ToString());

    var title = GetString("Item.Title");
    var products = GetLoop("Item.Products");

    var allowWishList = (bool)Pageview.Area.Item["AllowWishList"];
    var allowProductCompare = (bool)Pageview.Area.Item["AllowProductCompare"];
}

<h2 class="tt_uppercase m_bottom_10 color_dark heading1 animate_ftr t_xs_align_c">@title</h2>
@if (productCatalogPageID == 0)
{
<div class="alert_box r_corners warning m_bottom_15">
    <i class="fa fa-exclamation-circle"></i>
    @Translate("FeaturedProducts.NoProductCatalogPageID", "You need to define a 'Product Catalog Page ID' in admin.")
</div>
}
@if (myPageID == 0)
{
<div class="alert_box r_corners warning m_bottom_15">
    <i class="fa fa-exclamation-circle"></i>
    @Translate("FeaturedProducts.NoMyPageID", "You need to define a 'My Page ID' in admin.")
</div>
}
@if (products != null && products.Count > 0)
{

<section class="products_container category_grid">
    @*@if (productCatalogPageID == 0)
        {
            <div class="alert_box r_corners warning m_bottom_15" style="padding:2px 10px 1px 10px;">@Translate("FeaturedProducts.NoProductCatalogPageID", "You need to define a 'Product Catalog Page ID' in admin.")</div>
        }
        @if (myPageID == 0)
        {
            <div class="alert_box r_corners warning m_bottom_15" style="padding:2px 10px 1px 10px;">@Translate("FeaturedProducts.NoMyPageID", "You need to define a 'My Page ID' in admin.")</div>
        }*@
    @foreach (LoopItem i in products)
    {
    var id = i.GetString("Ecom:Product.ID");
    var number = i.GetString("Ecom:Product.Number");
    var name = i.GetString("Ecom:Product.Name");
    var imageCustom = i.GetString("Product.ImageCustom");
    var languageID = i.GetString("Ecom:Product.LanguageID");
    //var price = i.GetString("Ecom:Product.Price");
    var compareID = i.GetString("Ecom:Product.CompareID");
    var linkGroupClean = i.GetString("Ecom:Product.LinkGroup.Clean");
    var dbPrice = i.GetDouble("Ecom:Product.DBPrice");
    var salesPrice = dbPrice;
    var wishListPageID = Ecom.GetPageIdByLink(Pageview.Area.Item["WishList"].ToString());

    var variantCount = i.GetInteger("Ecom:Product.VariantCount");
    var variantGroups = i.GetLoop("VariantGroups");

    var allowBuy = i.GetBoolean("Product.AllowBuy");
    var isInCart = i.GetBoolean("Ecom:Product.IsInCart");

    var productLink = string.Format("/Default.aspx?ID={0}&ProductID={1}", productCatalogPageID, id);

    var popup = string.Format("#{0}_popup", ((!string.IsNullOrEmpty(userName)) ? "blank" : "login"));
    var url = string.Format("/Default.aspx?id={0}&ProductID={1}&LanguageID={2}", wishListPageID, id, languageID);
    var addCompare = string.Format("add_compare_{0}", compareID.Replace("$", "_"));
    var removeCompare = string.Format("remove_compare_{0}", compareID.Replace("$", "_"));


    <div class="product_item w_xs_full no-transition @(isInCart ? "in_cart" : string.Empty)" data-productno="@number">
      @i.TemplateTags()
      <figure class="r_corners photoframe type_2 t_align_c tr_all_hover shadow relative">
            <a class="d_block relative wrapper pp_wrap m_bottom_15" href='@productLink' style="height:150px; text-align:center; line-height:150px;">
                <img style="margin:auto; vertical-align:middle;" src='@Ecom.GetImage(imageCustom, height:250, width:250, placeholderText:Translate("Ecom.NoImage", "No image"), placeholderTextSize: 30)' class="tr_all_hover" alt="@name" />
            </a>
            <figcaption>
                <p style="text-transform:uppercase; font-size:11px;">@Translate("Ecom.ProductNumber"): @id</p>
                <h5 class="m_bottom_10" title='@name' style="height:34px;">
                    <a href='@productLink'>@Ecom.Wrap(name, 50)</a>
                </h5>
                <div class="clearfix">
                    <div class="f_left" style="width:50%; text-align:right;">
                        <div style="text-transform:uppercase; font-size:11px; margin:4px 30px 0 0;">@Translate("Ecom.SalesPrice")</div>
                    </div>
                    <div class="f_size_large f_right m_bottom_15 t_align_r" style="width:50%;">
                        <b>@salesPrice.ToString("C")</b>
                    </div>
                </div>
                <!-- VARIANTER -->
                @if (variantCount > 0)
                {
                <div class="variants my-3 clearfix">
                    @foreach (LoopItem vg in variantGroups)
                    {
                    <label class="variant-select-label f_left m-2">@vg.GetString("Ecom:VariantGroup.Label")</label>
                    <select id="SelectVariantId" class="form-control js-variant-select mx-2 @((vg.GetString("Ecom:VariantGroup.ID") ==  "FRG") ? "js-variant-color" : string.Empty) ">

                        @foreach (LoopItem vao in vg.GetLoop("VariantAvailableOptions"))
                        {
                        <option @(vao.GetBoolean("Ecom:VariantOption.Selected") ? "selected" : string.Empty) value="@vao.GetString("Ecom:VariantOption.ID")">@vao.GetString("Ecom:VariantOption.Name")</option>
                        }

                    </select>

                    }

                </div>
            
                foreach (LoopItem vc in i.GetLoop("VariantCombinations"))
                {
                <table class="js-variant-price collapse description_table mx-2 width-100" id='@vc.GetValue("Ecom:VariantCombination.VariantID")'>
                    <tr class="m_top_5">
                        <td style="text-transform:uppercase;">@Translate("Ecom.ListIncl")</td>
                        <td class="f_size_large m_bottom_15 t_align_r"><span class="">@salesPrice.ToString("C")</span></td>
                    </tr>

                    <tr class="t_align_r NetPrice">
                        <td>@Translate("Ecom:Price"): </td>
                        <td>@vc.GetString("Ecom:Product.Price.PriceWithoutVATFormatted")</td>
                    </tr>
                    <tr class="t_align_r">
                        <td>@Translate("Ecom:Stock"): </td>
                        <td>@vc.GetDouble("Ecom:VariantCombination.Product.Stock")</td>
                    </tr>
                    <tr class="t_align_r">
                        <td class="t_align_r" align="right" colspan="2">
                            <form method="post" role="form">
                                <input type="hidden" name="ID" value="@i.GetValue("Ecom:Product:Page.ID")" />
                                <input te="hidden" name="ProductID" value="@i.GetValue("Ecom:Product.ID")" />
                                <input type="hidden" name="VariantID" value="@vc.GetValue("Ecom:VariantCombination.VariantID")" />
                                <input type="number" name="Quantity" value="1" style="width:67px;" />
                                <input type="hidden" name="CartCmd" value="add" />
                                <button type="submit" style="height:37px;" class="button_type_4 bg_scheme_color r_corners tr_all_hover color_light mw_0">@Translate("Ecom:AddToBakset")</button>
                            </form>
                        </td>
                    </tr>
                </table>
                }
                }

                <!-- Varianter slutt-->
                @if (allowBuy && variantCount == 0)
                {
                <div class="clearfix">
                    <input type="text" class="r_corners type_2 t_align_c add_to_basket_quantity @(!isInCart ? string.Empty : "debug")" style="width:50px; height:34px;" value="1" data-productno="@id" />

                    <button onclick="BlockUI(); window.location.href = '/Default.aspx?ID=@cartPageID'; return false;" class="button_type_4 bg_light_color_1 r_corners tr_all_hover color_dark mw_0 m_bottom_15 added_to_basket @(isInCart ? string.Empty : "debug")" data-productno="@id"><i style="font-size:16px;" class="fa fa-check"></i> @Translate("Ecom.AddedToCart")</button>
                    <button style="height:31px;" class="button_type_4 bg_scheme_color r_corners tr_all_hover color_light mw_0 m_bottom_15 add_to_basket @(isInCart ? "debug" : string.Empty)" data-productno="@id">@Translate("Ecom.AddToCart")</button>
                </div>
                }
                <div class="clearfix m_bottom_5">
                    <ul class="horizontal_list d_inline_b l_width_divider">
                        @if (allowWishList == true)
                        {
                        <li title="" class="m_right_15 m_md_right_0 tooltip_container" data-popup="#blank_popup" data-url='@url'><a class="color_dark" href=""><i class="fa fa-heart-o m_right_5"></i> @Translate("Ecom.AddToWishlist")</a><span class="tooltip_type_2 bottom tr_all_hover r_corners f_size_small color_dark d_block">@Translate("Ecom.AddToWishList.Tooltip")</span><span class="d_mxs_none">&nbsp;&nbsp;|&nbsp;&nbsp;</span></li>
                        }
                        @if (allowProductCompare == true)
                        {
                        <li title="" class="@addCompare tooltip_container" style="margin:0;"><a class="color_dark" href="javascript:Compare.add('@compareID', '@name', '@linkGroupClean')"><i class="fa fa-files-o m_right_5"></i> @Translate("Ecom.AddToCompare")</a><span class="tooltip_type_2 bottom tr_all_hover r_corners f_size_small color_dark d_block">@Translate("Ecom.AddToCompare.Tooltip")</span></li>
                        <li title="" class="@removeCompare tooltip_container" style="display:none; margin:0;"><a href="javascript:Compare.remove('@compareID', true)"><i class="fa fa-files-o m_right_5"></i> @Translate("Ecom.Compare.Remove")</a><span class="tooltip_type_2 bottom tr_all_hover r_corners f_size_small color_dark d_block">@Translate("Ecom.RemoveFromCompare.Tooltip")</span></li>
                        }
                    </ul>
                </div>
            </figcaption>
        </figure>
    </div>
    }
</section>
}
else
{
<div class="alert_box r_corners info m_bottom_15">
    <i class="fa fa-info-circle"></i>
    @Translate("FeaturedProducts.NoProducts", "No products")
</div>
}

 

 

FeaturedProducts_Error.png FeaturedProducts_Item_Type.png FeaturedProducts_setup.png

Replies

 
Nicolai Pedersen
Reply

Uh - a nice Norwegian exception :-).

It could be related to the product with no product ID/number that you have in your list of products on the item "Et produkt". It seems to be rendering of the price that causes the exception and it could be related to 'bad' data (almost sure it is). Try removing it...

I guess you imported data for this?

If removing the product does not work, try creating a new product using the UI, and select that in the item - just to test.

I need to find out what the bad data is in order to fix the code that gives exception.

Sorry about the inconvenience, Nicolai

 
Bjørn Kamfjord
Reply

Yes this a lovely Norwegian code mashup! :O

hmmm, removing the products and creating a new product, it works fine. The problem occurs the moment I try to add prices to the variants..

Product_ERROR.png Product_Setup.png Works.png
 
Nicolai Pedersen
Reply

Hi Bjørn

Thanks - so as soon as you add a price to the price table, it crashes?

Nicolai

 
Bjørn Kamfjord
Reply

Jepp! It does, and in my shop, all products have variants... (the above example is from my local dev, but same thing occurs on live site).

 
Nicolai Pedersen
Reply

Ok - a bug.

I've send it for verification and fixing.

BR Nicolai

 

 
Oleg Rodionov Dynamicweb Employee
Oleg Rodionov
Reply

Hi all,

I've tried to test the issue (in line the comment above - "The problem occurs the moment I try to add prices to the variants..) on Rapido 2.0 solution under last DW947 but was not able to catch any issue, all right in my view. Please, find the proofs:

1. When price field cannot be changed across variants - https://www.screencast.com/t/OPZOUKrJbD

2. When price field can be changed across variant - https://www.screencast.com/t/AHlebg5hHgQo

3. Adding new row to price matrix when extended variants exists - https://www.screencast.com/t/NQbdW8PDg

Please, comment if your scenarios do not follow mine. 

BR, Oleg QA

 
Bjørn Kamfjord
Reply

Hmm, I can't really say if the setup is the same or not, since I get all the products from an integration. Also, the products in the regular product catalogue works just fine, the problem is with an itemtype (featured products) that I have on the front page. The site is also hosted on an Azure server, but that should not make difference?

I can send you a link to the actual site for you to have a look?

 
Oleg Rodionov Dynamicweb Employee
Oleg Rodionov
Reply

Hi,

Yes, do it. Please, specify your issue better. As I understood in line with your post above has screens, product price martix has rules uses the product variants is lost on the variant resaving. Please confirm and point a specific product can be tested.

BR, Oleg QA      

 
Bjørn Kamfjord
Reply

the site is https://egwbp-chrisco-test.azurewebsites.net/

The page and Itemtype in question is "Forside" (ID:1) and the paragraph "Utvalgte produkter" (ID:20). The itemtype is under Content  > Paragraphs > Featured Products.

All products I have tried have caused the error.

itemtype.png
 
Oleg Rodionov Dynamicweb Employee
Oleg Rodionov
Reply

Hm...I cannot understand meaning of your issue. You have recently written about some issue related to product price-matrix in product backend during variant re-saving. I cannot catch the issue on the solution during the re-saving with product used in item field, proof.

Please, capture video or describe your scenario in steps to cpecify your issue.

BR, Oleg QA

 
Bjørn Kamfjord
Reply

 No, the error is in the front-end, when I try to put a TemplateTags in the code to list out why the VariantCombinations loop is not working, the entire page breaks!

 
Oleg Rodionov Dynamicweb Employee
Oleg Rodionov
Reply

Hi,

I see the exception on the content. I was not able to add new product on your solution - it's not avialable via UI, limited with license, probably. But I see exception almost the same as yours on my test environment based on last DW947 as well (attachment). It's reproduced for any content has product item field when the tag is enabled and the field (product control) contains at least one product/product variant. I've created new TFS 48425 to fix the bug, will be provided by further DW94 hotfix/release. I hope the fix will solve your issue as well (can be checked after fixing only).

Thanks for observing.

BR, Oleg QA

2018-03-28_0952.png

 

You must be logged in to post in the forum