示例#1
0
        public static IList <CommerceBuilder.Search.ShopByChoice> GetShopByChoices()
        {
            string shopBy = HttpContext.Current.Request.QueryString["shopby"];

            if (string.IsNullOrEmpty(shopBy))
            {
                return(null);
            }
            int[] choiceIds = AlwaysConvert.ToIntArray(shopBy);
            if (choiceIds == null || choiceIds.Length == 0)
            {
                return(null);
            }
            IList <InputChoice> inputChoices = CommerceBuilder.DomainModel.NHibernateHelper.QueryOver <InputChoice>()
                                               .AndRestrictionOn(ic => ic.Id).IsIn(choiceIds)
                                               .Fetch(c => c.InputField).Eager
                                               .List <InputChoice>();

            List <CommerceBuilder.Search.ShopByChoice> choices = new List <CommerceBuilder.Search.ShopByChoice>();

            foreach (var choice in inputChoices)
            {
                choices.Add(new CommerceBuilder.Search.ShopByChoice()
                {
                    Id = choice.Id, FieldId = choice.InputFieldId, FieldName = choice.InputField.Name, Text = choice.ChoiceText, Value = choice.ChoiceValue
                });
            }

            return(choices);
        }
示例#2
0
        /// <summary>
        /// Load users in the id list
        /// </summary>
        /// <param name="idList">List of user ids</param>
        private void ParseUserIdList(string idList)
        {
            // VALIDATE THE INPUT
            if (string.IsNullOrEmpty(idList))
            {
                throw new ArgumentNullException("idList");
            }
            if (!Regex.IsMatch(idList, "^\\d+(,\\d+)*$"))
            {
                throw new ArgumentException("Id list can only be a comma delimited list of integer.", "idList");
            }

            // PARSE THE LIST OF INTEGERS
            if (idList.Contains(","))
            {
                ICriteria criteria = NHibernateHelper.CreateCriteria <User>();
                criteria.Add(Restrictions.Eq("Store", AbleContext.Current.Store));
                criteria.Add(Restrictions.In("Id", AlwaysConvert.ToIntArray(idList)));
                _UserList = UserDataSource.LoadForCriteria(criteria);
            }
            else
            {
                ICriteria criteria = NHibernateHelper.CreateCriteria <User>();
                criteria.Add(Restrictions.Eq("Store", AbleContext.Current.Store));
                criteria.Add(Restrictions.Eq("Id", AlwaysConvert.ToInt(idList)));
                _UserList = UserDataSource.LoadForCriteria(criteria);
            }
        }
