Esempio n. 1
0
        public ActionResult AjaxGetKitData(KitAddToCartPostModel model)
        {
            var product = new Product(model.ProductId);

            if (model.VariantId == 0)
            {
                model.VariantId = AppLogic.GetDefaultProductVariant(model.ProductId);
            }

            var variant = new ProductVariant(model.VariantId);

            var customer = HttpContext.GetCustomer();
            var cartType = model.IsWishlist
                                ? CartTypeEnum.WishCart
                                : CartTypeEnum.ShoppingCart;

            if (!product.IsAKit)
            {
                return(Content(string.Empty));
            }

            KitProductData kitData = KitProductData.Find(
                productId: product.ProductID,
                cartRecId: model.CartRecordId.HasValue
                                        ? model.CartRecordId.Value
                                        : 0,
                thisCustomer: customer);

            // Manipulate the default selections to reflect the selections made so far
            var selectedItems = model.GetSelectedItems(kitData);

            foreach (var item in kitData.Groups.SelectMany(g => g.Items))
            {
                if (selectedItems.Contains(item))
                {
                    item.IsSelected = true;
                }
                else
                {
                    item.IsSelected = false;
                }
            }

            var quantity = Math.Max(model.Quantity, 1);

            var kitAddToCartViewModel = BuildDefaultKitAddToCartViewModel(kitData, product, variant, quantity, customer, model.CartRecordId);

            var itemDisplayNames = kitAddToCartViewModel.KitGroups
                                   .SelectMany(group => group.Items)
                                   .ToDictionary(item => item.Id.ToString(), item => item.NameDisplay);

            return(Json(
                       new AjaxKitDataViewModel
            {
                SummaryHtml = ControllerContext.GetHtmlHelper().Partial(
                    partialViewName: ViewNames.KitSummaryPartial,
                    model: kitAddToCartViewModel).ToString(),
                ItemDisplayNames = itemDisplayNames
            }));
        }
Esempio n. 2
0
        protected override void OnInit(EventArgs e)
        {
            int productId = Request.QueryStringNativeInt("productId");
            int groupId   = Request.QueryStringNativeInt("groupId");
            int kitItemId = Request.QueryStringNativeInt("itemId");

            KitProductData kitProduct = KitProductData.Find(productId, Customer.Current);

            KitData = kitProduct;

            if (kitProduct != null)
            {
                KitGroupData kitGroup = kitProduct.GetGroup(groupId);
                if (kitGroup != null)
                {
                    KitItemData item = kitGroup.GetItem(kitItemId);
                    if (item != null)
                    {
                        KitItem = item;
                        kitProduct.TempFileStub = Request.QueryStringCanBeDangerousContent("stub");
                    }
                }
            }

            base.OnInit(e);
        }
Esempio n. 3
0
        protected void ddLocale_SelectedIndexChanged(object sender, EventArgs e)
        {
            string currentLocale = ddLocale.SelectedValue;

            Kit = KitProductData.Find(Kit.Id, ThisCustomer, currentLocale);
            InitializeDataSources();
            BindData();

            // force the update of the whole groups
            pnlUpdateAllGroups.Update();
        }
Esempio n. 4
0
        KitItemInfo GetKitItemInfo(int itemId, string stub)
        {
            int productId = 0;
            int groupId   = 0;

            using (var connection = new SqlConnection(DB.GetDBConn()))
                using (var command = new SqlCommand())
                {
                    command.Connection  = connection;
                    command.CommandText = @"select kg.ProductID, kg.KitGroupID from KitItem ki
										left join KitGroup kg on kg.KitGroupID = ki.KitGroupID
										where KitItemId = @KitItemId"                                        ;

                    command.Parameters.AddWithValue("KitItemId", itemId);
                    connection.Open();
                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            productId = reader.FieldInt("ProductID");
                            groupId   = reader.FieldInt("kitgroupID");
                        }
                    }
                }

            var kitData = KitProductData.Find(productId, Customer.Current);

            if (kitData == null)
            {
                return(null);
            }

            // Put the temporary file stub on the kit data object so that later it can be saved with the right filename.
            kitData.TempFileStub = stub;

            var kitGroup = kitData.GetGroup(groupId);

            if (kitGroup == null)
            {
                return(null);
            }

            return(new KitItemInfo
            {
                KitItem = kitGroup.GetItem(itemId),
                ProductId = productId,
                GroupId = groupId
            });
        }
Esempio n. 5
0
        private void LoadThisKitData()
        {
            int productId = Request.QueryStringNativeInt("productId");
            int cartId    = Request.QueryStringNativeInt("cartrecid");

            if (cartId > 0)
            {
                this.KitData = KitProductData.Find(productId, cartId, ThisCustomer);
                GetQuantityFromCart();
            }
            else
            {
                this.KitData = KitProductData.Find(productId, ThisCustomer);
            }
        }
Esempio n. 6
0
        protected override void OnInit(EventArgs e)
        {
            Response.CacheControl = "private";
            Response.Expires      = -1;
            Response.AddHeader("pragma", "no-cache");

            ThisCustomer = Customer.Current;

            int kitId   = Request.QueryStringNativeInt("kitId");
            int groupId = Request.QueryStringNativeInt("groupId");

            KitProductData kit = KitProductData.Find(kitId, ThisCustomer);

            KitGroup = kit.GetGroup(groupId);

            BindData();


            base.OnInit(e);
        }
