Exemplo n.º 1
0
        private static List <TopSellerProductModel> GetTopSellerProductModel(IEnumerable <TopSellerSku_V01> skus, string id, string locale)
        {
            var totals           = new OrderTotals_V01();
            var ShoppingCartItem = new List <ShoppingCartItem_V01>();

            ShoppingCartItem.AddRange(from i in skus
                                      select
                                      new ShoppingCartItem_V01(0, i.Sku, 1, DateTime.Now));
            var existingCart = ShoppingCartProvider.GetShoppingCart(id, locale);

            totals = existingCart != null?existingCart.Calculate(ShoppingCartItem.ToList()) as OrderTotals_V01 : null;

            var topSellerProductModelList = skus.Select(topsellerSku => new TopSellerProductModel
            {
                ImageUrl       = topsellerSku.ImageUrl,
                Quantity       = 1, // default quantity "1"
                Sku            = topsellerSku.Sku,
                Name           = topsellerSku.Name,
                Price          = GetTopSellerSkuPrice(skus, topsellerSku, locale, totals),
                CurrencySymbol = topsellerSku.CurrencySymbol,
                DisplayPrice   = String.Format("{0}{1}", HLConfigManager.Configurations.CheckoutConfiguration.CurrencySymbol,
                                               GetTopSellerSkuPrice(skus, topsellerSku, locale, totals))
            }).ToList();

            return(topSellerProductModelList);
        }
        public static bool CheckSKULimitation(string country, MyHLShoppingCart cart, out List <string> errors)
        {
            string ruleName = "SkuLimitation Rules";

            errors = new List <string>();

            var SKULimitationInfo = GetSKULimitationInfo();

            if (SKULimitationInfo != null && cart.CartItems != null)
            {
                if (SKULimitationInfo.ContainsKey(country))
                {
                    List <ShoppingCartItem_V01> intersect = (from c in cart.CartItems
                                                             from s in SKULimitationInfo[country].Select(l => l.SKU.Trim())
                                                             where c.SKU == s
                                                             select c).ToList <ShoppingCartItem_V01>();
                    if (intersect.Count() > 0)
                    {
                        MyHLShoppingCart myCart = new MyHLShoppingCart {
                            DistributorID = cart.DistributorID, Locale = cart.Locale, CartItems = new ShoppingCartItemList(), CountryCode = cart.CountryCode
                        };
                        myCart.RuleResults = new List <ShoppingCartRuleResult>();
                        ServerRulesManager.Instance.ValidateSKULimitation(myCart, cart.Locale, intersect);
                        if (myCart.RuleResults.Any(
                                rs =>
                                rs.RuleName == ruleName && rs.Result == RulesResult.Failure))
                        {
                            var ruleResultMsgs =
                                myCart.RuleResults.Where(r => r.Result == RulesResult.Failure && r.RuleName == ruleName)
                                .Select(r => r.Messages);
                            errors.AddRange(ruleResultMsgs.First().Distinct().ToList());
                            myCart.RuleResults.RemoveAll(x => x.RuleName == ruleName);
                            return(false);
                        }
                    }
                }
            }
            if (country == "JP" && Settings.GetRequiredAppSetting <bool>("EnableJPSKURestriction", false))
            {
                ruleName = "PurchaseRestriction Rules";
                var allLimits = SKULimitationProvider.SKUPurchaseRestrictionInfo(cart.DistributorID, SKULimitationProvider.GetOrderMonthString());
                if (allLimits != null && allLimits.Any())
                {
                    ShoppingCartProvider.processCart(cart, new List <ShoppingCartItem_V01>(), ShoppingCartRuleReason.CartBeingPaid);
                    if (cart.RuleResults.Any(
                            rs =>
                            rs.RuleName == ruleName && rs.Result == RulesResult.Failure))
                    {
                        var ruleResultMsgs =
                            cart.RuleResults.Where(r => r.Result == RulesResult.Failure && r.RuleName == ruleName)
                            .Select(r => r.Messages);
                        errors.AddRange(ruleResultMsgs.First().Distinct().ToList());
                        cart.RuleResults.RemoveAll(x => x.RuleName == ruleName);
                        return(false);
                    }
                }
            }
            return(true);
        }
