Exemplo n.º 1
0
        //EndDocSection:Constructor


        //DocSection:DisplayProduct
        /// <summary>
        /// Displays a product detail page of a product specified by the GUID of the product's page.
        /// </summary>
        /// <param name="guid">Node GUID of the product's page.</param>
        /// <param name="productAlias">Node alias of the product's page.</param>
        public ActionResult BasicDetail(Guid guid, string productAlias)
        {
            // Gets the product from the connected Kentico database
            SKUTreeNode product = GetProduct(guid);

            // If the product is not found or if it is not allowed for sale, redirects to error 404
            if ((product == null) || (product.SKU == null) || !product.SKU.SKUEnabled)
            {
                return(HttpNotFound());
            }

            // Redirects if the specified page alias does not match
            if (!string.IsNullOrEmpty(productAlias) && !product.NodeAlias.Equals(productAlias, StringComparison.InvariantCultureIgnoreCase))
            {
                return(RedirectToActionPermanent("Detail", new { guid = product.NodeGUID, productAlias = product.NodeAlias }));
            }

            // Initializes the view model of the product with a calculated price
            ShoppingCartInfo cart = shoppingService.GetCurrentShoppingCart();

            ProductCatalogPrices price = calculatorFactory
                                         .GetCalculator(cart.ShoppingCartSiteID)
                                         .GetPrices(product.SKU, Enumerable.Empty <SKUInfo>(), cart);

            // Fills the product model with retrieved data
            ProductViewModel viewModel = new ProductViewModel(product, price);

            // Displays the product details page
            return(View(viewModel));
        }
        /// <summary>
        /// Calculates and returns prices of the given product.
        /// </summary>
        /// <param name="product">Product to calculate prices for.</param>
        public ProductCatalogPrices CalculatePrice(SKUInfo product)
        {
            var cart = mShoppingService.GetCurrentShoppingCart();

            var prices = mCatalogPriceCalculatorFactory
                         .GetCalculator(cart.ShoppingCartSiteID)
                         .GetPrices(product, Enumerable.Empty <SKUInfo>(), cart);

            return(prices);
        }
Exemplo n.º 3
0
        //EndDocSection:Constructor


        //DocSection:DisplayProduct
        /// <summary>
        /// Displays a product detail page of a product.
        /// </summary>
        public IActionResult BasicDetail()
        {
            // Gets the product from the connected Xperience database
            SKUTreeNode product = GetProduct();

            // If the product is not found or if it is not allowed for sale, redirects to error 404
            if ((product == null) || (product.SKU == null) || !product.SKU.SKUEnabled)
            {
                return(NotFound());
            }

            // Initializes the view model of the product with a calculated price
            ShoppingCartInfo cart = shoppingService.GetCurrentShoppingCart();

            ProductCatalogPrices price = priceCalculatorFactory
                                         .GetCalculator(cart.ShoppingCartSiteID)
                                         .GetPrices(product.SKU, Enumerable.Empty <SKUInfo>(), cart);

            // Fills the product model with retrieved data
            ProductViewModel viewModel = new ProductViewModel(product, price);

            // Displays the product details page
            return(View("Detail", viewModel));
        }
Exemplo n.º 4
0
 // Retrieves a ProductCatalogPrices instance that contains calculated price information for the given product
 private ProductCatalogPrices GetPrice(SKUInfo product, ShoppingCartInfo cart)
 {
     return(calculatorFactory
            .GetCalculator(cart.ShoppingCartSiteID)
            .GetPrices(product, Enumerable.Empty <SKUInfo>(), cart));
 }
Exemplo n.º 5
0
        //EndDocSection:DifferentShippingAddress

        private object DummyEcommerceMethod()
        {
            ShoppingCartInfo  shoppingCart = null;
            SKUInfo           productSku   = null;
            ProductVariant    variant      = null;
            SKUTreeNode       product      = null;
            SKUInfo           sku          = null;
            DummyViewModel    model        = null;
            OrderInfo         order        = null;
            PaymentResultInfo result       = null;

            //DocSection:CalculatePriceOptions
            ProductCatalogPrices productPrice = catalogPriceCalculatorFactory
                                                .GetCalculator(shoppingCart.ShoppingCartSiteID)
                                                .GetPrices(productSku, Enumerable.Empty <SKUInfo>(), shoppingCart);
            //EndDocSection:CalculatePriceOptions

            //DocSection:FormatPriceOptions
            decimal price          = 5.50M;
            string  formattedPrice = String.Format(shoppingCart.Currency.CurrencyFormatString, price);
            //EndDocSection:FormatPriceOptions

            //DocSection:VariantDisplayImg
            var response = new
            {
                // ...

                imagePath = Url.Content(variant.Variant.SKUImagePath)
            };
            //EndDocSection:VariantDisplayImg

            //DocSection:DisplayAttributeSelection
            // Gets the cheapest variant of the product
            List <ProductVariant> variants = VariantHelper.GetVariants(product.NodeSKUID)
                                             .OnSite(siteService.CurrentSite.SiteID).ToList()
                                             .Select(s => new ProductVariant(s.SKUID))
                                             .OrderBy(v => v.Variant.SKUPrice)
                                             .ToList();

            ProductVariant cheapestVariant = variants.FirstOrDefault();

            // Gets the product's option categories
            IEnumerable <OptionCategoryInfo> categories = VariantHelper.GetProductVariantsCategories(sku.SKUID).ToList();

            // Gets the cheapest variant's selected attributes
            IEnumerable <ProductOptionCategoryViewModel> variantCategories = cheapestVariant?.ProductAttributes.Select(
                option =>
                new ProductOptionCategoryViewModel(sku.SKUID, option.SKUID,
                                                   categories.FirstOrDefault(c => c.CategoryID == option.SKUOptionCategoryID)));

            //EndDocSection:DisplayAttributeSelection

            //DocSection:ShippingIsDifferent
            if (model.IsShippingAddressDifferent)
            {
                // ...
            }
            //EndDocSection:ShippingIsDifferent

            //DocSection:DifferentPaymentMethods
            if (shoppingCart.PaymentOption.PaymentOptionName.Equals("PaymentMethodCodeName"))
            {
                return(RedirectToAction("ActionForPayment", "MyPaymentGateway"));
            }
            //EndDocSection:DifferentPaymentMethods

            //DocSection:SetPaymentResult
            order.UpdateOrderStatus(result);
            //EndDocSection:SetPaymentResult

            //DocSection:ImageUrl
            // Returns the relative path to the image of the provided product
            string relativeUrl = new FileUrl(sku.SKUImagePath, true).RelativePath;

            //EndDocSection:ImageUrl

            //DocSection:RedirectForManualPayment
            return(RedirectToAction("ThankYou", new { orderID = order.OrderID }));
            //EndDocSection:RedirectForManualPayment
        }