public override ActionResult Index(RenderModel model)
        {
            var shipping = new ShippingViewModel();

            shipping.AvailableShippingMethods = new List <SelectListItem>();

            var shippingInformation = TransactionLibrary.GetShippingInformation();

            var availableShippingMethods = TransactionLibrary.GetShippingMethods(shippingInformation.Country);

            var basket = TransactionLibrary.GetBasket().PurchaseOrder;

            shipping.SelectedShippingMethodId = basket.Shipments.FirstOrDefault() != null
                ? basket.Shipments.FirstOrDefault().ShippingMethod.ShippingMethodId : -1;

            foreach (var availableShippingMethod in availableShippingMethods)
            {
                var price          = availableShippingMethod.GetPriceForCurrency(basket.BillingCurrency);
                var formattedprice = new Money((price == null ? 0 : price.Price), basket.BillingCurrency);

                shipping.AvailableShippingMethods.Add(new SelectListItem()
                {
                    Selected = shipping.SelectedShippingMethodId == availableShippingMethod.ShippingMethodId,
                    Text     = String.Format(" {0} ({1})", availableShippingMethod.Name, formattedprice),
                    Value    = availableShippingMethod.ShippingMethodId.ToString()
                });
            }

            shipping.ShippingCountry = shippingInformation.Country.Name;

            return(base.View("/Views/Shipping.cshtml", shipping));
        }
        public ActionResult Index()
        {
            var shippingModel = new ShippingViewModel();

            shippingModel.AvailableShippingMethods = new List <SelectListItem>();

            var shippingCountry          = TransactionLibrary.GetShippingInformation().Country;
            var availableShippingMethods = TransactionLibrary.GetShippingMethods(shippingCountry);

            var selectedShipping = TransactionLibrary.GetBasket(false).PurchaseOrder.Shipments.FirstOrDefault();

            foreach (var availableShippingMethod in availableShippingMethods)
            {
                shippingModel.AvailableShippingMethods.Add(new SelectListItem()
                {
                    Selected = selectedShipping != null &&
                               selectedShipping.ShippingMethod.ShippingMethodId ==
                               availableShippingMethod.ShippingMethodId,
                    Text  = availableShippingMethod.Name,
                    Value = availableShippingMethod.ShippingMethodId.ToString()
                });
            }

            return(View("/Views/Shipping.cshtml", shippingModel));
        }
Ejemplo n.º 3
0
        private ReadOnlyCollection <global::Sitecore.Commerce.Entities.Shipping.ShippingMethod> GetCommerceConnectShippingMethods(Country country)
        {
            var mapper = ObjectFactory.Instance.Resolve <IMapping <ShippingMethod, global::Sitecore.Commerce.Entities.Shipping.ShippingMethod> >("ShippingMethodToShippingMethod");

            var shippingMethods = country == null?TransactionLibrary.GetShippingMethods() : TransactionLibrary.GetShippingMethods(country);

            IList <global::Sitecore.Commerce.Entities.Shipping.ShippingMethod> cCshippingMethods = shippingMethods.Select(shippingMethod => mapper.Map(shippingMethod)).ToList();

            return(new ReadOnlyCollection <global::Sitecore.Commerce.Entities.Shipping.ShippingMethod>(cCshippingMethods));
        }
Ejemplo n.º 4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                return;
            }

            var basket        = TransactionLibrary.GetBasket().PurchaseOrder;
            var firstShipment = basket.Shipments.First();

            var shippingMethods = TransactionLibrary.GetShippingMethods(firstShipment.ShipmentAddress.Country);

            AvailableShipmentMethods.DataSource = shippingMethods;
            AvailableShipmentMethods.DataBind();
        }
    private List <ShippingMethod> GetShippingMethods()
    {
        List <ShippingMethod> availableShippingMethods;
        bool showForCurrentCountry = ValidationHelper.GetBoolean(GetValue("ShowForCurrentCountry"), true);

        if (showForCurrentCountry)
        {
            availableShippingMethods = TransactionLibrary.GetShippingMethods().ToList();
        }
        else
        {
            var shippingMethods = ObjectFactory.Instance.Resolve <IRepository <ShippingMethod> >();
            availableShippingMethods = shippingMethods.Select(x => !x.Deleted).ToList();
        }

        return(availableShippingMethods);
    }