Esempio n. 7
0
        public static AddToCartContext ConvertToAddToCartContext(this KitAddToCartPostModel kitAddToCartPostModel, Customer customer, CartTypeEnum cartType)
        {
            // Start with default kit data with no customer selections
            var kitData = KitProductData.Find(
                productId: kitAddToCartPostModel.ProductId,
                cartRecId: kitAddToCartPostModel.CartRecordId ?? 0,
                thisCustomer: customer);

            // Move uploaded files to their permanent location.
            kitData.TempFileStub = kitAddToCartPostModel.TemporaryImageNameStub;
            if (kitData.HasFileUploadGroup)
            {
                kitData.MoveAllTempImagesToOrdered();                 // This also updates the text option field for file uploads.
            }
            return(new AddToCartContext()
            {
                Customer = customer,
                CartType = cartType,

                ShoppingCartRecId = kitAddToCartPostModel.CartRecordId,
                Quantity = kitAddToCartPostModel.Quantity,

                ProductId = kitAddToCartPostModel.ProductId,
                VariantId = kitAddToCartPostModel.VariantId,
                UpsellProducts = kitAddToCartPostModel.UpsellProducts,
                IsWishlist = kitAddToCartPostModel.IsWishlist,

                CustomerEnteredPrice = 0,
                Color = string.Empty,
                Size = string.Empty,
                TextOption = string.Empty,

                TemporaryImageNameStub = kitAddToCartPostModel.TemporaryImageNameStub,
                KitData = kitData,
                Composition =
                    BuildCompositionFromModel(
                        model: kitAddToCartPostModel,
                        kitData: kitData,
                        customerId: customer.CustomerID)
            });
        }
Esempio n. 8
0
        public static AddToCartContext ConvertToAddToCartContext(this KitAddToCartPostModel kitAddToCartPostModel, Customer customer, CartTypeEnum cartType)
        {
            // Start with default kit data with no customer selections
            var kitData = KitProductData.Find(
                productId: kitAddToCartPostModel.ProductId,
                cartRecId: kitAddToCartPostModel.CartRecordId ?? 0,
                thisCustomer: customer);

            // Add the temp file stup to the kit data for use later.
            kitData.TempFileStub = kitAddToCartPostModel.TemporaryImageNameStub;

            return(new AddToCartContext()
            {
                Customer = customer,
                CartType = cartType,

                ShoppingCartRecId = kitAddToCartPostModel.CartRecordId,
                Quantity = kitAddToCartPostModel.Quantity,

                ProductId = kitAddToCartPostModel.ProductId,
                VariantId = kitAddToCartPostModel.VariantId,
                UpsellProducts = kitAddToCartPostModel.UpsellProducts,
                IsWishlist = kitAddToCartPostModel.IsWishlist,

                CustomerEnteredPrice = 0,
                Color = string.Empty,
                Size = string.Empty,
                TextOption = string.Empty,

                TemporaryImageNameStub = kitAddToCartPostModel.TemporaryImageNameStub,
                KitData = kitData,
                Composition =
                    BuildCompositionFromModel(
                        model: kitAddToCartPostModel,
                        kitData: kitData,
                        customerId: customer.CustomerID)
            });
        }
Esempio n. 9
0
        public ActionResult KitAddToCartForm(int?productId = null, int?variantId = null, int?cartRecordId = null)
        {
            var product = new Product(productId ?? 0);

            if (variantId == null || variantId == 0)
            {
                variantId = AppLogic.GetDefaultProductVariant(product.ProductID);
            }

            var variant = new ProductVariant(variantId.Value);

            var customer = HttpContext.GetCustomer();

            if (!product.IsAKit)
            {
                throw new Exception(string.Format("product {0} is not a kit and so we cannot show the kit add to cart form", product.ProductID));
            }

            var kitData = KitProductData.Find(
                productId: product.ProductID,
                cartRecId: cartRecordId.HasValue
                                        ? cartRecordId.Value
                                        : 0,
                thisCustomer: customer);

            var quantity = GetKitQuantity(cartRecordId, variant.MinimumQuantity);

            if (kitData == null)
            {
                return(Content("Details for this kit have not been setup"));
            }

            var kitAddToCartViewModel = BuildDefaultKitAddToCartViewModel(kitData, product, variant, quantity, customer, cartRecordId);

            return(PartialView(ViewNames.KitAddToCartFormPartial, kitAddToCartViewModel));
        }
Esempio n. 10
0
        protected override void OnInit(EventArgs e)
        {
            int productId = Request.QueryStringNativeInt("productId");

            Customer ThisCustomer = Customer.Current;

            this.Kit = KitProductData.Find(productId, ThisCustomer);

            if (this.Kit != null)
            {
                InitializeDataSources();
                BindData();

                if (!this.IsPostBack)
                {
                    InitializeLocales();
                }

                CreateBreadCrumb();
            }


            base.OnInit(e);
        }