Exemplo n.º 3
0
        /// <summary>Initialize this object</summary>
        private void Initialize()
        {
            _CreateDateTime = DateUtils.GetCurrentLocalTime(_CountryCode);
            var orderMonth = _CreateDateTime;
            var fromDate   = DateTimeUtils.GetFirstDayOfMonth(orderMonth);
            var from       = new DateTime(fromDate.Year, fromDate.Month, fromDate.Day);
            var toDate     = DateTimeUtils.GetLastDayOfMonth(orderMonth);
            var to         = new DateTime(toDate.Year, toDate.Month, toDate.Day, 23, 59, 59);

            _MonthEndDate = _DualOrderMonthDate = to;
            //List<DualMonthPair> dualMonth = ShoppingCartProvider.GetDualOrderMonthDatesFromService(from, to, _CountryCode);
            if (!isPC())
            {
                var dualMonth = ShoppingCartProvider.GetDualOrderMonthDates(from, to, _CountryCode);
                if (null != dualMonth)
                {
                    foreach (DualMonthPair dmp in dualMonth)
                    {
                        if (_CreateDateTime < dmp.MonthEndDate)
                        {
                            // when MonthEndDate is 2014-12-31 23:59:59.000,  _CreateDateTime is 12/31, _CreateDateTime.Day is 31 and OrderMonth is 11 => exception
                            int year    = Convert.ToInt32(dmp.OrderMonth.Substring(0, 4));
                            int month   = Convert.ToInt32(dmp.OrderMonth.Substring(4, 2));
                            var lastDay = DateTimeUtils.GetLastDayOfMonth(new DateTime(year, month, 1));
                            _DualOrderMonthDate = dmp.MonthEndDate;
                            _MonthEndDate       = new DateTime(year, month, lastDay.Day, 23, 59, 59);

                            //    _MonthEndDate = new DateTime(Convert.ToInt32(dmp.OrderMonth.Substring(0, 4)),
                            //                                 Convert.ToInt32(dmp.OrderMonth.Substring(4, 2)),
                            //                                 _CreateDateTime.Day, 23, 59, 59);
                        }
                        break;
                    }

                    if (HLConfigManager.Configurations.DOConfiguration.ExtendDualOrderMonth > 0)
                    {
                        _DualOrderMonthDate =
                            _DualOrderMonthDate.AddHours(
                                HLConfigManager.Configurations.DOConfiguration.ExtendDualOrderMonth);
                    }
                }
                else
                {
                    LoggerHelper.Error("Failed to get Dual Month info from the Catalog Service");
                }
            }
            _OrderMonthData.CurrentOrderMonth = OrderMonthNumber;

            //Account for any EOM grace period
            //if (_MonthEndGracePeriod.Ticks  > 0)
            //{
            //    _MonthEndDate = to + _MonthEndGracePeriod;
            //    _DualOrderMonthDate += _MonthEndGracePeriod;
            //}
        }
Exemplo n.º 4
0
 public static MyHLShoppingCart CopyShoppingCartFromMemberInvoice(string distributorID, string locale, int invoiceID)
 {
     try
     {
         return(ShoppingCartProvider.GetShoppingCartFromMemberInvoice(distributorID, locale, invoiceID));
     }
     catch (Exception ex)
     {
         LoggerHelper.Error(string.Format("CopyInvoiceError error: DS {0}, locale{1}, invoice id {2}, error: {3}", distributorID, locale, invoiceID, ex.ToString()));
     }
     return(null);
 }
