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.

  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Apr 06, 2011 @ 12:49
    Jeavon Leopold
    0

    Accessing the Top 10 products

    Anyone know, is it possible to access the top 10 selling products (in the analytics section of uCommerce UI) via the API/Razor or XSLT?

    Thanks,

    Jeavon

  • Christian Wendler 46 posts 155 karma points
    Apr 06, 2011 @ 14:47
    Christian Wendler
    0

    Sure, this is possible. The UI uses a SQL stored procedure, you can call this procedure in your custom XSLT extension class. Here's my way of doing this:

            public static XPathNodeIterator GetTopSellers(int count) {

                try {
                    List<UCommerce.EntitiesV2.Product> products = new List<UCommerce.EntitiesV2.Product>();

                    StoredProcedure procedure = SPs.GetProductTop10();
                    procedure.Command.Parameters.Add("ProductCatalogGroupId", null);

                    DbDataReader dataReader = procedure.ExecuteReader();

                    foreach(var data in dataReader) {
                        count--;
                        if(count < 0)
                            break;

                        string sku = dataReader["SKU"].ToString();
                        string variantSku = dataReader["VariantSKU"].ToString();

                        var product = UCommerce.EntitiesV2.Product.SingleOrDefault(p => p.Sku == sku && p.VariantSku == variantSku);
                        products.Add(product);
                    }

                    ProductRenderer pr = new ProductRenderer();
                    if(products.Count() > 0)
                        return pr.RenderDocument(products, "products").CreateNavigator().Select(".");

                    XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.LoadXml("<products />");
                    return xmlDoc.CreateNavigator().Select(".");

                }
                catch(Exception ex) {
                    XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.LoadXml("<error><message>" + ex.Message + "</message><stack>" + HttpUtility.HtmlEncode(ex.StackTrace) + "</stack></error>");
                    return xmlDoc.CreateNavigator().Select(".");
                }

            }

     

    Best regards

    Christian

  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Apr 08, 2011 @ 13:04
    Jeavon Leopold
    0

    Thanks Christian, this is really useful. We are thinking about starting a uCommerce Contrib project (simular to the Contour Contrib project) so we can collect all of the useful uCommerce extensions into one library, would you be interested in being a contributor? 

    Regards,

    Jeavon

  • wolulcmit 357 posts 693 karma points
    Dec 01, 2011 @ 08:44
    wolulcmit
    0

    does anyone know how to do that same without using SubSonic.Schema; now that it's no longer shipped in ucommerce 2.0?
    trying to modify the uCommerceContrib source myself but not having much luck

    I have the following

    SPs procedure = new SPs();
    var top10 = procedure.GetProductTop10();
     
    //how then to pass the right info to the datareader object?

    a bit out of my depth really

    thanks for any help.

    - Tim

Please Sign in or register to post replies

Write your reply to:

Draft