Пример #1
0
 public int CheckForBackOrderableOverage(SKU_V01 sku,
                                         int quantity,
                                         string warehouse,
                                         DeliveryOptionType type)
 {
     return(Providers.ShoppingCartProvider.CheckForBackOrderableOverage(sku, quantity, warehouse, type));
 }
        private ShoppingCartRuleResult CheckForInvalidSKU(ShoppingCart_V01 shoppingCart,
                                                          ShoppingCartRuleResult ruleResult)
        {
            var cart = shoppingCart as MyHLShoppingCart;

            if (cart != null)
            {
                bool    isValid      = false;
                SKU_V01 testThisItem = null;
                var     validSKUList = CatalogProvider.GetAllSKU(Locale);
                if (null != validSKUList)
                {
                    isValid = validSKUList.TryGetValue(cart.CurrentItems[0].SKU, out testThisItem);
                    if (isValid)
                    {
                        isValid = (null != testThisItem.CatalogItem);
                    }
                }

                if (!isValid)
                {
                    ruleResult.Result = RulesResult.Failure;
                    var errorMessage =
                        HttpContext.GetGlobalResourceObject(string.Format("{0}_Rules", HLConfigManager.Platform),
                                                            "SkuIsInvalid") ??
                        "SKU {0} is not available.";
                    ruleResult.AddMessage(string.Format(errorMessage.ToString(), cart.CurrentItems[0].SKU));
                }
            }
            return(ruleResult);
        }
Пример #3
0
        CartItemWithDetailList GetEventProductList(ShoppingCart_V02 cart)
        {
            var ret = new CartItemWithDetailList();

            if (Helper.Instance.HasData(cart.CurrentItems))
            {
                foreach (var cartItem in cart.CurrentItems)
                {
                    if (!IsEventProduct(cartItem.SKU))
                    {
                        continue;
                    }
                    SKU_V01 sku_v01 = null;
                    SkuList.TryGetValue(cartItem.SKU, out sku_v01);
                    if (sku_v01 == null)
                    {
                        continue;
                    }
                    var child = new CartItemWithDetail
                    {
                        CurrentItem = cartItem,
                        SKU         = sku_v01
                    };
                    ret.Add(child);
                }
            }

            if (Helper.Instance.HasData(cart.CartItems))
            {
                foreach (var cartItem in cart.CartItems)
                {
                    if (!IsEventProduct(cartItem.SKU))
                    {
                        continue;
                    }

                    var child = ret.FirstOrDefault(x => x.SkuCode == cartItem.SKU);
                    if (child != null)
                    {
                        child.CartItem = cartItem;
                    }
                    else
                    {
                        child = new CartItemWithDetail
                        {
                            CartItem = cartItem,
                            SKU      = SkuList[cartItem.SKU],
                        };
                        ret.Add(child);
                    }
                }
            }

            return(ret);
        }
Пример #4
0
        bool IsEventProduct(string sku)
        {
            SKU_V01 sku_v01 = null;

            SkuList.TryGetValue(sku, out sku_v01);
            if (sku_v01 == null)
            {
                return(false);
            }

            var p = sku_v01.Product;

            return(p != null && (p.TypeOfProduct == ServiceProvider.CatalogSvc.ProductType.EventTicket));
        }
        private bool IsBlocked(SKU_V01 sku)
        {
            bool isBlocked = false;

            string wareHouse = CurrentWarehouse;

            try
            {
                WarehouseInventory_V01 inventory = sku.CatalogItem.InventoryList[wareHouse] as WarehouseInventory_V01;
                isBlocked = inventory.IsBlocked;
            }
            catch { }

            return(isBlocked);
        }
        private Dictionary <int, SKU_V01> GetEventTicketList(ShoppingCart_V01 cart)
        {
            var eventItemList = new Dictionary <int, SKU_V01>();

            if (Helper.Instance.HasData(cart.CurrentItems))
            {
                foreach (var currentitem in cart.CurrentItems)
                {
                    var     AllSKUS = CatalogProvider.GetAllSKU(cart.Locale);
                    SKU_V01 sku_v01 = null;
                    AllSKUS.TryGetValue(currentitem.SKU, out sku_v01);
                    if (sku_v01 == null)
                    {
                        continue;
                    }
                    if (sku_v01.Product.TypeOfProduct == ProductType.EventTicket)
                    {
                        var result = cart.CartItems.FirstOrDefault(x => x.SKU == sku_v01.SKU);
                        if (result != null)
                        {
                            eventItemList.Add(currentitem.Quantity + result.Quantity, sku_v01);
                            var shoppingCart = cart as MyHLShoppingCart;
                            var listitem     = new List <string> {
                                sku_v01.SKU
                            };
                            if (shoppingCart != null)
                            {
                                shoppingCart.DeleteItemsFromCart(listitem, true);
                            }
                        }
                        else
                        {
                            eventItemList.Add(currentitem.Quantity, sku_v01);
                        }
                    }
                }
            }
            return(eventItemList);
        }
