Exemple #1
0
        private static ProductInfoCatalog_V01 LoadProductInfoFromService(string locale)
        {
            if (string.IsNullOrEmpty(locale))
            {
                return(null);
            }

            ProductInfoCatalog_V01 productInfo = null;

            using (var proxy = ServiceClientProvider.GetCatalogServiceProxy())
            {
                try
                {
                    var request  = new GetProductInfoRequest_V01(Settings.GetRequiredAppSetting("DWSCatalogPlatformKey", "dws_default"), locale);
                    var response = proxy.GetProductInfo(new GetProductInfoRequest1(request)).GetProductInfoResult as GetProductInfoResponse_V01;

                    if (response == null || response.Status != ServiceResponseStatusType.Success ||
                        response.ProductCatalog == null)
                    {
                        throw new ApplicationException(
                                  "CatalogProvider.LoadProductInfoFromService error. GetProductInfoResponse indicates error. Locale : " +
                                  locale);
                    }

                    productInfo = response.ProductCatalog;
                }
                catch (Exception ex)
                {
                    LoggerHelper.Error(string.Format("LoadProductInfoFromService error, locale: {0} {1}", locale, ex));
                }
            }

            return(productInfo);
        }
        /// <summary>
        ///     The get category from product.
        /// </summary>
        /// <param name="product">
        ///     The product.
        /// </param>
        /// <param name="productInfoCatalog">
        ///     The product info catalog.
        /// </param>
        /// <returns>
        /// </returns>
        public static Category_V02 GetCategoryFromProduct(ProductInfo_V02 product,
                                                          ProductInfoCatalog_V01 productInfoCatalog)
        {
            var varProd = from a in productInfoCatalog.AllCategories.Values
                          from p in a.Products
                          where p != null && p.ID == product.ID
                          select a;

            return(varProd.Count() > 0 ? varProd.First() : null);
        }
        //[TestMethod]
        //public void TestCartWithVirtualSku()
        //{

        //    // 0 == will iclude 9909 vitual sku
        //    var shoppingCartList = GetShopingCartList(0);
        //    var invalidCart = GetUnfilteredCart(shoppingCartList);
        //    var target = GetTarget(invalidCart,GetProductInfoCatalogMock(0));
        //    var shoppingCartTestObject = shoppingCartList.FirstOrDefault();
        //    if (shoppingCartTestObject != null)
        //    {
        //        var result = target.GetDiscontinuededSku(shoppingCartTestObject.ShoppingCartID, shoppingCartTestObject.DistributorID, shoppingCartTestObject.Locale,0,null);
        //        Assert.IsNotNull(result);
        //    }

        //}

        //[TestMethod]
        //public void TestNormalSkuOrder()
        //{
        //   // will only generate normal sku 1316
        //    var shoppingCartList = GetShopingCartList(1);
        //    var invalidCart = GetUnfilteredCart(shoppingCartList);
        //    var target = GetTarget(invalidCart, GetProductInfoCatalogMock(0));
        //    var shoppingCartTestObject = shoppingCartList.FirstOrDefault();
        //    if (shoppingCartTestObject != null)
        //    {
        //        var result = target.GetDiscontinuededSku(shoppingCartTestObject.ShoppingCartID, shoppingCartTestObject.DistributorID, shoppingCartTestObject.Locale, 0, null);
        //        Assert.IsNotNull(result);
        //        Assert.AreEqual(0,result.Count);
        //    }
        //}

        //[TestMethod]
        //public void TestDiscContinueSku()
        //{
        //    // will only generate normal sku 1316
        //    var shoppingCartList = GetShopingCartList(1);
        //    var invalidCart = GetUnfilteredCart(shoppingCartList);
        //    var target = GetTarget(invalidCart, GetProductInfoCatalogMock(1));
        //    var shoppingCartTestObject = shoppingCartList.FirstOrDefault();
        //    if (shoppingCartTestObject != null)
        //    {
        //        var result = target.GetDiscontinuededSku(shoppingCartTestObject.ShoppingCartID, shoppingCartTestObject.DistributorID, shoppingCartTestObject.Locale, 0, null);
        //        Assert.IsNotNull(result);
        //        Assert.AreEqual(1, result.Count);
        //    }
        //}

        //[TestMethod]
        //public void TestPromoSku()
        //{
        //    // will only generate normal sku 1316
        //    var shoppingCartList = GetShopingCartList(3);
        //    var invalidCart = GetUnfilteredCart(shoppingCartList);
        //    var target = GetTarget(invalidCart, GetProductInfoCatalogMock(1));
        //    var shoppingCartTestObject = shoppingCartList.FirstOrDefault();
        //    if (shoppingCartTestObject != null)
        //    {
        //        var result = target.GetDiscontinuededSku(shoppingCartTestObject.ShoppingCartID, shoppingCartTestObject.DistributorID, shoppingCartTestObject.Locale, 0, null);
        //        Assert.IsNotNull(result);
        //        Assert.AreEqual(1, result.Count);
        //    }
        //}

        //public ShoppingCartProviderLoader GetTarget(ICatalogInterface invalidCart, ProductInfoCatalog_V01 allSku)
        //{
        //    var proxy = Substitute.For<ICatalogProviderLoader>();
        //    proxy.GetProductInfoCatalog("zh-CN")
        //        .Returns(new ProductInfoCatalog_V01()
        //        {
        //            Locale = "zh-CN",
        //            AllCategories = allSku.AllCategories,
        //            AllSKUs = allSku.AllSKUs
        //        });
        //    var target = new ShoppingCartProviderLoader(proxy,invalidCart);
        //    return target;
        //}

        private ProductInfoCatalog_V01 GetProductInfoCatalogMock(int mode)
        {
            ProductInfoCatalog_V01 allSku = new ProductInfoCatalog_V01()
            {
                Platform = "MyHL", Locale = "zh-CN"
            };

            allSku.AllSKUs       = GetMockAllSku(mode);
            allSku.AllCategories = GetAllCategories();
            return(allSku);
        }
