Beispiel #1
0
        static KitComposition BuildCompositionFromModel(KitAddToCartPostModel model, KitProductData kitData, int customerId)
        {
            // Build up the kit selections from the model
            var selectedItems = model.GetSelectedItems(kitData);

            // Now build the composition
            var composition = new KitComposition(0);

            foreach (var selectedItem in selectedItems)
            {
                KitCartItem kcItem = new KitCartItem();
                kcItem.ProductID  = model.ProductId;
                kcItem.VariantID  = model.VariantId;
                kcItem.KitGroupID = selectedItem.Group.Id;
                kcItem.KitItemID  = selectedItem.Id;
                kcItem.CustomerID = customerId;
                kcItem.TextOption = selectedItem.TextOption;
                int qty = 1;
                if (selectedItem.HasMappedVariant &&
                    selectedItem.InventoryQuantityDelta > 1)
                {
                    qty = selectedItem.InventoryQuantityDelta;
                }

                kcItem.Quantity = qty;

                composition.Compositions.Add(kcItem);
            }

            return(composition);
        }
Beispiel #2
0
        private KitComposition ComposeAddToCart()
        {
            KitComposition composition = new KitComposition(0);

            foreach (KitItemData selectedItem in KitData.SelectedItems)
            {
                KitCartItem kcItem = new KitCartItem();
                kcItem.ProductID  = KitData.Id;
                kcItem.VariantID  = KitData.VariantId;
                kcItem.KitGroupID = selectedItem.Group.Id;
                kcItem.KitItemID  = selectedItem.Id;
                kcItem.CustomerID = ThisCustomer.CustomerID;
                kcItem.TextOption = selectedItem.TextOption;
                int qty = 1;
                if (selectedItem.HasMappedVariant &&
                    selectedItem.InventoryQuantityDelta > 1)
                {
                    qty = selectedItem.InventoryQuantityDelta;
                }

                kcItem.Quantity = qty;

                composition.Compositions.Add(kcItem);
            }

            return(composition);
        }
Beispiel #3
0
        static KitComposition BuildCompositionFromModel(KitAddToCartPostModel model, KitProductData kitData, int customerId)
        {
            // Build up the kit selections from the model
            var selectedItems = model.GetSelectedItems(kitData);

            // Validate Kit options
            if (kitData.HasRequiredGroups)
            {
                foreach (var requiredGroup in kitData.Groups.Where(g => g.IsRequired))
                {
                    var requirementIsMet = requiredGroup
                                           .Items
                                           .Intersect(selectedItems)
                                           .Any();

                    if (!requirementIsMet)
                    {
                        return(null);
                    }
                }
            }

            // Now build the composition
            var composition = new KitComposition(0);

            foreach (var selectedItem in selectedItems)
            {
                KitCartItem kcItem = new KitCartItem();
                kcItem.ProductID  = model.ProductId;
                kcItem.VariantID  = model.VariantId;
                kcItem.KitGroupID = selectedItem.Group.Id;
                kcItem.KitItemID  = selectedItem.Id;
                kcItem.CustomerID = customerId;
                kcItem.TextOption = selectedItem.TextOption;
                int qty = 1;
                if (selectedItem.HasMappedVariant &&
                    selectedItem.InventoryQuantityDelta > 1)
                {
                    qty = selectedItem.InventoryQuantityDelta;
                }

                kcItem.Quantity = qty;

                composition.Compositions.Add(kcItem);
            }

            return(composition);
        }