示例#3
0
 public void AddRange(string list)
 {
     int[] items = AlwaysConvert.ToIntArray(list);
     if (items != null)
     {
         this.AddRange(items);
     }
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="productId">Product id</param>
 /// <param name="quantity">Quantity</param>
 /// <param name="optionList">List of option ids if this is a variant</param>
 /// <param name="kitList">List of Kit Product Ids</param>
 /// <param name="userId">User Id</param>
 /// <param name="calculateTax">If true, also calculates the PriceWithTax property to determine
 /// the shopping price inclusive of tax.</param>
 private ProductCalculator(int productId, short quantity, string optionList, string kitList, int userId, bool calculateTax)
 {
     _ProductId     = productId;
     _Quantity      = quantity;
     _OptionList    = optionList;
     _KitProductIds = AlwaysConvert.ToIntArray(kitList);
     _UserId        = userId;
     _CalculateTax  = calculateTax;
     Calculate();
 }
示例#5
0
        /// <summary>
        /// Returns a comma delimited list of OrderId given a comma delimited list of OrderNumber
        /// </summary>
        /// <param name="orderNumberList">A comma delimited list of OrderNumber</param>
        /// <returns>A comma delimited list of OrderId</returns>
        public static string GetOrderIdList(string orderNumberList)
        {
            int[] orderNumbers = AlwaysConvert.ToIntArray(orderNumberList);
            Dictionary <int, int> orderIdLookup = LookupOrderIds(orderNumbers);
            List <string>         orderIds      = new List <string>();

            foreach (int id in orderIdLookup.Keys)
            {
                orderIds.Add(orderIdLookup[id].ToString());
            }
            return(string.Join(",", orderIds.ToArray()));
        }
示例#6
0
 private void LoadCustomViewState()
 {
     if (Page.IsPostBack)
     {
         string vsContent      = Request.Form[VS.UniqueID];
         string decodedContent = EncryptionHelper.DecryptAES(vsContent);
         UrlEncodedDictionary customViewState = new UrlEncodedDictionary(decodedContent);
         _AddProductId  = AlwaysConvert.ToInt(customViewState.TryGetValue("PID"));
         _AddOptionList = customViewState.TryGetValue("OL");
         int[] skp = AlwaysConvert.ToIntArray(customViewState.TryGetValue("SKP"));
         if (skp != null && skp.Length > 0)
         {
             _AddKitProducts.AddRange(skp);
         }
     }
 }
示例#7
0
        /// <summary>
        /// Checks the list of kit products and updates as necessary.
        /// </summary>
        /// <param name="kitList">The list of kit products to refresh.</param>
        /// <returns>An updated list of kit products.</returns>
        /// <remarks>
        /// 1. Ensures any included kit products are in the list
        /// 2. Any kit products that are no longer associated to the kit are removed.
        /// </remarks>
        internal string RefreshKitProducts(string kitList)
        {
            // PARSE THE ORIGINAL KIT LIST
            List <int> kitProductIds = new List <int>();

            if (!string.IsNullOrEmpty(kitList))
            {
                kitProductIds.AddRange(AlwaysConvert.ToIntArray(kitList));
            }

            // REMOVE INVALID KITPRODUCTS
            RemoveInvalidKitProducts(kitProductIds);

            // ENSURE REQUIRED CHOICES ARE IN THE KITLIST
            foreach (ProductKitComponent pkc in _Product.ProductKitComponents)
            {
                KitComponent kc = pkc.KitComponent;
                if (kc.InputType == KitInputType.IncludedShown || kc.InputType == KitInputType.IncludedHidden)
                {
                    // THIS IS AN INCLUDED COMPONENT, SO ALL ITEMS ARE REQUIRED
                    foreach (KitProduct kp in kc.KitProducts)
                    {
                        if (!kitProductIds.Contains(kp.KitProductId))
                        {
                            kitProductIds.Add(kp.KitProductId);
                        }
                    }
                }
                else if ((kc.InputType == KitInputType.DropDown || kc.InputType == KitInputType.RadioButton) &&
                         string.IsNullOrEmpty(kc.HeaderOption) && kc.KitProducts.Count == 1)
                {
                    // THIS TYPE OF CONTROL WITHOUT A HEADER OPTION AND A SINGLE KITPRODUCT FORCES CHOICE
                    KitProduct kp = kc.KitProducts[0];
                    if (!kitProductIds.Contains(kp.KitProductId))
                    {
                        kitProductIds.Add(kp.KitProductId);
                    }
                }
            }

            // RETURN THE REFRESHED KITLIST
            if (kitProductIds.Count == 0)
            {
                return(string.Empty);
            }
            return(AlwaysConvert.ToList(",", kitProductIds.ToArray()));
        }
        protected int GetExportCount()
        {
            string exportType = Request.QueryString["Type"];
            string ids        = Session["EXPORT_USER_IDS"] as string;

            if (!string.IsNullOrEmpty(exportType) && !string.IsNullOrEmpty(ids) && exportType == "selected")
            {
                return(AlwaysConvert.ToIntArray(ids).Length);
            }
            else if (!string.IsNullOrEmpty(Request.QueryString["filter"]))
            {
                var serializer = new JavaScriptSerializer();
                UserSearchCriteria criteria = serializer.Deserialize(Request.QueryString["filter"], typeof(UserSearchCriteria)) as UserSearchCriteria;
                return(UserDataSource.SearchCount(criteria));
            }
            else
            {
                return(UserDataSource.CountAll());
            }
        }
        protected string GetAvailableQuantity(object dataItem)
        {
            BasketItem item = (BasketItem)dataItem;

            if (_StoreInventoryEnabled && item.Product != null && item.Product.InventoryMode != InventoryMode.None)
            {
                List <int> kitList = null;
                if (!string.IsNullOrEmpty(item.KitList))
                {
                    kitList = new List <int>();
                    kitList.AddRange(AlwaysConvert.ToIntArray(item.KitList));
                }
                InventoryManagerData inv = _InventoryManager.CheckStock(item.ProductId, item.OptionList, kitList);
                return(inv.InStock.ToString());
            }
            else
            {
                return("n/a");
            }
        }
示例#10
0
        protected int GetExportCount()
        {
            int           count      = 0;
            ProductFilter criteria   = null;
            string        exportType = Request.QueryString["Type"];

            if (!string.IsNullOrEmpty(exportType) && exportType == "selected")
            {
                string ids = Session["EXPORT_PRODUCT_IDS"] as string;
                if (!string.IsNullOrEmpty(ids))
                {
                    criteria = new ProductFilter();
                    criteria.ProductIdRange = ids;
                }
            }
            else if (!string.IsNullOrEmpty(Request.QueryString["filter"]))
            {
                var serializer = new JavaScriptSerializer();
                criteria = serializer.Deserialize(Request.QueryString["filter"], typeof(ProductFilter)) as ProductFilter;
            }
            else
            {
                return(ProductDataSource.CountAll());
            }

            if (criteria != null && !string.IsNullOrEmpty(criteria.ProductIdRange))
            {
                // use specific product list
                int[] productIds = AlwaysConvert.ToIntArray(criteria.ProductIdRange);
                count = productIds.Length;
            }
            else if (criteria != null)
            {
                // use search results
                IProductRepository productRepository = AbleContext.Container.Resolve <IProductRepository>();
                count = productRepository.FindProductsCount(criteria.Name, criteria.SearchDescriptions, criteria.Sku, criteria.CategoryId, criteria.ManufacturerId, criteria.VendorId, criteria.Featured, 0, criteria.FromPrice, criteria.ToPrice, criteria.DigitalGoodsOnly, criteria.GiftCertificatesOnly, criteria.KitsOnly, criteria.SubscriptionsOnly);
            }

            return(count);
        }
 private void LoadCustomViewState()
 {
     if (Page.IsPostBack)
     {
         UrlEncodedDictionary customViewState = new UrlEncodedDictionary(EncryptionHelper.DecryptAES(Request.Form[VS.UniqueID]));
         _ShowEditGrid    = AlwaysConvert.ToBool(customViewState.TryGetValue("ShowEditGrid"), false);
         _EnableScrolling = AlwaysConvert.ToBool(customViewState.TryGetValue("EnableScrolling"), true);
         string selectedCategories = customViewState.TryGetValue("SC");
         if (!string.IsNullOrEmpty(selectedCategories))
         {
             int[] tempCategoryIds = AlwaysConvert.ToIntArray(selectedCategories);
             if (tempCategoryIds != null && tempCategoryIds.Length > 0)
             {
                 for (int i = 0; i < tempCategoryIds.Length; i++)
                 {
                     AddCategoryToList(tempCategoryIds[i]);
                 }
             }
         }
         BuildFieldList(customViewState.TryGetValue("SF"));
     }
 }
 private void LoadCustomViewState()
 {
     if (Page.IsPostBack)
     {
         string vsContent      = Request.Form[VS.UniqueID];
         string decodedContent = EncryptionHelper.DecryptAES(vsContent);
         UrlEncodedDictionary customViewState = new UrlEncodedDictionary(decodedContent);
         string selectedProducts = customViewState.TryGetValue("SP");
         if (!string.IsNullOrEmpty(selectedProducts))
         {
             int[] tempProductIds = AlwaysConvert.ToIntArray(selectedProducts);
             if (tempProductIds != null && tempProductIds.Length > 0)
             {
                 for (int i = 0; i < tempProductIds.Length; i++)
                 {
                     AddProductToList(tempProductIds[i]);
                 }
                 BindSelectedProducts(_SelectedProducts);
             }
         }
     }
 }
示例#13
0
        /// <summary>
        /// Gets a list of KitProduct objects associated with this BasketItem
        /// </summary>
        /// <param name="includeHidden">If true, items in hidden components are included.  If false, only items in visible component are included.</param>
        /// <returns>A list of KitProduct objects</returns>
        public List <KitProduct> GetKitProducts(bool includeHidden)
        {
            // BUILD LIST OF KIT PRODUCTS
            List <KitProduct> kitProductList = new List <KitProduct>();

            int[] kitProductIds = AlwaysConvert.ToIntArray(this.KitList);
            if (kitProductIds != null && kitProductIds.Length > 0)
            {
                for (int i = 0; i < kitProductIds.Length; i++)
                {
                    KitProduct kp = KitProductDataSource.Load(kitProductIds[i]);
                    if (kp != null)
                    {
                        bool addToList = (includeHidden || (kp.KitComponent.InputType != KitInputType.IncludedHidden));
                        if (addToList)
                        {
                            kitProductList.Add(kp);
                        }
                    }
                }
            }
            return(kitProductList);
        }
示例#14
0
 private void InitializeTemplateList()
 {
     if (Page.IsPostBack)
     {
         _Product.ProductTemplates.Clear();
         int[] selectedTemplates = AlwaysConvert.ToIntArray(Request.Form[HiddenSelectedTemplates.UniqueID]);
         if (selectedTemplates != null && selectedTemplates.Length > 0)
         {
             foreach (int ptid in selectedTemplates)
             {
                 ProductTemplate template = ProductTemplateDataSource.Load(ptid);
                 if (template != null)
                 {
                     _Product.ProductTemplates.Add(template);
                 }
             }
         }
     }
     else
     {
         HiddenSelectedTemplates.Value = GetTemplateIdList();
     }
     TemplateList.Text = GetTemplateList();
 }
示例#15
0
        private List <int> GetSelectedOrderIds()
        {
            List <int> selectedOrders = new List <int>();

            if (AlwaysConvert.ToBool(SelectAll.Value, false))
            {
                OrderFilter   filter = GetOrderFilter();
                IList <Order> orders = OrderDataSource.LoadForFilter(filter, 0, 0, "OrderNumber ASC");
                foreach (Order order in orders)
                {
                    selectedOrders.Add(order.Id);
                }
            }
            else
            {
                int[] orderNumbers = AlwaysConvert.ToIntArray(Request.Form["OID"]);
                IDictionary <int, int> orderIds = OrderDataSource.LookupOrderIds(orderNumbers);
                foreach (int orderId in orderIds.Values)
                {
                    selectedOrders.Add(orderId);
                }
            }
            return(selectedOrders);
        }
        protected void ChangeGroupListOKButton_Click(object sender, System.EventArgs e)
        {
            // REMOVE ANY MANAGEABLE GROUPS ASSOCIATED WITH USER, EXCEPT THE SUBSCRIPTION GROUPS
            IList <Group> managableGroups = SecurityUtility.GetManagableGroups();

            for (int i = _User.UserGroups.Count - 1; i >= 0; i--)
            {
                if (managableGroups.IndexOf(_User.UserGroups[i].GroupId) > -1 &&
                    _User.UserGroups[i].Subscription == null)
                {
                    _User.UserGroups.DeleteAt(i);
                }
            }

            // LOOP SUBMITTED GROUPS AND ADD (VALID) SELECTED GROUPS
            int[] selectedGroups = AlwaysConvert.ToIntArray(Request.Form[HiddenSelectedGroups.UniqueID]);
            if (selectedGroups != null && selectedGroups.Length > 0)
            {
                foreach (int groupId in selectedGroups)
                {
                    int index = managableGroups.IndexOf(groupId);
                    if (index > -1)
                    {
                        _User.UserGroups.Add(new UserGroup(_User, managableGroups[index]));
                    }
                }
            }
            else
            {
                // ASSIGN TO DEFAULT USER GROUP (NO MATTER USER HAVE SOME SUBSCRIPTION GROUPS ALREADY ASSIGNED)
                _User.UserGroups.Add(new UserGroup(_User, GroupDataSource.LoadForName(Group.DefaultUserGroupName)));
            }

            // SAVE ANY CHANGES TO USER GROUPS
            _User.Save();
        }
示例#17
0
        public void SaveButton_Click(object sender, EventArgs e)
        {
            // UPDATE TEMPLATE AND COLLECT ANY VALUES
            if (_Product.ProductTemplates.Count > 0)
            {
                // DELETE THE OLD PRODUCT TEMPLATE ASSOCIATION FROM DATABASE
                int[] selectedTemplates = AlwaysConvert.ToIntArray(Request.Form[HiddenSelectedTemplates.UniqueID]);
                ClearInvalidTemplateFields(_Product, selectedTemplates);
                if (selectedTemplates != null && selectedTemplates.Length > 0)
                {
                    for (int i = _Product.ProductTemplates.Count - 1; i > -1; i--)
                    {
                        // check if this template is in the list of selected templates
                        ProductTemplate template = _Product.ProductTemplates[i];
                        if (Array.IndexOf(selectedTemplates, template.Id) < 0)
                        {
                            _Product.ProductTemplates.DeleteAt(i);
                        }
                    }
                }

                // GATHER NEW VALUES FOR PRODUCT CUSTOM FIELDS
                AbleCommerce.Code.ProductHelper.CollectProductTemplateInput(_Product, phCustomFields);
                _Product.TemplateFields.Save();
            }
            else
            {
                // NO TEMPLATES SHOULD BE ASSOCIATED TO THE PRODUCT
                _Product.ProductTemplates.DeleteAll();
                _Product.TemplateFields.DeleteAll();
            }

            // DISPLAY CONFIRMATION
            SavedMessage.Visible = true;
            SavedMessage.Text    = string.Format(SavedMessage.Text, LocaleHelper.LocalNow);
        }
        /// <summary>
        /// Recalculates all items in the basket, for example price and kit member products
        /// </summary>
        internal void Recalculate()
        {
            // BUILD A LIST OF ANY CHILD (GENERATED) PRODUCTS
            List <int>        childItemIds  = new List <int>();
            List <BasketItem> childProducts = new List <BasketItem>();

            foreach (BasketItem item in this)
            {
                if (item.OrderItemType == OrderItemType.Product && item.IsChildItem)
                {
                    childItemIds.Add(item.BasketItemId);
                    childProducts.Add(item);
                }
            }

            // MOVE THROUGH THE COLLECTION AND REMOVE ANY ITEMS ASSOCIATED WITH A CHILD ITEM
            for (int i = this.Count - 1; i >= 0; i--)
            {
                BasketItem item      = this[i];
                List <int> childPath = item.GetPath();
                if (IsChildItemInPath(childItemIds, childPath))
                {
                    if (item.OrderItemType == OrderItemType.Product)
                    {
                        this.RemoveAt(i);
                    }
                    else
                    {
                        this.DeleteAt(i);
                    }
                }
            }

            // LOOP EACH REMAINING ITEM AND RECALCULATE
            int currentCount = this.Count;

            for (int i = 0; i < currentCount; i++)
            {
                BasketItem basketItem = this[i];
                Basket     basket     = basketItem.Basket;
                int        userId     = (basket == null ? Token.Instance.UserId : basket.UserId);

                // WE ONLY NEED TO CHECK PRODUCTS, NON-PRODUCT ITEMS HAVE NO RECALCULATION TASKS
                if (basketItem.OrderItemType == OrderItemType.Product)
                {
                    // IF WE HAVE A KIT, WE MUST REFRESH ANY CONFIGURED KIT OPTIONS
                    bool isKit = (basketItem.Product.KitStatus == KitStatus.Master);
                    if (isKit)
                    {
                        basketItem.KitList = basketItem.Product.Kit.RefreshKitProducts(basketItem.KitList);
                    }

                    // RECALCULATE THE STARTING SKU/PRICE/WEIGHT FOR THIS ITEM
                    ProductCalculator pcalc = ProductCalculator.LoadForProduct(basketItem.ProductId, basketItem.Quantity, basketItem.OptionList, basketItem.KitList, userId);
                    basketItem.Sku    = pcalc.Sku;
                    basketItem.Weight = pcalc.Weight;
                    if (isKit || !basketItem.Product.UseVariablePrice)
                    {
                        // KITS AND NONVARIABLE PRICED PRODUCTS MUST HAVE PRICE RECALCULATED
                        basketItem.Price = pcalc.Price;
                    }
                    basketItem.Save();

                    // REGENERATE THE KIT ITEMS FOR THIS ITEM
                    if (basket != null && isKit)
                    {
                        // OBTAIN THE KIT PRODUCTS THAT ARE SELECTED RATHER THAN INCLUDED
                        int[] kitProductIds = AlwaysConvert.ToIntArray(basketItem.KitList);
                        if (kitProductIds != null && kitProductIds.Length > 0)
                        {
                            //keep track of the price/weight of the master line item
                            //decrement these values for each line item registered
                            LSDecimal masterPrice  = basketItem.Price;
                            LSDecimal masterWeight = basketItem.Weight;
                            foreach (int kitProductId in kitProductIds)
                            {
                                KitProduct kitProduct = KitProductDataSource.Load(kitProductId);
                                if (kitProduct != null && kitProduct.KitComponent.InputType != KitInputType.IncludedHidden)
                                {
                                    // WE WANT TO GENERATE BASKET RECORDS FOR ALL ITEMS *EXCEPT* INCLUDED HIDDEN ITEMS
                                    // INCLUDED HIDDEN ITEMS ARE TREATED AS PART OF THE MAIN PRODUCT AND ARE NOT GENERATED
                                    // UNTIL THE ORDER IS FINALIZED
                                    Product    product    = kitProduct.Product;
                                    BasketItem searchItem = new BasketItem();
                                    searchItem.BasketId         = basket.BasketId;
                                    searchItem.OrderItemType    = OrderItemType.Product;
                                    searchItem.ParentItemId     = basketItem.BasketItemId;
                                    searchItem.ProductId        = product.ProductId;
                                    searchItem.OptionList       = kitProduct.OptionList;
                                    searchItem.BasketShipmentId = basketItem.BasketShipmentId;

                                    // LOOK FOR ITEM
                                    BasketItem childItem = FindChildProduct(childProducts, searchItem);

                                    // UPDATE CALCULATED PROPERTIES
                                    childItem.Name      = kitProduct.DisplayName;
                                    childItem.Quantity  = (short)(kitProduct.Quantity * basketItem.Quantity);
                                    childItem.TaxCodeId = product.TaxCodeId;
                                    childItem.Shippable = product.Shippable;
                                    childItem.Price     = kitProduct.CalculatedPrice / kitProduct.Quantity;;
                                    childItem.Weight    = kitProduct.CalculatedWeight / kitProduct.Quantity;
                                    // CALCULATE SKU
                                    ProductCalculator childCalc = ProductCalculator.LoadForProduct(childItem.ProductId, childItem.Quantity, childItem.OptionList, childItem.KitList, basket.UserId);
                                    childItem.Sku = childCalc.Sku;

                                    basket.Items.Add(childItem);
                                    childItem.Save();
                                    masterPrice  -= kitProduct.CalculatedPrice;
                                    masterWeight -= kitProduct.CalculatedWeight;
                                }
                            }

                            // UPDATE MASTER PRICE, FACTORING IN CHILD ITEMS
                            basketItem.Price  = masterPrice;
                            basketItem.Weight = masterWeight;
                            basketItem.Save();
                        }
                    }
                }
            }

            // DELETE ANY CHILD PRODUCTS THAT WERE NOT PRESERVED
            foreach (BasketItem bi in childProducts)
            {
                bi.Delete();
            }
        }
        /// <summary>
        /// Gets the order items that would result from the addition of the given product to an order.
        /// </summary>
        /// <param name="productId">The id of the product to add.</param>
        /// <param name="quantity">The quantity of the product to add.</param>
        /// <param name="optionList">List of option choice ids if this is a variant</param>
        /// <param name="kitList">List of kit products if it is a Kit</param>
        /// <returns>The order items that would result from the addition of the given product to an order</returns>
        public static List <OrderItem> CreateForProduct(int productId, short quantity, string optionList, string kitList)
        {
            List <OrderItem> orderItems = new List <OrderItem>();
            Product          product    = ProductDataSource.Load(productId);

            if (product != null)
            {
                //CREATE THE BASE ORDER ITEM
                OrderItem baseItem = new OrderItem();
                baseItem.Name          = product.Name;
                baseItem.OrderItemType = OrderItemType.Product;
                baseItem.ProductId     = productId;
                baseItem.TaxCodeId     = product.TaxCodeId;
                baseItem.Quantity      = quantity;
                baseItem.ShippableId   = product.ShippableId;
                //CALCULATE THE PRICE OF THE PRODUCT
                ProductCalculator pcalc = ProductCalculator.LoadForProduct(productId, quantity, optionList, kitList);
                baseItem.Sku    = pcalc.Sku;
                baseItem.Price  = pcalc.Price;
                baseItem.Weight = pcalc.Weight;
                //CHECK PRODUCT VARIANT
                ProductVariant variant = ProductVariantDataSource.LoadForOptionList(productId, optionList);
                if (variant != null)
                {
                    baseItem.OptionList  = optionList;
                    baseItem.VariantName = variant.VariantName;
                }
                //CHECK FOR DIGITAL GOODS
                foreach (ProductDigitalGood dg in product.DigitalGoods)
                {
                    if (dg.DigitalGood != null && (String.IsNullOrEmpty(baseItem.OptionList) || baseItem.OptionList == dg.OptionList))
                    {
                        OrderItemDigitalGood oidg = new OrderItemDigitalGood();
                        oidg.OrderItemId   = baseItem.OrderItemId;
                        oidg.DigitalGoodId = dg.DigitalGoodId;
                        oidg.Name          = dg.DigitalGood.Name;
                        baseItem.DigitalGoods.Add(oidg);
                    }
                }
                orderItems.Add(baseItem);

                //CHECK FOR KIT ITEMS
                int[] kitProductIds = AlwaysConvert.ToIntArray(kitList);
                if (kitProductIds != null && kitProductIds.Length > 0)
                {
                    LSDecimal baseItemPrice  = baseItem.Price;
                    LSDecimal baseItemWeight = baseItem.Weight;
                    foreach (int kitProductId in kitProductIds)
                    {
                        KitProduct kitProduct = KitProductDataSource.Load(kitProductId);
                        if (kitProduct != null)
                        {
                            OrderItem kitItem = new OrderItem();
                            kitItem.Name          = kitProduct.DisplayName;
                            kitItem.OrderItemType = OrderItemType.Product;
                            kitItem.ParentItemId  = baseItem.OrderItemId;
                            kitItem.ProductId     = kitProduct.ProductId;
                            kitItem.OptionList    = kitProduct.OptionList;
                            kitItem.Quantity      = (short)(kitProduct.Quantity * baseItem.Quantity);
                            kitItem.Sku           = kitProduct.Product.Sku;
                            kitItem.TaxCodeId     = kitProduct.Product.TaxCodeId;
                            kitItem.Price         = kitProduct.CalculatedPrice / kitProduct.Quantity;
                            kitItem.Weight        = kitProduct.CalculatedWeight / kitProduct.Quantity;
                            //CHECK FOR DIGITAL GOODS
                            foreach (DigitalGood dg in kitItem.Product.DigitalGoods)
                            {
                                OrderItemDigitalGood oidg = new OrderItemDigitalGood();
                                oidg.OrderItemId   = kitItem.OrderItemId;
                                oidg.DigitalGoodId = dg.DigitalGoodId;
                                kitItem.DigitalGoods.Add(oidg);
                            }
                            baseItemPrice  -= kitProduct.CalculatedPrice;
                            baseItemWeight -= kitProduct.CalculatedWeight;
                            orderItems.Add(kitItem);
                        }
                    }
                    baseItem.Price  = baseItemPrice;
                    baseItem.Weight = baseItemWeight;
                }
            }
            return(orderItems);
        }
示例#20
0
        /// <summary>
        /// Converts kit product assoications into order line items for a basket that is
        /// being finalized.
        /// </summary>
        /// <param name="basket">The basket checking out</param>
        /// <param name="order">The order being created</param>
        /// <param name="idLookup">A translation table to map basket ids to order ids</param>
        internal static void GenerateKitProducts(Basket basket, Order order, Dictionary <string, int> idLookup)
        {
            foreach (BasketItem basketItem in basket.Items)
            {
                if (basketItem.OrderItemType == OrderItemType.Product)
                {
                    int[] kitProductIds = AlwaysConvert.ToIntArray(basketItem.KitList);
                    if (kitProductIds != null && kitProductIds.Length > 0)
                    {
                        //keep track of the price/weight of the master line item
                        //decrement these values for each line item registered
                        LSDecimal masterPrice  = basketItem.Price;
                        LSDecimal masterWeight = basketItem.Weight;
                        foreach (int kitProductId in kitProductIds)
                        {
                            // WE ONLY NEED TO GENERATE RECORDS FOR THE HIDDEN ITEMS
                            // VISIBLE KIT MBMER PRODUCTS ARE GENERATED DURING THE BASKET RECALCULATION
                            KitProduct kp = KitProductDataSource.Load(kitProductId);
                            if (kp.KitComponent.InputType == KitInputType.IncludedHidden)
                            {
                                Product        p    = kp.Product;
                                ProductVariant pv   = kp.ProductVariant;
                                OrderItem      item = new OrderItem();
                                item.OrderId = order.OrderId;

                                // SET THE PARENT ITEM ID FOR THIS ITEM
                                if (idLookup.ContainsKey("I" + basketItem.BasketItemId))
                                {
                                    item.ParentItemId = idLookup["I" + basketItem.BasketItemId];
                                }

                                item.OrderItemType = OrderItemType.Product;
                                if (idLookup.ContainsKey("S" + basketItem.BasketShipmentId))
                                {
                                    item.OrderShipmentId = idLookup["S" + basketItem.BasketShipmentId];
                                }
                                if (idLookup.ContainsKey("I" + basketItem.BasketItemId))
                                {
                                    item.ParentItemId = idLookup["I" + basketItem.BasketItemId];
                                }
                                item.ProductId  = kp.ProductId;
                                item.Name       = kp.DisplayName;
                                item.OptionList = kp.OptionList;
                                if (pv != null)
                                {
                                    item.VariantName = pv.VariantName;
                                    item.Sku         = pv.Sku;
                                }
                                else
                                {
                                    item.Sku = p.Sku;
                                }
                                item.Quantity  = (short)(kp.Quantity * basketItem.Quantity);
                                item.TaxCodeId = p.TaxCodeId;
                                //THE CALCULATED PRICE IS FOR ALL ITEMS (EXT PRICE)
                                //TO GET A LINE ITEM PRICE WE MUST DIVIDE BY QUANTITY
                                item.Price          = kp.CalculatedPrice / kp.Quantity;
                                item.Weight         = kp.CalculatedWeight / kp.Quantity;
                                item.CostOfGoods    = p.CostOfGoods;
                                item.WishlistItemId = basketItem.WishlistItemId;
                                item.WrapStyleId    = basketItem.WrapStyleId;
                                item.IsHidden       = (kp.KitComponent.InputType == KitInputType.IncludedHidden);

                                //USE PARENT SHIPPABLE STATUS FOR HIDDEN KITTED PRODUCTS
                                item.Shippable = basketItem.Shippable;
                                item.Save();
                                order.Items.Add(item);
                                masterPrice  -= kp.CalculatedPrice;
                                masterWeight -= kp.CalculatedWeight;
                            }
                        }

                        //UPDATE THE PRICE OF THE KIT LINE ITEM (BASE PRICE OF PRODUCT LESS KIT PARTS)
                        if (idLookup.ContainsKey("I" + basketItem.BasketItemId))
                        {
                            int index = order.Items.IndexOf(idLookup["I" + basketItem.BasketItemId]);
                            if (index > -1)
                            {
                                order.Items[index].Price  = masterPrice;
                                order.Items[index].Weight = masterWeight;
                                order.Items[index].Save();
                            }
                        }
                    }
                }
            }
        }
示例#21
0
        public static List <AbleCommerce.Code.ProductAssetWrapper> GetAssets(Page page, Product product, string optionList, string kitList, string returnUrl)
        {
            // BUILD LIST OF ASSETS
            List <string> assetTracker = new List <string>();
            string        encodedReturnUrl;

            if (!string.IsNullOrEmpty(returnUrl))
            {
                encodedReturnUrl = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(returnUrl));
            }
            else
            {
                encodedReturnUrl = string.Empty;
            }
            List <AbleCommerce.Code.ProductAssetWrapper> assetList = new List <AbleCommerce.Code.ProductAssetWrapper>();

            string agreeUrl    = page.ResolveUrl("~/ViewLicenseAgreement.aspx") + "?id={0}&ReturnUrl=" + encodedReturnUrl;
            string agreePopup  = agreeUrl + "\" onclick=\"" + AbleCommerce.Code.PageHelper.GetPopUpScript(agreeUrl, "license", 640, 480, "resizable=1,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no") + ";return false";
            string readmeUrl   = page.ResolveUrl("~/ViewReadme.aspx") + "?ReadmeId={0}&ReturnUrl=" + encodedReturnUrl;
            string readmePopup = readmeUrl + "\" onclick=\"" + AbleCommerce.Code.PageHelper.GetPopUpScript(readmeUrl, "readme", 640, 480, "resizable=1,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no") + ";return false";

            List <ProductAndOptionList> products = new List <ProductAndOptionList>();

            products.Add(new ProductAndOptionList(product, optionList));

            // IF IT IS A KIT LOOK FOR CHILD PRODUCTS AS WELL
            if (!String.IsNullOrEmpty(kitList))
            {
                if (product.IsKit)
                {
                    bool  kitIsBundled  = !product.Kit.ItemizeDisplay;
                    int[] kitProductIds = AlwaysConvert.ToIntArray(kitList);
                    if (kitProductIds != null && kitProductIds.Length > 0)
                    {
                        foreach (int kitProductId in kitProductIds)
                        {
                            KitProduct kitProduct = KitProductDataSource.Load(kitProductId);
                            if ((kitProduct != null) &&
                                (kitProduct.KitComponent.InputType == KitInputType.IncludedHidden || kitIsBundled))
                            {
                                products.Add(new ProductAndOptionList(kitProduct.Product, kitProduct.OptionList));
                            }
                        }
                    }
                }
            }

            foreach (ProductAndOptionList pol in products)
            {
                foreach (ProductDigitalGood pdg in pol.Product.DigitalGoods)
                {
                    if ((string.IsNullOrEmpty(pdg.OptionList)) || (pol.OptionList == pdg.OptionList))
                    {
                        DigitalGood digitalGood = pdg.DigitalGood;
                        Readme      readme      = digitalGood.Readme;
                        if (readme != null && assetTracker.IndexOf("R" + readme.Id.ToString()) < 0)
                        {
                            assetList.Add(new AbleCommerce.Code.ProductAssetWrapper(string.Format(readmePopup, readme.Id), readme.DisplayName));
                            assetTracker.Add("R" + readme.Id.ToString());
                        }
                        LicenseAgreement agreement = digitalGood.LicenseAgreement;
                        if (agreement != null && assetTracker.IndexOf("L" + agreement.Id.ToString()) < 0)
                        {
                            assetList.Add(new AbleCommerce.Code.ProductAssetWrapper(string.Format(agreePopup, agreement.Id), agreement.DisplayName));
                            assetTracker.Add("L" + agreement.Id.ToString());
                        }
                    }
                }
            }
            return(assetList);
        }