Exemple #4
0
        /// <summary>
        /// The find category.
        /// </summary>
        /// <param name="ProductInfoCatalog"></param>
        /// <param name="categoryID">
        /// The category id.
        /// </param>
        /// <returns>
        /// </returns>
        public static Category_V02 FindCategory(ProductInfoCatalog_V01 ProductInfoCatalog, int categoryID)
        {
            Category_V02 category;

            if (ProductInfoCatalog.AllCategories.TryGetValue(categoryID, out category))
            {
                return(category);
            }

            return(null);
        }
Exemple #5
0
        /// <summary>
        /// The find category.
        /// </summary>
        /// <param name="productInfoCatalog"></param>
        /// <param name="categoryID"></param>
        /// <param name="ParentCategoryID"> The category id. </param>
        /// <returns>
        /// </returns>
        /// <param name="rootCategoryID"></param>
        public static Category_V02 FindCategory(ProductInfoCatalog_V01 productInfoCatalog, int categoryID, int ParentCategoryID, int rootCategoryID)
        {
            var varRootCategories = productInfoCatalog.RootCategories.Where(r => r.ID == rootCategoryID);

            if (varRootCategories.Count() > 0)
            {
                Category_V02 rootCategory = varRootCategories.First();
                return(CatalogHelper.findCategory(categoryID, ParentCategoryID, rootCategory));
            }

            return(null);
        }
Exemple #6
0
        /// <summary>
        /// The get product.
        /// </summary>
        /// <param name="categoryID">
        /// The category id.
        /// </param>
        /// <param name="productID">
        /// The product id.
        /// </param>
        /// <returns>
        /// </returns>
        public static ProductInfo_V02 getProduct(ProductInfoCatalog_V01 ProductInfoCatalog, int categoryID, int productID)
        {
            Category_V02 category;

            if (ProductInfoCatalog.AllCategories.TryGetValue(categoryID, out category))
            {
                IEnumerable <ProductInfo_V02> varProd = category.Products.Where(p => p.ID == productID);
                return(varProd.Count() > 0 ? varProd.First() : null);
            }

            return(null);
        }
