Esempio n. 1
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
        }
Esempio n. 2
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 = Service.Resolve <ICatalogPriceCalculatorFactory>()
                                                .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(SiteContext.CurrentSiteID).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:RedirectForManualPayment
            return(RedirectToAction("ThankYou", new { orderID = order.OrderID }));
            //EndDocSection:RedirectForManualPayment
        }