Ejemplo n.º 1
0
        //EndDocSection:RemoveAllItems


        //DocSection:DetailUrl
        /// <summary>
        /// Redirects to a product detail page based on the ID of a product's SKU object.
        /// </summary>
        /// <param name="skuID">ID of the product's SKU object.</param>
        public IActionResult ItemDetail(int skuID)
        {
            // Gets the SKU object
            SKUInfo sku = skuInfo.Get(skuID);

            // If the SKU does not exist or it is a product option, returns error 404
            if (sku == null || sku.IsProductOption)
            {
                return(NotFound());
            }

            // If the SKU is a product variant, uses its parent product's ID
            if (sku.IsProductVariant)
            {
                skuID = sku.SKUParentSKUID;
            }

            // Gets the product's page
            TreeNode node = pageRetriever.Retrieve <TreeNode>(query => query
                                                              .Culture("en-us")
                                                              .CombineWithDefaultCulture()
                                                              .WhereEquals("NodeSKUID", skuID))
                            .FirstOrDefault();

            // Returns 404 if no page for the specified product exists
            if (node == null)
            {
                return(NotFound());
            }

            // Gets the product page's URL
            string pageUrl = pageUrlRetriever.Retrieve(node).AbsoluteUrl;

            return(Redirect(pageUrl));
        }
Ejemplo n.º 2
0
        public JsonResult Variant(int variantID)
        {
            // Gets SKU information based on the variant's ID
            SKUInfo variant = skuInfoProvider.Get(variantID);

            // If the variant is null, returns null
            if (variant == null)
            {
                return(null);
            }

            var cart = shoppingService.GetCurrentShoppingCart();

            // Calculates the price of the variant
            ProductCatalogPrices variantPrice = priceCalculatorFactory
                                                .GetCalculator(cart.ShoppingCartSiteID)
                                                .GetPrices(variant, Enumerable.Empty <SKUInfo>(), cart);

            // Finds out whether the variant is in stock
            bool isInStock = variant.SKUTrackInventory == TrackInventoryTypeEnum.Disabled || variant.SKUAvailableItems > 0;

            // Creates a JSON response for the JavaScript that switches the variants
            var response = new
            {
                totalPrice   = String.Format(cart.Currency.CurrencyFormatString, variantPrice.Price),
                inStock      = isInStock,
                stockMessage = isInStock ? "Yes" : "No"
            };

            // Returns the response
            return(Json(response));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns a variant with the specified identifier.
        /// </summary>
        /// <param name="variantId">Product variant's SKU object identifier.</param>
        /// <returns><see cref="ProductVariant"/> object representing a product variant with the specified identifier. Returns <c>null</c> if not found.</returns>
        public ProductVariant GetById(int variantId)
        {
            var sku = skuInfoProvider.Get(variantId);

            if (sku == null || sku.SKUSiteID != SiteContext.CurrentSiteID)
            {
                return(null);
            }

            return(new ProductVariant(variantId));
        }
Ejemplo n.º 4
0
        private IEnumerable <SKUInfo> GetOptions(int skuID, int categoryID, ISKUInfoProvider skuInfoProvider)
        {
            // Get all variant's options
            var variantOptionIDs = VariantOptionInfo.Provider.Get()
                                   .WhereIn("VariantSKUID", VariantHelper.GetVariants(skuID).Column("SKUID"))
                                   .Column("OptionSKUID");

            var variantOptionsList = skuInfoProvider.Get()
                                     .WhereIn("SKUID", variantOptionIDs)
                                     .OrderBy("SKUOrder")
                                     .ToList();

            // Create option categories with selectable variant options
            return(variantOptionsList.Where(o => o.SKUOptionCategoryID == categoryID));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Returns the product with the specified SKU identifier.
        /// </summary>
        /// <param name="skuId">The product or variant SKU identifier.</param>
        public SKUTreeNode GetProductForSKU(int skuId)
        {
            var sku = skuInfoProvider.Get(skuId);

            if ((sku == null) || sku.IsProductOption)
            {
                return(null);
            }

            if (sku.IsProductVariant)
            {
                skuId = sku.SKUParentSKUID;
            }

            return(pageRetriever.Retrieve <TreeNode>(
                       query => query
                       .WhereEquals("NodeSKUID", skuId),
                       cache => cache
                       .Key($"{nameof(KenticoProductRepository)}|{nameof(GetProductForSKU)}|{skuId}")
                       .Dependencies((_, builder) => builder.ObjectType("ecommerce.sku")))
                   .FirstOrDefault() as SKUTreeNode);
        }