Esempio n. 1
0
        public void GetProductVariants_ReturnAllVariants()
        {
            var variants         = variantRepository.GetByProductId(skuWithVariants.SKUID).ToList();
            var firstVariant     = variants.FirstOrDefault();
            var enabledVariants  = variants.Where(v => v.Enabled);
            var disabledVariants = variants.Where(v => !v.Enabled);

            CMSAssert.All(
                () => Assert.AreEqual(SIZES.Length * COLORS.Length, variants.Count(), "Not all variants are returned."),
                () => Assert.AreEqual(2, firstVariant.ProductAttributes.Count(), "Variant has wrong option count"),
                () => Assert.IsTrue(firstVariant.ProductAttributes.Any(o => SIZES.Any(s => s.EqualsCSafe(o.SKUName))), "Variant do not contain correct option"),
                () => Assert.IsTrue(enabledVariants.Any(), "Enabled variants are not returned."),
                () => Assert.IsTrue(disabledVariants.Any(), "Disabled variants are not returned.")
                );
        }
Esempio n. 2
0
        private Variant GetCheapestVariant(SKUTreeNode product)
        {
            var variants        = mVariantRepository.GetByProductId(product.NodeSKUID).OrderBy(v => v.VariantPrice).ToList();
            var cheapestVariant = variants.FirstOrDefault();

            return(cheapestVariant);
        }
Esempio n. 3
0
        //EndDocSection:DisplayProduct

        //DocSection:DisplayVariant
        /// <summary>
        /// Displays product detail page of a product or a product variant specified by ID of the product's or variant's page.
        /// </summary>
        /// <param name="id">Node ID of the product's (variant's) page.</param>
        /// <param name="productAlias">Node alias of the product's (variant's) page.</param>
        public ActionResult Detail(int id, string productAlias)
        {
            // Gets the product from Kentico
            SKUTreeNode product = GetProduct(id);

            // If the product is not found or if it is not allowed for sale, redirects to error 404
            if ((product == 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 { id = product.NodeID, productAlias = product.NodeAlias }));
            }

            // Gets all product variants of the product
            List <Variant> variants = variantRepository.GetByProductId(product.NodeSKUID).OrderBy(v => v.VariantPrice).ToList();

            // Selects the first product variant
            Variant selectedVariant = variants.FirstOrDefault();

            // Calculates the price of the product or the variant
            ShoppingCart cart        = shoppingService.GetCurrentShoppingCart();
            ProductPrice priceDetail = selectedVariant != null?pricingService.CalculatePrice(selectedVariant, cart) : pricingService.CalculatePrice(product.SKU, cart);

            // Initializes the view model of the product or product variant
            ProductViewModel viewModel = new ProductViewModel(product, priceDetail, variants, selectedVariant?.VariantSKUID ?? 0);

            // Displays the product detail page
            return(View(viewModel));
        }
Esempio n. 4
0
        public ActionResult Detail()
        {
            var product = dataRetriever.Retrieve <SKUTreeNode>().Page;
            var sku     = product.SKU;

            // If a product is not found or not allowed for sale, redirect to 404
            if (!sku?.SKUEnabled ?? true)
            {
                return(HttpNotFound());
            }

            // all variants are disabled, redirect to 404
            var variants     = variantRepository.GetByProductId(product.NodeSKUID);
            var variantCount = variants.Count();

            if (variantCount > 0 && variantCount == variants.Count(i => !i.Variant.SKUEnabled))
            {
                return(HttpNotFound());
            }

            var viewModel = PrepareProductDetailViewModel(product);

            return(View(viewModel));
        }
            public void AllDisabledSkuVariants_Returns_HttpNotFoundResult()
            {
                sku.SKUEnabled     = true;
                variant.SKUEnabled = false;
                page.NodeSKUID.Returns(SKU_ID);
                var data = Substitute.For <IPageDataContext <SKUTreeNode> >();

                data.Page.Returns(page);

                var variants = new List <ProductVariant>()
                {
                    new ProductVariant(VARIANT_ID)
                };

                retiever.Retrieve <SKUTreeNode>().Returns(data);
                variantRepository.GetByProductId(SKU_ID).Returns(variants);

                var detail = controller.Detail();

                Assert.IsInstanceOf <HttpNotFoundResult>(detail);
            }
Esempio n. 6
0
        //EndDocSection:DifferentShippingAddress

        private object DummyEcommerceMethod()
        {
            IPricingService    pricingService     = null;
            ShoppingCart       shoppingCart       = null;
            SKUInfo            productSku         = null;
            Variant            variant            = null;
            IVariantRepository mVariantRepository = null;
            SKUTreeNode        product            = null;
            SKUInfo            sku   = null;
            DummyViewModel     model = null;
            Order             order  = null;
            PaymentResultInfo result = null;

            //DocSection:CalculatePriceOptions
            ProductPrice productPrice = pricingService.CalculatePrice(productSku, shoppingCart);
            //EndDocSection:CalculatePriceOptions

            //DocSection:FormatPriceOptions
            decimal price          = 5.50M;
            string  formattedPrice = shoppingCart.Currency.FormatPrice(price);
            //EndDocSection:FormatPriceOptions

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

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

            //DocSection:DisplayAttributeSelection
            // Gets the cheapest variant from the product
            List <Variant> variants        = mVariantRepository.GetByProductId(product.NodeSKUID).OrderBy(v => v.VariantPrice).ToList();
            Variant        cheapestVariant = variants.FirstOrDefault();

            // Gets the product's option categories.
            IEnumerable <ProductOptionCategory> categories = mVariantRepository.GetVariantOptionCategories(sku.SKUID);

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

            //EndDocSection:DisplayAttributeSelection

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

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

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

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