private void AddProductToCart()
        {
            /*
             * Example based on the code at the following documentation page:
             *
             * https://hotcakescommerce.zendesk.com/hc/en-us/articles/204725889-Add-a-Product-to-Cart-Programmatically
             *
             */

            // create a reference to the Hotcakes store
            var HccApp = HccAppHelper.InitHccApp();

            // find the first product returned that doesn't have options or variants
            if (product == null)
            {
                GetProductFromTheStore();
            }

            // set the quantity
            var quantity = 1;

            // create a reference to the current shopping cart
            Order currentCart = HccApp.OrderServices.EnsureShoppingCart();

            // create a line item for the cart using the product
            LineItem li = product.ConvertToLineItem(HccApp, quantity, new OptionSelections());

            // add the line item to the current cart
            HccApp.AddToOrderWithCalculateAndSave(currentCart, li);

            // send the customer to the shopping cart page
            Response.Redirect(HccUrlBuilder.RouteHccUrl(HccRoute.Cart));
        }
        private void GetProductFromTheStore()
        {
            // create a reference to the Hotcakes store
            var HccApp = HccAppHelper.InitHccApp();

            // get a collection of the products in the store already
            var products = HccApp.CatalogServices.Products.FindAllPaged(1, int.MaxValue);

            // make sure we don't throw an error
            if (products == null || !products.Any())
            {
                return;
            }

            // see if any are available that don't have any choices assigned
            if (products.Any(p => !p.HasOptions() && !p.HasVariants()))
            {
                // find the first product returned that doesn't have options or variants
                product = products.FirstOrDefault(p => !p.HasOptions() && !p.HasVariants());
            }
        }
Пример #3
0
        public List <MenuNode> ManipulateNodes(List <MenuNode> nodes, DotNetNuke.Entities.Portals.PortalSettings portalSettings)
        {
            MenuNode categoriesMenu = new MenuNode {
                Text = "Product Categories"
            };

            nodes.Insert(0, categoriesMenu);

            //Find Categories to Display in Menu

            HotcakesApplication     hccApp     = HccAppHelper.InitHccApp();
            List <CategorySnapshot> categories = hccApp.CatalogServices.Categories.FindForMainMenu();

            foreach (CategorySnapshot category in categories)
            {
                string url = HccUrlBuilder.RouteHccUrl(HccRoute.Category, new { slug = category.RewriteUrl });
                categoriesMenu.Children.Add(new MenuNode {
                    Text = category.Name, Url = url, Enabled = true, Parent = categoriesMenu
                });
            }

            return(nodes);
        }