Beispiel #1
0
        public IActionResult ShippingInfoSave(ShippingInfoModel requestModel)
        {
            if (!CanCheckout(out Cart cart))
            {
                return(R.Fail.Result);
            }
            var shippingRequired = CartHelper.IsShippingRequired(cart);

            if (!shippingRequired)
            {
                return(R.Success.Result);
            }
            if (cart.BillingAddressId == 0 || cart.ShippingAddressId == 0)
            {
                return(R.Fail.With("error", T("The address details were not provided")).Result);
            }
            if (cart.ShippingOptionsSerialized.IsNullEmptyOrWhiteSpace() || requestModel.ShippingOption == null || !requestModel.ShippingOption.Any())
            {
                return(R.Fail.With("error", T("No shipping options selected")).Result);
            }

            var shippingOptionModels =
                _dataSerializer.DeserializeAs <IList <WarehouseShippingOptionModel> >(cart.ShippingOptionsSerialized).SelectMany(x => x.ShippingOptions).ToList();
            var selectedOptions = new List <ShippingOptionModel>();

            foreach (var shippingOptionModel in requestModel.ShippingOption)
            {
                var shippingOptionId = shippingOptionModel.Id;
                var option           = shippingOptionModels.FirstOrDefault(x => x.Id == shippingOptionId);
                if (option == null)
                {
                    return(R.Fail.With("error", T("Could not find one of selected shipping option")).Result);
                }
                selectedOptions.Add(option);
            }

            var additionalFee = cart.CartItems.Sum(x => x.Product.AdditionalShippingCharge);

            //shipping handler validation
            if (requestModel.ShippingMethod != null)
            {
                //validate shipping method
                var shippingHandler = PluginHelper.GetShipmentHandler(requestModel.ShippingMethod.SystemName);
                if (shippingHandler == null || !shippingHandler.IsMethodAvailable(cart))
                {
                    return(R.Fail.With("error", T("Shipping method unavailable")).Result);
                }
                cart.ShippingMethodName        = requestModel.ShippingMethod.SystemName;
                cart.ShippingFee               = additionalFee + selectedOptions.Sum(x => x.Rate);
                cart.ShippingMethodDisplayName = shippingHandler.PluginInfo.Name;
            }

            cart.SelectedShippingOption = _dataSerializer.Serialize(ToShippingOptions(selectedOptions));
            _cartService.Update(cart);
            return(R.Success.Result);
        }
        public ActionResult ShippingMethod()
        {
            var shippingOptions = this.checkoutService.GetShippingOptions();

            var shippingInfos = new List <ShippingInfoModel>();

            foreach (var sho in shippingOptions)
            {
                var option = new ShippingInfoModel()
                {
                    OptionName = sho.Name,
                    OptionType = sho.ShippingOptionType.Value,
                    Selected   = sho.ShippingOptionType.Value == 0
                };

                shippingInfos.Add(option);
            }

            return(View("ShippingMethod", shippingInfos));
        }
Beispiel #3
0
        public ActionResult UpdateShippingInfo(ShippingInfoModel model)
        {
            /// -2: có lỗi xảy ra
            /// -1: đã tồn tại số phone, không update
            /// 0: insert bị lỗi
            /// > 0: insert thành công.
            var result = new CustomJsonResult()
            {
                Result = -2
            };

            try
            {
                /// check user info by store
                if (model.StoreId == 0)
                {
                    var storeInfo = GetStoreAccountInfo();
                    if (storeInfo != null && storeInfo.id > 0)
                    {
                        model.StoreId = storeInfo.id;
                    }
                }
                if (model.StoreId > 0)
                {
                    bool hasExists = _storeService.Admin_CheckPhoneUserInfoOfStore(model.StoreId, model.TypeUser, model.Phone);
                    // init
                    tblSender         _s = new tblSender();
                    tblRecipientsInfo _r = new tblRecipientsInfo();

                    switch ((OrderUserInfo)model.TypeUser)
                    {
                    case OrderUserInfo.Recipient:
                        _r = new tblRecipientsInfo
                        {
                            Phone      = model.Phone,
                            Add1       = model.AddressLine1,
                            Add2       = model.AddressLine2,
                            CityId     = model.CityId,
                            DistrictId = model.DistrictId,
                            FullName   = model.FullName,
                            StoreId    = model.StoreId,
                            WardId     = model.WardId
                        };
                        break;

                    default:
                    case OrderUserInfo.Sender:
                        _s = new tblSender
                        {
                            Phone    = model.Phone,
                            Add1     = model.AddressLine1,
                            Add2     = model.AddressLine2,
                            CityId   = model.CityId,
                            FullName = model.FullName,
                            StoreId  = model.StoreId,
                            StateId  = model.StateId,
                            Zip      = model.Zip,
                            Email    = model.Email
                        };
                        break;
                    }
                    if (!hasExists)
                    {
                        switch ((OrderUserInfo)model.TypeUser)
                        {
                        case OrderUserInfo.Recipient:
                            result.Result = _storeService.InsertReciever(_r);
                            break;

                        case OrderUserInfo.Sender:
                            result.Result = _storeService.InsertSender(_s);
                            break;
                        }
                    }
                    else
                    {
                        switch ((OrderUserInfo)model.TypeUser)
                        {
                        case OrderUserInfo.Recipient:
                            _r.id         = model.Id;
                            result.Result = _storeService.UpdateReciever(_r);
                            break;

                        case OrderUserInfo.Sender:
                            _s.Id         = model.Id;
                            result.Result = _storeService.UpdateSender(_s);
                            break;
                        }
                        //result.Result = -1;
                    }
                }
                else
                {
                    result.Message = "You dont have store info!";
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                Libraries.Log.Write(ex.Message);
            }
            return(Json(result));
        }
 public WayBillInfoModel()
 {
     ShippingInfo = new ShippingInfoModel();
     SenderInfo   = new SenderInfoModel();
 }