Copied to clipboard

Flag this post as spam?

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


These support forums are now closed for new topics and comments.
Please head on over to http://eureka.ucommerce.net/ for support.

  • Kim Hansen 63 posts 144 karma points
    Apr 12, 2013 @ 13:18
    Kim Hansen
    0

    Get all products via XSLT-Extension

    Hi thereI need some help from you guys.Im trying to make an XSLT Extension give me all products in the shop (2.6.1), but im getting an error."Cannot serialize member UCommerce.EntitiesV2.Product.Variants of type System.Collections.Generic.ICollection`1[[UCommerce.EntitiesV2.Product, UCommerce, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] because it is an interface."public string GetAllProducts(){StringBuilder sb = new StringBuilder();List<Product> productList = Product.All().ToList<Product>();XmlWriter xmlWriter = XmlWriter.Create(sb);XmlSerializer serializer = new XmlSerializer(typeof(Product));serializer.Serialize(xmlWriter, productList);xmlWriter.Dispose();return sb.ToString();}

  • Kim Hansen 63 posts 144 karma points
    Apr 12, 2013 @ 13:19
    Kim Hansen
    0

    Hi there

    I need some help from you guys.

    Im trying to make an XSLT Extension give me all products in the shop (2.6.1), but im getting an error.

    "Cannot serialize member UCommerce.EntitiesV2.Product.Variants of type System.Collections.Generic.ICollection`1[[UCommerce.EntitiesV2.Product, UCommerce, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] because it is an interface."

    public string GetAllProducts()
    {
    StringBuilder sb = new StringBuilder();
    List<Product> productList = Product.All().ToList<Product>();
    XmlWriter xmlWriter = XmlWriter.Create(sb);
    XmlSerializer serializer = new XmlSerializer(typeof(Product));
    serializer.Serialize(xmlWriter, productList);
    xmlWriter.Dispose();
    return sb.ToString();
    }

  • Søren Spelling Lund 1797 posts 2786 karma points
    Apr 12, 2013 @ 14:22
    Søren Spelling Lund
    100

    It's a limitation inherent in the .NET XmlSerializer. You can use the built-in XML renderers that ship out of the box with uCommerce.

    The one for converting a product to XML is called ProductRenderer and lives in the UCommerce.Xslt namespace.

    Why aren't out letting the LINQ API perform the search prior to performing the search? It would make the solution much, much faster as it would only have to deal with a minimum of information.

Please Sign in or register to post replies

Write your reply to:

Draft