コード例 #1
0
        private void Initialize(ShippingRatesViewModel viewModel)
        {
            viewModel.NumberFormat = this._webStoreServices.NumberFormat;

            this._webStoreServices.UsingClient(
                c =>
            {
                Basket basket = c.BasketClient.GetBasket(this._webStoreServices.CurrentUserName, this._webStoreServices.BasketName);
                if (basket != null)
                {
                    IEnumerable <OrderSubset> physicalOrderSubsets = basket.OrderSubsets.Where(os => !os.IsVirtual);

                    if (physicalOrderSubsets.Any())
                    {
                        Dictionary <Guid, IEnumerable <ShippingRateValue> > availableShippingRates = c.BasketClient.GetShippingRateValues(this._webStoreServices.CurrentUserName, this._webStoreServices.BasketName, this._webStoreServices.CurrentCultureId);

                        viewModel.ShippingRatesByOrderSubset = physicalOrderSubsets.ToDictionary(
                            os => os.OrderSubsetId,
                            os => availableShippingRates.Where(asr => asr.Key == os.OrderSubsetId)
                            .SelectMany(asr => asr.Value.OrderBy(srv => srv.PriceTaxIncluded))
                            .ToList()
                            .AsEnumerable()
                            );

                        viewModel.ShippingRateValueSelections = physicalOrderSubsets.Select(os => new ShippingRatesViewModel.ShippingRateValueSelection {
                            OrderSubsetId = os.OrderSubsetId, ShippingRateCode = os.ShippingRateCode
                        })
                                                                .ToList();
                    }
                }
            }
                );
        }
コード例 #2
0
        public ActionResult EditShippingRates()
        {
            ShippingRatesViewModel viewModel = new ShippingRatesViewModel();

            this.Initialize(viewModel);

            return(this.BuildShippingRatesShapeResult(viewModel));
        }
コード例 #3
0
        public ActionResult SetShippingRates(ShippingRatesViewModel viewModel)
        {
            if (this.ModelState.IsValid)
            {
                String basketHash = null;

                Exception exception = this._webStoreServices.UsingClient(
                    c =>
                {
                    c.BasketClient.SetShippingRateValues(this._webStoreServices.CurrentUserName, this._webStoreServices.BasketName, viewModel.ShippingRateValueSelections.ToDictionary(srvs => srvs.OrderSubsetId, srvs => srvs.ShippingRateCode));
                    basketHash = c.BasketClient.GetBasketHash(this._webStoreServices.CurrentUserName, this._webStoreServices.BasketName);
                }
                    );

                return(this.Json(new { success = exception == null, basketHash = basketHash }));
            }
            else
            {
                this.Initialize(viewModel);
                return(this.BuildShippingRatesShapeResult(viewModel));
            }
        }
コード例 #4
0
 private ActionResult BuildShippingRatesShapeResult(ShippingRatesViewModel viewModel)
 {
     return(new ShapePartialResult(this, this._shapeFactory.EditorTemplate(TemplateName: "Checkout/ShippingRates", Model: viewModel)));
 }