Exemple #7
0
        public static Category_V02 GetRootCategory(ProductInfoCatalog_V01 productInfoCatalog, int categoryID)
        {
            foreach (Category_V02 cat in productInfoCatalog.RootCategories)
            {
                Category_V02 categoryToFind = findCategoryByID(categoryID, cat);
                if (categoryToFind != null)
                {
                    return(cat);
                }
            }

            return(null);
        }
        /// <summary>
        ///     The check product availability.
        /// </summary>
        /// <param name="showAllInventory">
        ///     The show all inventory.
        /// </param>
        /// <param name="itemList">
        ///     The item list.
        /// </param>
        private void checkProductAvailability(bool showAllInventory, List <UIProductInfo> itemList)
        {
            // ListView Products
            if (!showAllInventory)
            {
                ProductInfoCatalog_V01 ProductInfoCatalog = ProductsBase.ProductInfoCatalog;
                foreach (ListViewDataItem listItem in Products.Items)
                {
                    var hdProductID = listItem.FindControl("ProductID") as HiddenField;
                    var hdCatID     = listItem.FindControl("CatID") as HiddenField;
                    if (hdProductID != null && hdCatID != null)
                    {
                        string prodID = hdProductID.Value;
                        string catID  = hdCatID.Value;

                        ProductInfo_V02 product = CatalogHelper.getProduct(ProductInfoCatalog, int.Parse(catID),
                                                                           int.Parse(prodID));

                        IEnumerable <SKU_V01> hasStock = from l in product.SKUs
                                                         from s in AllSKUS.Keys
                                                         where
                                                         l.SKU == s &&
                                                         AllSKUS[s].ProductAvailability !=
                                                         ProductAvailabilityType.Unavailable
                                                         select l;
                        //var lbOutofstock = listItem.FindControl("lbOutofstock") as Label;
                        //if (lbOutofstock != null)
                        //{
                        //    lbOutofstock.Visible = hasStock.Count() == 0;
                        //}
                        var td = listItem.FindControl("tdProduct") as HtmlTableCell;
                        if (td != null)
                        {
                            td.Visible = (hasStock != null && hasStock.Count() != 0) || showAllInventory;
                        }
                    }
                }
            }
            //else
            //{
            //    foreach (ListViewDataItem listItem in Products.Items)
            //    {
            //        var lbOutofstock = listItem.FindControl("lbOutofstock") as Label;
            //        if (lbOutofstock != null)
            //        {
            //            lbOutofstock.Visible = false;
            //        }
            //    }
            //}
        }
        public void PrintWebControl()
        {
            var ispc = Request.QueryString["IsPC"];
            var stringWrite = new StringWriter();
            var htmlWrite = new HtmlTextWriter(stringWrite);

            var pg = new Page();
            pg.EnableEventValidation = false;
            var frm = new HtmlForm();
            pg.Controls.Add(frm);
            frm.Attributes.Add("runat", "server");

            var currentProduct = Session["CurrentProduct"] as ProductInfo_V02;
            if (currentProduct != null)
            {
                var member = (MembershipUser<DistributorProfileModel>)Membership.GetUser();
                var user = member.Value;
                string locale = CultureInfo.CurrentCulture.Name;
                SessionInfo sessionInfo = SessionInfo.GetSessionInfo(user.Id, locale);


                MyHLShoppingCart shoppingCart = ShoppingCartProvider.GetShoppingCart(user.Id, locale);
                ProductInfoCatalog_V01 ProductInfoCatalog = CatalogProvider.GetProductInfoCatalog(locale, 
                                                                                                  shoppingCart
                                                                                                      .DeliveryInfo !=
                                                                                                  null
                                                                                                      ? shoppingCart
                                                                                                            .DeliveryInfo
                                                                                                            .WarehouseCode
                                                                                                      : HLConfigManager
                                                                                                            .Configurations
                                                                                                            .ShoppingCartConfiguration
                                                                                                            .DefaultWarehouse);

                var ucPrintThisPage =
                    LoadControl("~/Ordering/Controls/PrintThisPageContent.ascx") as PrintThisPageContent;
                ucPrintThisPage.BindProduct(currentProduct, sessionInfo.ShowAllInventory, ProductInfoCatalog.AllSKUs,ispc);
                frm.Controls.Add(ucPrintThisPage);
            }

            pg.DesignerInitialize();
            pg.RenderControl(htmlWrite);

            ClientScript.RegisterStartupScript(GetType(), "PrintThisProduct", stringWrite.ToString());
            ClientScript.RegisterStartupScript(GetType(), "PrintPage", "<script>window.print();</script>");
            ClientScript.RegisterStartupScript(GetType(), "CloseWindow",
                                               "<script>setTimeout('window.close()', 2000);</script>");
        }
Exemple #10
0
 private static void SaveProductInfoCatalogToCache(string cacheKey, ProductInfoCatalog_V01 category)
 {
     HttpRuntime.Cache.Insert(cacheKey, category, null, DateTime.Now.AddMinutes(ProductinfoCacheMinutes),
                              Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, OnCategoryCacheRemove);
 }