Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Bjarne Fyrstenborg 1285 posts 4039 karma points MVP 8x c-trib
    Sep 22, 2013 @ 15:29
    Bjarne Fyrstenborg
    0

    Not only Product doctypes in variants dropdown

    I discovered a minor issue in the starterkit, when using other document types under the master product node.

    In this case the variant dropdown also displays other document types in Tea Commerce Starter Kit 3.2.0.

    I my case I have created a "TabPage" documenttype to let the shop owner create additional content in seperate tabs on product pages, e.g. a tab "Benefits". Other tabs like "Specifications", "Images" and "Downloads" I just create from properties on the master product node.

     

    With these code lines in product/view.cshtml a get both nodes in variant dropdown:

    //Product
    string ProductTypeName = "Product";
    DynamicNode currentPage = Model;
    DynamicNode mainProduct = currentPage.AncestorOrSelf( p => p.NodeTypeAlias == ProductTypeName && p.Parent.NodeTypeAlias != ProductTypeName );
    
    //Variants
    List<DynamicNode> variants = mainProduct.Descendants( p => !p.ChildrenAsList.Any( c => c.NodeTypeAlias == ProductTypeName ) ).Items;

    so instead a modified variants a bit and get only the nodes of type Product in the dropdown.. not sure if it's the best way to write the code, but this works..

    //Variants
    List<DynamicNode> variants = mainProduct.Descendants().Items
        .Where(c => c.NodeTypeAlias == ProductTypeName).ToList();

    /Bjarne

  • Anders Burla 2560 posts 8256 karma points
    Sep 23, 2013 @ 09:04
    Anders Burla
    0

    Hi Bjarne

    Thanks!

Please Sign in or register to post replies

Write your reply to:

Draft