示例#22
0
        /// <summary>
        /// Checks the set of kit products selected for this kit to determine if they are valid and complete
        /// </summary>
        /// <param name="kitList">List of kit product ids</param>
        /// <returns>True if the kit choices represent a valid kit, false otherwise</returns>
        public bool ValidateChoices(string kitList)
        {
            // PARSE THE KIT LIST
            List <int> kitProductIds = new List <int>();

            if (!string.IsNullOrEmpty(kitList))
            {
                kitProductIds.AddRange(AlwaysConvert.ToIntArray(kitList));
            }

            // CHECK FOR INVALID KITPRODUCTS IN THE LIST
            int originalCount = kitProductIds.Count;

            RemoveInvalidKitProducts(kitProductIds);

            // IF ANY INVALID ITEMS WERE REMOVED, THIS IS NOT A VALID KITLIST
            if (kitProductIds.Count != originalCount)
            {
                return(false);
            }

            // LOOP THE KIT COMPONENTS
            foreach (ProductKitComponent pkc in _Product.ProductKitComponents)
            {
                KitComponent kc = pkc.KitComponent;
                switch (kc.InputType)
                {
                case KitInputType.IncludedHidden:
                case KitInputType.IncludedShown:
                    foreach (KitProduct kp in kc.KitProducts)
                    {
                        // IF THIS INCLUDED ITEM IS NOT IN THE KITLIST IT IS INVALID
                        if (!kitProductIds.Contains(kp.KitProductId))
                        {
                            return(false);
                        }
                    }
                    break;

                case KitInputType.DropDown:
                case KitInputType.RadioButton:
                    // WE EITHER NEED 0 OR 1 FROM THIS COMPONENT, CAN NEVER HAVE TWO
                    bool needOne  = kc.KitProducts.Count > 0 && string.IsNullOrEmpty(kc.HeaderOption);
                    bool foundOne = false;
                    foreach (KitProduct kp in kc.KitProducts)
                    {
                        // IF THIS INCLUDED ITEM IS NOT IN THE KITLIST IT IS INVALID
                        if (kitProductIds.Contains(kp.KitProductId))
                        {
                            // IF WE HAVE ALREADY FOUND ONE CHOICE FROM THIS LIST THIS KIT IS INVALID
                            if (foundOne)
                            {
                                return(false);
                            }
                            foundOne = true;
                        }
                    }
                    // IF A CHOICE IS REQUIRED BUT NOT FOUND THIS KIT IS INVALID
                    if (needOne && !foundOne)
                    {
                        return(false);
                    }
                    break;
                }
            }

            // IF WE DID NOT FIND ANY PROBLEMS THE KIT IS VALID
            return(true);
        }