Пример #7
0
        private List <InvoiceSKU> ValidSkus(List <InvoiceSKU> lstskus)
        {
            var ProductInfoCatalog = CatalogProvider.GetProductInfoCatalog(Thread.CurrentThread.CurrentCulture.Name);
            Dictionary <string, SKU_V01> allSKU;
            SKU_V01 sku_v01 = null;

            allSKU = ProductInfoCatalog.AllSKUs;
            InvoiceSKU        validinvoicesku = null;
            List <InvoiceSKU> ValidInfoceSkus = new List <InvoiceSKU>();

            foreach (var invoiceSku in lstskus)
            {
                allSKU.TryGetValue(invoiceSku.SKU, out sku_v01);
                if (sku_v01 != null)
                {
                    validinvoicesku                   = new InvoiceSKU();
                    validinvoicesku.Quantity          = invoiceSku.Quantity;
                    validinvoicesku.SKU               = invoiceSku.SKU;
                    validinvoicesku.UnitVolumePoints  = sku_v01.CatalogItem.VolumePoints;
                    validinvoicesku.UnitTotalPrice    = sku_v01.CatalogItem.ListPrice;
                    validinvoicesku.TotalPrice        = sku_v01.CatalogItem.ListPrice * invoiceSku.Quantity;
                    validinvoicesku.TotalVolumePoints = sku_v01.CatalogItem.VolumePoints * invoiceSku.Quantity;
                    validinvoicesku.ID                = invoiceSku.ID;
                    validinvoicesku.InvoiceID         = invoiceSku.InvoiceID;
                    validinvoicesku.Description       = invoiceSku.Description;
                    ValidInfoceSkus.Add(validinvoicesku);
                }
            }
            if (ValidInfoceSkus.Count > 0)
            {
                return(ValidInfoceSkus);
            }
            else
            {
                return(new List <InvoiceSKU>());
            }
        }
        private int GetFeeAmount()
        {
            int     installments = 0;
            decimal feePrice     = 0.0M;
            decimal totalDue     = 0M;

            if (int.TryParse(ddlInstallments.SelectedValue, out installments))
            {
                if (installments > 1)
                {
                    OrderTotals_V01 totals = _page.ShoppingCart.Totals as OrderTotals_V01;
                    SKU_V01         feeSku = null;
                    if (_page.AllSKUS.TryGetValue(_cards.FeeSKU, out feeSku))
                    {
                        feePrice = feeSku.CatalogItem.ListPrice;
                        var     fees        = new AdditionalFees(_cards);
                        decimal coefficient = fees.GetCoefficient(ddlCards.SelectedValue, installments);
                        if (totals.ItemsTotal > 0)
                        {
                            totalDue = (totals.AmountDue) * (coefficient);
                        }
                    }
                    else
                    {
                        string errorMessage =
                            string.Format(
                                "Cannot find Credit Card Installment SKU {0}. Cannot calculate fees for Payment Installments",
                                _cards.FeeSKU);
                        LoggerHelper.Error(errorMessage);
                        throw new ApplicationException(errorMessage);
                    }
                }
            }

            return((totalDue > 0) ? int.Parse(Math.Ceiling(totalDue / feePrice).ToString()) : 0);
        }
