예제 #1
0
        protected void btnAddProducts_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                foreach (var prodBvin in ucProductPicker.SelectedProducts)
                {
                    // Preventative Code Only - this shouldn't be necessary, but is
                    // do not bundle a product to itself to prevent stackoverflow errors in customer views
                    if (prodBvin.Equals(ProductId))
                    {
                        EventLog.LogEvent("Bundled Products", "Product cannot be bundled to itself",
                                          EventLogSeverity.Information);
                        continue;
                    }

                    var bundledProduct = new BundledProduct
                    {
                        BundledProductId = prodBvin,
                        ProductId        = ProductId,
                        Quantity         = 1
                    };

                    HccApp.CatalogServices.BundledProductCreate(bundledProduct);
                }

                LoadItems();
            }
        }
예제 #2
0
        /// <summary>
        ///     Creates the bundle.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="hccApp">The HCC application.</param>
        /// <returns></returns>
        public object CreateBundle(HttpRequest request, HotcakesApplication hccApp)
        {
            var productId       = request.Params["productId"];
            var productIdString = request.Params["productIds"];

            var productIds = Json.ObjectFromJson <string[]>(productIdString).ToList();

            productIds.Insert(0, productId);

            var mainProduct = hccApp.CatalogServices.Products.FindWithCache(productId);

            var p = new Product();

            p.Sku           = CreateSku(mainProduct.Sku + "Bundle", hccApp);
            p.ProductName   = mainProduct.ProductName + " Bundle";
            p.IsBundle      = true;
            p.IsSearchable  = true;
            p.Status        = ProductStatus.Disabled;
            p.InventoryMode = ProductInventoryMode.AlwayInStock;
            p.UrlSlug       = CreateUrlSlug(mainProduct.UrlSlug + "-bundle", hccApp);
            hccApp.CatalogServices.ProductsCreateWithInventory(p, true);

            foreach (var subProductId in productIds)
            {
                var bundledProduct = new BundledProduct
                {
                    BundledProductId = subProductId,
                    ProductId        = p.Bvin,
                    Quantity         = 1
                };

                hccApp.CatalogServices.BundledProductCreate(bundledProduct);
            }

            return(string.Format("/DesktopModules/Hotcakes/Core/Admin/catalog/Products_Edit.aspx?id={0}", p.Bvin));
        }