Exemplo n.º 5
0
        public static bool CanAddAPF(string distributorID)
        {
            var canAdd = false;
            var locale = Thread.CurrentThread.CurrentCulture.Name;
            var cart   = ShoppingCartProvider.GetShoppingCart(distributorID, locale, true);

            //var quantityInCart = APFQuantityInCart(cart);
            canAdd = (IsAPFDueWithinOneYear(distributorID, locale.Substring(3)) ||
                      (GetDSLevel(distributorID) == "DS" &&
                       IsAPFDueAndNotPaid(distributorID, locale) &&
                       (CalcQuantity(GetAPFDueDate(distributorID, locale.Substring(3))) > APFQuantityInCart(cart))));

            return(canAdd);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Copy a shopping cart from a exisiting order.
        /// </summary>
        /// <param name="shoppingCartID">Exisisting shopping cart.</param>
        /// <param name="distributorID">Actual distributor ID.</param>
        /// <param name="locale">Actual Locale.</param>
        /// <param name="SkuitemList">List of SKU item</param>
        /// <returns>New Shopping cart id.</returns>
        public static MyHLShoppingCart CopyShoppingCart(int shoppingCartID, string distributorID, string locale, SKU_V01ItemCollection SkuitemList = null)
        {
            try
            {
                //var myHLShoppingCart = ShoppingCartProvider.createShoppingCart(distributorID, locale);
                // create a new cart in catalog service
                MyHLShoppingCart copiedCart = ShoppingCartProvider.GetShoppingCartForCopy(distributorID, shoppingCartID, locale, 0, SkuitemList);
                if (copiedCart != null && copiedCart.ShippingAddressID != 0)
                {
                    IShippingProvider shippingProvider = ShippingProvider.GetShippingProvider(null);
                    if (HLConfigManager.Configurations.AddressingConfiguration.HasAddressRestriction)
                    {
                        List <DeliveryOption> shippingAddresses = shippingProvider.GetShippingAddresses(distributorID, locale).Where(s => s.HasAddressRestriction == true)
                                                                  .ToList();
                        if (shippingAddresses.Count > 0)
                        {
                            copiedCart.ShippingAddressID = shippingAddresses.FirstOrDefault().ID;
                        }
                    }

                    if (shippingProvider != null)
                    {
                        List <DeliveryOption> shippingAddresses = shippingProvider.GetShippingAddresses(distributorID, locale);
                        if (shippingAddresses == null || shippingAddresses != null &&
                            shippingAddresses.Find(s => s.ID == copiedCart.ShippingAddressID) == null)
                        {
                            string cacheKey = new ShippingProviderBase().getSessionShippingAddressKey(distributorID, locale);
                            HttpContext.Current.Session.Remove(cacheKey);
                        }
                    }
                }
                return(copiedCart);
            }
            catch (Exception ex)
            {
                LoggerHelper.Error(string.Format("CopyOrderError error: DS {0}, locale{1}, original {2}, error: {3}", distributorID, locale, shoppingCartID, ex.ToString()));
            }
            return(null);
        }
Exemplo n.º 7
0
 public List <ShoppingCartItem_V01> GetDiscontinuededSku(int shoppingCartId, string distributorId, string locale, int newShoppingCartId,
                                                         SKU_V01ItemCollection skuitemList = null)
 {
     return(ShoppingCartProvider.GetDiscontinuededSku(shoppingCartId, distributorId, locale, newShoppingCartId,
                                                      skuitemList));
 }
Exemplo n.º 8
0
 public List <ShoppingCartItem_V01> GetDiscontinuededSku(MyHLShoppingCart originalUnfilteredCopyCart)
 {
     return(ShoppingCartProvider.GetDiscontinuededSku(originalUnfilteredCopyCart));
 }
        /// <summary>
        /// The setup customer order data.
        /// </summary>
        /// <param name="customerOrderId">
        /// The customer order id.
        /// </param>
        /// <param name="distributorId"></param>
        /// <param name="countryCode"></param>
        /// <param name="locale"></param>
        /// <param name="isAddressValid"></param>
        /// <param name="customerAddressId"></param>
        public static void SetupCustomerOrderData(string customerOrderId, string distributorId, string countryCode, string locale, out bool isAddressValid, out int customerAddressId)
        {
            isAddressValid = false;
            var customerOrderV01 = CustomerOrderingProvider.GetCustomerOrderByOrderID(customerOrderId);

            // Close all carts for provided Customer Order ID
            if (customerOrderV01.OrderStatus == CustomerOrderStatusType.Cancelled)
            {
                ShoppingCartProvider.DeleteOldShoppingCartForCustomerOrder(
                    distributorId, customerOrderV01.OrderID);
            }

            var  existingCart                  = ShoppingCartProvider.GetShoppingCart(distributorId, locale);
            bool useAddressValidation          = ShippingProvider.GetShippingProvider(customerOrderV01.ProcessingCountry).AddressValidationRequired();
            bool useDsAddressAsShippingAddress = ShippingProvider.GetShippingProvider(customerOrderV01.ProcessingCountry).DSAddressAsShippingAddress();
            var  DShippingAddressForCustomer   = new List <DeliveryOption>();

            if (HLConfigManager.Configurations.PickupOrDeliveryConfiguration.SetDSAddressforCashOnDelivery && customerOrderV01.PaymentMethodChoice == CustomerPaymentMethodChoice.CashOnDelivery) // Mappinf object error CustomerPaymentMethodChoice.CashOnDelivery)
            {
                var dsProfile = DistributorOrderingProfileProvider.GetProfile(distributorId,
                                                                              customerOrderV01.ProcessingCountry);

                var mailingAddress = DistributorOrderingProfileProvider.GetAddress(ServiceProvider.OrderSvc.AddressType.Mailing, distributorId, customerOrderV01.ProcessingCountry);
                if (string.IsNullOrWhiteSpace(mailingAddress.PostalCode) || string.IsNullOrWhiteSpace(mailingAddress.City) || string.IsNullOrWhiteSpace(mailingAddress.Line1) || string.IsNullOrWhiteSpace(mailingAddress.StateProvinceTerritory) || dsProfile.PhoneNumbers == null)
                {
                    HttpContext.Current.Response.Redirect("~/dswebadmin/customerorders.aspx?error=2", false);
                }
                useDsAddressAsShippingAddress = true;
                DShippingAddressForCustomer.Add(

                    new DeliveryOption
                {
                    Address     = ObjectMappingHelper.Instance.GetToShipping(mailingAddress),
                    Id          = -4,
                    AddressId   = new Guid(),
                    AddressType = "Shipping",
                    Alias       = "",
                    AltAreaCode = string.Empty,
                    AltPhone    = string.Empty,
                    AreaCode    = mailingAddress.PostalCode,
                    Recipient   = string.Empty,
                    PostalCode  = mailingAddress.PostalCode,
                    Phone       = dsProfile.PhoneNumbers != null
                                    ? dsProfile.PhoneNumbers.Find(x => x.IsPrimary) != null
                                          ? dsProfile.PhoneNumbers.FirstOrDefault(x => x.IsPrimary).CountryPrefix + dsProfile.PhoneNumbers.FirstOrDefault(x => x.IsPrimary).AreaCode + dsProfile.PhoneNumbers.FirstOrDefault(x => x.IsPrimary).Number
                                          : dsProfile.PhoneNumbers.FirstOrDefault().CountryPrefix + dsProfile.PhoneNumbers.FirstOrDefault().AreaCode + dsProfile.PhoneNumbers.FirstOrDefault().Number
                                    : string.Empty,
                    State       = mailingAddress.StateProvinceTerritory,
                    FreightCode = "NOF",         // DEFAULT FREIGHTCODE TO CALL retrieveFreightCode,
                    Name        = DistributorProfileModel.DistributorName(),
                }
                    );
            }
            int            temporaryEnteredAddressId = 0;
            DeliveryOption option           = null;
            var            custOrderAddress = GetCustomerAddress(customerOrderV01, useAddressValidation);

            if ((custOrderAddress != null) && (!useDsAddressAsShippingAddress))
            {
                ShippingProvider.GetShippingProvider(countryCode).GetShippingAddresses(
                    distributorId, customerOrderV01.ProcessingLocale);
                temporaryEnteredAddressId =
                    ShippingProvider.GetShippingProvider(countryCode).SaveShippingAddress(
                        distributorId, customerOrderV01.ProcessingLocale, custOrderAddress, true, true, false);

                isAddressValid = true;

                // Add address To Temporary Address and Insert customer order cart
                custOrderAddress.ID = temporaryEnteredAddressId;
                option = new DeliveryOption(custOrderAddress);
            }
            else
            {
                ShippingAddress_V02 shippingAddress = null;
                if (useDsAddressAsShippingAddress)
                {
                    List <DeliveryOption> shippingAddresses = DShippingAddressForCustomer.Count > 0 ? DShippingAddressForCustomer:
                                                              ShippingProvider.GetShippingProvider(countryCode).GetShippingAddresses(
                        distributorId, customerOrderV01.ProcessingLocale);
                    if (shippingAddresses != null && shippingAddresses.Count > 0)
                    {
                        if ((shippingAddress = shippingAddresses.Find(s => s.IsPrimary)) == null)
                        {
                            shippingAddress = shippingAddresses.First();
                        }
                    }
                }
                if (shippingAddress != null)
                {
                    ShippingAddress_V02 shippingAddressV2 = null;
                    if (DShippingAddressForCustomer.Count > 0)
                    {
                        shippingAddressV2           = DShippingAddressForCustomer[0];
                        shippingAddressV2.ID        = -4;
                        shippingAddressV2.Recipient = DistributorProfileModel.DistributorName();
                    }

                    option = new DeliveryOption(shippingAddress);
                    temporaryEnteredAddressId = DShippingAddressForCustomer.Count > 0 ?  ShippingProvider.GetShippingProvider(countryCode).SaveShippingAddress(
                        distributorId, customerOrderV01.ProcessingLocale, shippingAddressV2, true, true, false) : shippingAddress.ID;
                    if (DShippingAddressForCustomer.Count > 0)
                    {
                        DShippingAddressForCustomer[0].ID = temporaryEnteredAddressId;
                    }
                }
                else
                {
                    option = new DeliveryOption();
                }
            }

            customerAddressId = temporaryEnteredAddressId;

            if (existingCart != null)
            {
                if (existingCart.DeliveryInfo != null)
                {
                    existingCart.DeliveryInfo.Address.ID = temporaryEnteredAddressId;
                }
                ShoppingCartProvider.UpdateShoppingCart(existingCart);
            }
            else
            {
                var shippingInfo = new Shipping.ShippingInfo(ServiceProvider.ShippingSvc.DeliveryOptionType.Shipping, option);

                MyHLShoppingCart customerCart = ShoppingCartProvider.InsertShoppingCart(
                    distributorId,
                    customerOrderV01.ProcessingLocale,
                    ServiceProvider.CatalogSvc.OrderCategoryType.RSO,
                    shippingInfo,
                    getCustomerOrderDetails(customerOrderV01), false, string.Empty);

                if (customerCart != null)
                {
                    foreach (ShoppingCartItem_V01 item in
                             GetCustomerCartItems(customerCart.ShoppingCartID, customerOrderV01.OrderItems))
                    {
                        ShoppingCartProvider.InsertShoppingCartItem(
                            distributorId, item, customerCart.ShoppingCartID);
                    }

                    // Update Status of Order To In Progress In Azure
                    CustomerOrderingProvider.UpdateCustomerOrderStatus(
                        customerOrderV01.OrderID, customerOrderV01.OrderStatus, CustomerOrderStatusType.InProgress);
                }
                else
                {
                    throw new Exception("Unable to Convert Customer Order To DO Order");
                }
            }
        }