Пример #9
0
 public void CheckInventory(ShoppingCart_V02 shoppingCart, int quantity, SKU_V01 sku, string warehouse, ref int availQuantity)
 {
     availQuantity = InventoryHelper.CheckInventory(shoppingCart, quantity, sku.CatalogItem, warehouse);
 }
Пример #10
0
        public GetFavouriteResponseWrapper Post(SetFavouriteRequestViewModel request, string memberId)
        {
            if (request == null)
            {
                throw CreateException(HttpStatusCode.BadRequest, "Invalid or Incomplete Set Favourite SKU information", 999998);
            }

            if (request.Data.Favourites.Count < 1)
            {
                throw CreateException(HttpStatusCode.BadRequest, "Invalid or Incomplete Set Favourite SKU information", 999998);
            }
            string obj      = JsonConvert.SerializeObject(request);
            var    response = new GetFavouriteResponseWrapper
            {
                ValidationErrors = new List <ValidationErrorViewModel>(),
                Data             = new FavouriteSetSKUResponseViewModel
                {
                    Favourites = new List <FavouriteSetSKUResponseViewModelItem>()
                }
            };

            try
            {
                string locale = Thread.CurrentThread.CurrentCulture.Name;

                Dictionary <string, SKU_V01>           allSKU    = CatalogProvider.GetAllSKU(locale);
                List <FavouriteSKUUpdateItemViewModel> favorList = request.Data.Favourites;
                List <ValidationErrorViewModel>        errors    = new List <ValidationErrorViewModel>();

                IEnumerable <FavouriteSKUUpdateItemViewModel> availableList = favorList.Where(x => allSKU.Select(y => y.Key).Contains(x.ProductSKU));
                IEnumerable <FavouriteSKUUpdateItemViewModel> exceptList    = favorList.Except(availableList);


                List <FavouriteSKUUpdateItemViewModel> SKUs = new List <FavouriteSKUUpdateItemViewModel>();
                foreach (var fv in availableList)
                {
                    var sku = allSKU.Where(x => x.Key == fv.ProductSKU); //.Where(x => x.Key == fv.ProductSKU).Select(x => x.Value);

                    if (sku != null)
                    {
                        SKU_V01 pd = (SKU_V01)sku.First().Value;
                        SKUs.Add(new FavouriteSKUUpdateItemViewModel {
                            productID = int.Parse(pd.CatalogItem.StockingSKU), ProductSKU = fv.ProductSKU, Action = fv.Action
                        });
                    }
                }

                string skuList = "";
                foreach (var sku in SKUs)
                {
                    skuList += sku.productID + "," + sku.ProductSKU + "," + sku.Action + "|";
                }


                SetFavouriteParam query = new SetFavouriteParam {
                    DistributorID = memberId,
                    Locale        = Thread.CurrentThread.CurrentCulture.Name,
                    SKUList       = skuList
                };

                var result = _mobileFavouriteProvider.SetFavouriteSKUs(query, ref errors);

                if (result)
                {
                    foreach (var s in SKUs)
                    {
                        response.Data.Favourites.Add(new FavouriteSetSKUResponseViewModelItem {
                            productSKU = s.ProductSKU, Updated = true
                        });
                    }

                    if (exceptList.Any())
                    {
                        foreach (var ex in exceptList)
                        {
                            response.Data.Favourites.Add(new FavouriteSetSKUResponseViewModelItem {
                                productSKU = ex.ProductSKU, Updated = false, reason = "SKU of " + ex.ProductSKU + " not part of product master"
                            });
                        }

                        response.ValidationErrors.Add(
                            new ValidationErrorViewModel
                        {
                            Message = "Update partially successful!"
                        });
                    }
                }
                else
                {
                    response.ValidationErrors.Add(
                        new ValidationErrorViewModel
                    {
                        Message = "Update not successful, kindly contact the administrator!"
                    });
                }
                JObject json = JObject.Parse(obj);
                MobileActivityLogProvider.ActivityLog(json, response, memberId, true,
                                                      this.Request.RequestUri.ToString(),
                                                      this.Request.Headers.ToString(),
                                                      this.Request.Headers.UserAgent.ToString(),
                                                      locale);


                return(response);
            }
            catch (Exception ex)
            {
                LoggerHelper.Error(ex.ToString());
                throw CreateException(HttpStatusCode.InternalServerError,
                                      "Internal server errror searching for Set Favourite SKU" + ex.Message, 404);
            }
        }
 public void CheckInventory(ShoppingCart_V02 shoppingCart, int quantity, SKU_V01 sku, string warehouse, ref int availQuantity)
 {
 }
        public static string GetSlowMovingPopUp(MyHLShoppingCart shoppingCart, Dictionary <string, SKU_V01> AllSKUS,
                                                out int count, out bool display)
        {
            count   = 0;
            display = false;
            if (shoppingCart == null || shoppingCart.CurrentItems == null)
            {
                return(string.Empty);
            }

            var SlowMovingskuList = LoadSlowMovingSkuInfo();
            var str = new StringBuilder();

            if (SlowMovingskuList != null && SlowMovingskuList.Any() && shoppingCart.CartItems.Any())
            {
                str.Append("<ul>");
                var quentity = (from slowmovingsku in SlowMovingskuList
                                from CurrentItems in shoppingCart.CurrentItems
                                where CurrentItems.SKU.Equals(slowmovingsku.SKU.Trim())
                                select CurrentItems.Quantity).Sum();

                if (AllSKUS != null)
                {
                    str.Append(string.Format("{0} {1} ",
                                             HttpContext.GetGlobalResourceObject(
                                                 string.Format("{0}_ErrorMessage", HLConfigManager.Platform),
                                                 "SlowMovingHeader"),
                                             "<br>"));
                    str.Append(
                        string.Format(
                            HttpContext.GetGlobalResourceObject(
                                string.Format("{0}_ErrorMessage", HLConfigManager.Platform),
                                "SlowMovingTotalQuentityMessagePart1")
                            + "{0}" +
                            HttpContext.GetGlobalResourceObject(
                                string.Format("{0}_ErrorMessage", HLConfigManager.Platform),
                                "SlowMovingTotalQuentityMessagePart2"), quentity.ToString()));
                    foreach (var skudetail in SlowMovingskuList)
                    {
                        if (shoppingCart.CurrentItems.Any(x => x.SKU.Trim().Equals(skudetail.SKU)))
                        {
                            var skudescription = new SKU_V01();
                            AllSKUS.TryGetValue(skudetail.SKU, out skudescription);
                            if (skudescription != null)
                            {
                                str.Append(
                                    string.Format(
                                        "<li>" + HttpContext.GetGlobalResourceObject(
                                            string.Format("{0}_ErrorMessage", HLConfigManager.Platform),
                                            "SlowMovingSku") + "{0} {1}" +
                                        HttpContext.GetGlobalResourceObject(
                                            string.Format("{0}_ErrorMessage", HLConfigManager.Platform),
                                            "SlowMovingSkuDescription") + "{2}" +
                                        HttpContext.GetGlobalResourceObject(
                                            string.Format("{0}_ErrorMessage", HLConfigManager.Platform),
                                            "SlowMovingSkuUnit") + "</li>", skudetail.SKU,
                                        skudescription.Product.DisplayName + skudescription.Description,
                                        Math.Round(skudescription.CatalogItem.ListPrice - skudetail.DiscountAmount,
                                                   0)));
                            }

                            count++;
                        }
                    }

                    str.Append("</ul>");
                    display = true;
                }
            }
            return(str.ToString());
        }
        /// <summary>
        /// The get all input.
        /// </summary>
        /// <returns>
        /// </returns>
        ///
        private List <ShoppingCartItem_V01> getAllInput(List <string> friendlyMessages)
        {
            Dictionary <string, SKU_V01> allSKUs = CatalogProvider.GetAllSKU(Locale, base.CurrentWarehouse);
            SKU_V01 skuV01 = null;

            friendlyMessages.Clear();
            errSKU.Clear();

            var      products         = new List <ShoppingCartItem_V01>();
            setError setErrorDelegate = delegate(SkuQty sku, string error, List <string> errors)
            {
                sku.Image.Visible = true;
                sku.HasError      = true;
                if (!errors.Contains(error))
                {
                    errors.Add(error);
                }
            };

            bool bNoItemSelected = true;

            for (int i = 1; i < NUMITEMS + 1; i++)
            {
                string controlID = "SKUBox" + i;
                var    ctrlSKU   = tblSKU.FindControl(controlID) as TextBox;
                var    ctrlQty   = tblSKU.FindControl("QuantityBox" + i) as TextBox;
                var    ctrlError = tblSKU.FindControl("imgError" + i) as Image;

                string strSKU = ctrlSKU.Text.Trim();
                string strQty = ctrlQty.Text;
                int    qty;
                int.TryParse(strQty, out qty);

                if (!string.IsNullOrEmpty(strSKU) && qty != 0)
                {
                    strSKU = strSKU.ToUpper();

                    // If the str has a product.
                    strSKU = strSKU.Split(new char[] { ' ' })[0];

                    AllSKUS.TryGetValue(strSKU, out skuV01);
                    if (skuV01 == null)
                    {
                        // if not valid setup error
                        setErrorDelegate(new SkuQty(controlID, strSKU, qty, ctrlError, true, true), string.Format((GetLocalResourceObject("NoSKUFound") as string), strSKU), errSKU);
                    }
                    else
                    {
                        if (CheckMaxQuantity(ShoppingCart.CartItems, qty, skuV01, errSKU))
                        {
                            if (skuList.Any(s => s.SKU == strSKU))
                            {
                                var skuQty = new SkuQty(controlID, strSKU, qty, ctrlError, true, true);
                                skuList.Add(skuQty);
                                setErrorDelegate(skuQty, string.Format((GetLocalResourceObject("DuplicateSKU") as string), strSKU), errSKU);
                                SkuQty skuToFind = skuList.Find(s => s.SKU == strSKU);
                                if (skuToFind != null)
                                {
                                    // this is to prevent dupe one to NOT be added to cart
                                    skuToFind.HasError      = true;
                                    skuToFind.Image.Visible = true;
                                }
                            }
                            else
                            {
                                skuList.Add(new SkuQty(controlID, strSKU, qty, ctrlError, false, false));
                            }
                        }
                        else
                        {
                            ctrlError.CssClass = ctrlError.CssClass.Replace("hide", string.Empty);
                        }
                    }
                }
                else if (!string.IsNullOrEmpty(strSKU) && qty <= 0)
                {
                    setErrorDelegate(new SkuQty(controlID, strSKU, qty, ctrlError, true, false), String.Format(PlatformResources.GetGlobalResourceString("ErrorMessage", "QuantityIncorrect"), strSKU), errSKU);
                }
                else
                {
                    if (strSKU.Length + strQty.Length != 0)
                    {
                        setErrorDelegate(new SkuQty(controlID, strSKU, qty, ctrlError, true, false), GetLocalResourceObject("SKUOrQtyMissing") as string, errSKU);
                    }
                }

                if (!string.IsNullOrEmpty(strSKU) || !string.IsNullOrEmpty(strQty))
                {
                    bNoItemSelected = false;
                }
            }

            if (bNoItemSelected)
            {
                errSKU.Add(PlatformResources.GetGlobalResourceString("ErrorMessage", "NoItemsSelected"));
            }
            else
            {
                try
                {
                    foreach (SkuQty s in skuList)
                    {
                        // do not need to check at this point
                        if (APFDueProvider.IsAPFSku(s.SKU))
                        {
                            setErrorDelegate(s, string.Format(PlatformResources.GetGlobalResourceString("ErrorMessage", "SKUNotAvailable"), s.SKU), errSKU);
                            continue;
                        }

                        AllSKUS.TryGetValue(s.SKU, out skuV01);
                        if (skuV01 != null)
                        {
                            HLRulesManager.Manager.ProcessCatalogItemsForInventory(Locale, this.ShoppingCart, new List <SKU_V01> {
                                skuV01
                            });
                            CatalogProvider.GetProductAvailability(skuV01, CurrentWarehouse);

                            int availQty;

                            // check isBlocked first
                            if (IsBlocked(skuV01))
                            {
                                setErrorDelegate(s, string.Format(PlatformResources.GetGlobalResourceString("ErrorMessage", "SKUNotAvailable"), s.SKU), errSKU);
                            }
                            else if (!skuV01.IsPurchasable)
                            {
                                setErrorDelegate(s, string.Format(GetLocalResourceObject("SKUCantBePurchased") as string, s.SKU), errSKU);
                            }
                            else if (skuV01.ProductAvailability == ProductAvailabilityType.Unavailable)
                            {
                                setErrorDelegate(s, string.Format(PlatformResources.GetGlobalResourceString("ErrorMessage", "SKUNotAvailable"), s.SKU), errSKU);
                            }
                            else if (HLConfigManager.Configurations.DOConfiguration.IsChina && ChinaPromotionProvider.GetPCPromoSkus(skuV01.SKU))
                            {
                                setErrorDelegate(s, string.Format(GetLocalResourceObject("SKUCantBePurchased") as string, s.SKU), errSKU);
                            }
                            else
                            {
                                int backorderCoverage = CheckBackorderCoverage(s.Qty, skuV01, friendlyMessages);
                                if (backorderCoverage == 0)
                                {
                                    // out of stock
                                    if ((availQty = ShoppingCartProvider.CheckInventory(skuV01.CatalogItem, GetAllQuantities(ShoppingCart.CartItems, s.Qty, s.SKU), CurrentWarehouse)) == 0)
                                    {
                                        setErrorDelegate(s, string.Format(MyHL_ErrorMessage.OutOfInventory, s.SKU), errSKU);
                                    }
                                    else if (availQty < GetAllQuantities(ShoppingCart.CartItems, s.Qty, s.SKU))
                                    {
                                        setErrorDelegate(s, string.Format(PlatformResources.GetGlobalResourceString("ErrorMessage", "LessInventory"), s.SKU, availQty), errSKU);
                                        HLRulesManager.Manager.PerformBackorderRules(ShoppingCart, skuV01.CatalogItem);
                                        IEnumerable <string> ruleResultMessages =
                                            from r in ShoppingCart.RuleResults
                                            where r.Result == RulesResult.Failure && r.RuleName == "Back Order"
                                            select r.Messages[0];
                                        if (null != ruleResultMessages && ruleResultMessages.Count() > 0)
                                        {
                                            errSKU.Add(ruleResultMessages.First());
                                            ShoppingCart.RuleResults.Clear();
                                        }
                                    }
                                }
                            }
                        }
                    }

                    //if (errSKU.Count == 0)
                    {
                        products.AddRange((from c in skuList
                                           where c.HasError == false
                                           select new ShoppingCartItem_V01(0, c.SKU, c.Qty, DateTime.Now)).ToList());
                    }
                }
                catch (Exception ex)
                {
                    LoggerHelper.Error(string.Format("getAllInput error:" + ex));
                }
            }

            return(products);
        }
 public ProductAvailabilityType GetProductAvailability(SKU_V01 sku, string warehouse, DeliveryOptionType deliveryOption = DeliveryOptionType.Unknown, string freightCode = null)
 {
     return Providers.CatalogProvider.GetProductAvailability(sku, warehouse, deliveryOption, freightCode);
 }