コード例 #1
0
        public IHttpActionResult EstimatePost(ShippingEstimateModel shippingEstimateModel)
        {
            if (ModelState.IsValid)
            {
                var helper = new CartHelper(CartHelper.CartName);

                //Find best shipping method
	            var store = StoreHelper.StoreClient.GetCurrentStore();
	            var storeShippingMethods = helper.ShippingClient.GetAllShippingMethods()
					  .Where(sm => sm.PaymentMethodShippingMethods.Select(x => x.PaymentMethod)
		                   .Any(pm => store.PaymentGateways.Any(pg => pg.PaymentGateway == pm.Name)))
						   .Select(s=>s.ShippingMethodId).ToList();
				var bestShipping = helper.GetShippingMethods(storeShippingMethods).Min();

                //Update line items
                foreach (var lineItem in helper.OrderForm.LineItems)
                {
                    lineItem.ShippingMethodId = bestShipping.Id;
                    lineItem.ShippingMethodName = bestShipping.DisplayName;
                }

                // run workflow
                helper.RunWorkflow("ShoppingCartPrepareWorkflow");
                helper.SaveChanges();

                return Ok(bestShipping);
            }

            return BadRequest();
        }
コード例 #2
0
ファイル: CartController.cs プロジェクト: Wdovin/vc-community
        public HttpResponseMessage EstimatePost(ShippingEstimateModel shippingEstimateModel)
        {
            if (ModelState.IsValid)
            {
                var helper = new CartHelper(CartHelper.CartName);

                //Find best shipping method
	            var store = StoreHelper.StoreClient.GetCurrentStore();
	            var storeShippingMethods = helper.ShippingClient.GetAllShippingMethods()
					  .Where(sm => sm.PaymentMethodShippingMethods.Select(x => x.PaymentMethod)
		                   .Any(pm => store.PaymentGateways.Any(pg => pg.PaymentGateway == pm.Name)))
						   .Select(s=>s.ShippingMethodId).ToList();
				var bestShipping = helper.GetShippingMethods(storeShippingMethods).Min();

                //Update line items
                foreach (var lineItem in helper.OrderForm.LineItems)
                {
                    lineItem.ShippingMethodId = bestShipping.Id;
                    lineItem.ShippingMethodName = bestShipping.DisplayName;
                }

                // run workflow
                helper.RunWorkflow("ShoppingCartPrepareWorkflow");
                helper.SaveChanges();

                var response = Request.CreateResponse(HttpStatusCode.OK);
                var bShippingJson = System.Web.Helpers.Json.Encode(bestShipping);
                response.Content = new StringContent(bShippingJson);
                return response;
            }

            return Request.CreateResponse(HttpStatusCode.BadRequest);
        }