Esempio n. 1
0
        /// <summary>
        /// display Promo
        /// </summary>

        private void displayPromo()
        {
            divPromo.Visible = false;
            PromotionInformation         promo;
            List <CatalogItem>           PcPromoOnly = new List <CatalogItem>();
            Dictionary <string, SKU_V01> _AllSKUS    = null;

            if (ShoppingCart != null && ShoppingCart.CartItems.Any())
            {
                if (ShoppingCart.DeliveryInfo == null || string.IsNullOrEmpty(ShoppingCart.DeliveryInfo.WarehouseCode))
                {
                    return;
                }
                if (CatalogProvider.IsPreordering(ShoppingCart.CartItems, ShoppingCart.DeliveryInfo.WarehouseCode))
                {
                    return;
                }
            }
            else
            {
                return;
            }

            var profile = DistributorOrderingProfileProvider.GetProfile(ShoppingCart.DistributorID, ShoppingCart.DeliveryInfo.Address.Address.Country);

            if ((promo =
                     ChinaPromotionProvider.GetPCPromotion(profile.CNCustomorProfileID.ToString(), ShoppingCart.DistributorID)) !=
                null)
            {
                var     totals = ShoppingCart.Totals as MyHerbalife3.Ordering.ServiceProvider.OrderSvc.OrderTotals_V02;
                decimal currentMonthTotalDue = 0;
                if (promo.MonthlyInfo != null)
                {
                    if (promo.MonthlyInfo.Count > 0)
                    {
                        currentMonthTotalDue = promo.MonthlyInfo[0].Amount;
                    }
                }
                if (totals != null && totals.OrderFreight != null && totals.AmountDue + currentMonthTotalDue - totals.OrderFreight.FreightCharge >= promo.promoelement.AmountMinInclude)
                {
                    if (promo.IsEligible)
                    {
                        if (promo.SKUList.Count > 0)
                        {
                            if (ShoppingCart != null && ShoppingCart.CartItems.Count > 0)
                            {
                                if (rblFreeGiftlist.Items.Count > 0)
                                {
                                    rblFreeGiftlist.Items.Clear();
                                }
                                _AllSKUS = (ProductsBase).ProductInfoCatalog.AllSKUs;
                                SKU_V01 sku;
                                foreach (CatalogItem t in promo.SKUList)
                                {
                                    if (_AllSKUS.TryGetValue(t.SKU, out sku))
                                    {
                                        if (!ChinaPromotionProvider.GetPCPromoCode(t.SKU).Trim().Equals("PCPromo"))
                                        {
                                            continue;
                                        }
                                        if ((
                                                ShoppingCartProvider.CheckInventory(t as CatalogItem_V01, 1,
                                                                                    ProductsBase.CurrentWarehouse) > 0 &&
                                                (CatalogProvider.GetProductAvailability(sku,
                                                                                        ProductsBase.CurrentWarehouse) == ProductAvailabilityType.Available)))
                                        {
                                            rblFreeGiftlist.Items.Add(new ListItem(t.Description,
                                                                                   t.SKU));

                                            divPromo.Visible = true;
                                            PcPromoOnly.Add(t);
                                        }
                                    }
                                }
                                if (rblFreeGiftlist.Items.Count > 0)
                                {
                                    rblFreeGiftlist.Items[0].Selected = true;
                                }
                                var myShoppingCart = (Page as ProductsBase).ShoppingCart;

                                var promoInCart =
                                    myShoppingCart.CartItems.Select(c => c.SKU).Intersect(PcPromoOnly.Select(f => f.SKU));
                                if (promoInCart.Any())
                                {
                                    btnAddToCart.Enabled = false;
                                    divPromo.Visible     = false;
                                }
                                else
                                {
                                    btnAddToCart.Enabled = true;
                                }
                                if (ShoppingCart.CartItems.Count == 1)
                                {
                                    if (promoInCart.Any())
                                    {
                                        ShoppingCart.DeleteItemsFromCart(promoInCart.ToList(), true);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        var itemsInBoth =
                            ShoppingCart.CartItems.Where(x => x.IsPromo)
                            .Select(c => c.SKU)
                            .Intersect(promo.SKUList.Select(f => f.SKU));
                        if (itemsInBoth.Any())
                        {
                            ShoppingCart.DeleteItemsFromCart(itemsInBoth.ToList(), true);
                        }
                    }
                }
                else
                {
                    var itemsInBoth =
                        ShoppingCart.CartItems.Where(x => x.IsPromo)
                        .Select(c => c.SKU)
                        .Intersect(promo.SKUList.Select(f => f.SKU));
                    if (itemsInBoth.Any())
                    {
                        ShoppingCart.DeleteItemsFromCart(itemsInBoth.ToList(), true);
                    }
                }
            }
            promotionPanel.Update();
        }
        /// <summary>
        /// display Promo
        /// </summary>

        private void displayPromo()
        {
            divPromo.Visible = false;
            PromotionInformation         promo;
            List <CatalogItem>           PcPromoOnly = new List <CatalogItem>();
            Dictionary <string, SKU_V01> _AllSKUS    = null;

            if ((promo = ChinaPromotionProvider.GetChinaPromotion(DistributorID)) != null)
            {
                var currestsession = SessionInfo.GetSessionInfo(DistributorID, "zh-CN");
                if (currestsession != null && currestsession.ChinaPromoSKUQuantity > 0)
                {
                    if (promo.SKUList.Count > 0)
                    {
                        if (ShoppingCart != null && ShoppingCart.CartItems.Count > 0)
                        {
                            if (rblFreeGiftlist.Items.Count > 0)
                            {
                                rblFreeGiftlist.Items.Clear();
                            }
                            _AllSKUS = (ProductsBase).ProductInfoCatalog.AllSKUs;
                            SKU_V01 sku;
                            foreach (CatalogItem t in promo.SKUList)
                            {
                                if (_AllSKUS.TryGetValue(t.SKU, out sku))
                                {
                                    if (!ChinaPromotionProvider.GetPCPromoCode(t.SKU).Trim().Equals("DSChinaPromo")) // SKUs are same for both DSChinaPromo and PCChinaPromo
                                    {
                                        continue;
                                    }
                                    if ((
                                            ShoppingCartProvider.CheckInventory(t as CatalogItem_V01, 1,
                                                                                ProductsBase.CurrentWarehouse) > 0 &&
                                            (CatalogProvider.GetProductAvailability(sku,
                                                                                    ProductsBase.CurrentWarehouse) == ProductAvailabilityType.Available)))
                                    {
                                        rblFreeGiftlist.Items.Add(new ListItem(t.Description,
                                                                               t.SKU));

                                        divPromo.Visible = true;
                                        PcPromoOnly.Add(t);
                                    }
                                }
                            }
                            ChinaPromoSkus = PcPromoOnly;
                            if (rblFreeGiftlist.Items.Count > 0)
                            {
                                rblFreeGiftlist.Items[0].Selected = true;
                            }
                            var myShoppingCart = (Page as ProductsBase).ShoppingCart;

                            var promoInCart =
                                myShoppingCart.CartItems.Select(c => c.SKU).Intersect(PcPromoOnly.Select(f => f.SKU));
                            var itemcount = promoInCart as string[] ?? promoInCart.ToArray();
                            var count     = (from skucount in myShoppingCart.CartItems
                                             from cartitem in itemcount
                                             where cartitem.Trim().Equals(skucount.SKU.Trim())
                                             select skucount.Quantity).Sum();

                            if (count == currestsession.ChinaPromoSKUQuantity)
                            {
                                btnAddToCart.Enabled = false;
                                divPromo.Visible     = false;
                            }
                            else if (count > currestsession.ChinaPromoSKUQuantity)
                            {
                                var itemsInBoth =
                                    myShoppingCart.CartItems.Where(x => x.IsPromo)
                                    .Select(c => c.SKU)
                                    .Intersect(ChinaPromoSkus.Select(f => f.SKU));
                                if (itemsInBoth.Any())
                                {
                                    myShoppingCart.DeleteItemsFromCart(itemsInBoth.ToList(), true);
                                }
                                btnAddToCart.Enabled = true;
                                lblFreeGift.Text     =
                                    string.Format(GetLocalResourceObject("lblFreeGiftResource1.Text") as string,
                                                  currestsession.ChinaPromoSKUQuantity);
                            }
                            else
                            {
                                btnAddToCart.Enabled = true;
                                lblFreeGift.Text     =
                                    string.Format(GetLocalResourceObject("lblFreeGiftResource1.Text") as string,
                                                  currestsession.ChinaPromoSKUQuantity - count);
                            }
                        }
                    }
                }
                promotionPanel.Update();
            }
        }