本文整理汇总了C#中Nop.Web.Models.ShoppingCart.ShoppingCartModel类的典型用法代码示例。如果您正苦于以下问题:C# ShoppingCartModel类的具体用法?C# ShoppingCartModel怎么用?C# ShoppingCartModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ShoppingCartModel类属于Nop.Web.Models.ShoppingCart命名空间,在下文中一共展示了ShoppingCartModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RemoveGiftardCode
public ActionResult RemoveGiftardCode(int giftCardId)
{
var cart = _workContext.CurrentCustomer.ShoppingCartItems.Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart).ToList();
var model = new ShoppingCartModel();
var gc = _giftCardService.GetGiftCardById(giftCardId);
if (gc != null)
{
_workContext.CurrentCustomer.RemoveGiftCardCouponCode(gc.GiftCardCouponCode);
_customerService.UpdateCustomer(_workContext.CurrentCustomer);
}
PrepareShoppingCartModel(model, cart);
return View(model);
}
示例2: UpdateCartItem
public ActionResult UpdateCartItem(FormCollection form)
{
if (!_permissionService.Authorize(StandardPermissionProvider.EnableShoppingCart))
return RedirectToRoute("HomePage");
//get shopping cart item identifier
int sciId = 0;
foreach (var formValue in form.AllKeys)
if (formValue.StartsWith("updatecartitem-", StringComparison.InvariantCultureIgnoreCase))
sciId = Convert.ToInt32(formValue.Substring("updatecartitem-".Length));
//get shopping cart item
var cart = _workContext.CurrentCustomer.ShoppingCartItems
.Where(x => x.ShoppingCartType == ShoppingCartType.ShoppingCart).ToList();
var sci = cart.Where(x => x.Id == sciId).FirstOrDefault();
if (sci == null)
{
return RedirectToRoute("ShoppingCart");
}
//update the cart item
var warnings = new List<string>();
foreach (string formKey in form.AllKeys)
if (formKey.Equals(string.Format("itemquantity{0}", sci.Id), StringComparison.InvariantCultureIgnoreCase))
{
int newQuantity = sci.Quantity;
if (int.TryParse(form[formKey], out newQuantity))
{
warnings.AddRange(_shoppingCartService.UpdateShoppingCartItem(_workContext.CurrentCustomer,
sci.Id, newQuantity, true));
}
break;
}
//updated cart
cart = _workContext.CurrentCustomer.ShoppingCartItems.Where(x => x.ShoppingCartType == ShoppingCartType.ShoppingCart).ToList();
var model = new ShoppingCartModel();
PrepareShoppingCartModel(model, cart);
//update current warnings
//find model
var sciModel = model.Items.Where(x => x.Id == sciId).FirstOrDefault();
if (sciModel != null)
foreach (var w in warnings)
if (!sciModel.Warnings.Contains(w))
sciModel.Warnings.Add(w);
return View(model);
}
示例3: GetEstimateShipping
public ActionResult GetEstimateShipping(EstimateShippingModel shippingModel, FormCollection form)
{
var cart = _workContext.CurrentCustomer.ShoppingCartItems
.Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart)
.LimitPerStore(_storeContext.CurrentStore.Id)
.ToList();
//parse and save checkout attributes
ParseAndSaveCheckoutAttributes(cart, form);
var model = new ShoppingCartModel();
model.EstimateShipping.CountryId = shippingModel.CountryId;
model.EstimateShipping.StateProvinceId = shippingModel.StateProvinceId;
model.EstimateShipping.ZipPostalCode = shippingModel.ZipPostalCode;
PrepareShoppingCartModel(model, cart,setEstimateShippingDefaultAddress: false);
if (cart.RequiresShipping())
{
var address = new Address()
{
CountryId = shippingModel.CountryId,
Country = shippingModel.CountryId.HasValue ? _countryService.GetCountryById(shippingModel.CountryId.Value) : null,
StateProvinceId = shippingModel.StateProvinceId,
StateProvince = shippingModel.StateProvinceId.HasValue ? _stateProvinceService.GetStateProvinceById(shippingModel.StateProvinceId.Value) : null,
ZipPostalCode = shippingModel.ZipPostalCode,
};
GetShippingOptionResponse getShippingOptionResponse = _shippingService
.GetShippingOptions(cart, address, "", _storeContext.CurrentStore.Id);
if (!getShippingOptionResponse.Success)
{
foreach (var error in getShippingOptionResponse.Errors)
model.EstimateShipping.Warnings.Add(error);
}
else
{
if (getShippingOptionResponse.ShippingOptions.Count > 0)
{
foreach (var shippingOption in getShippingOptionResponse.ShippingOptions)
{
var soModel = new EstimateShippingModel.ShippingOptionModel()
{
Name = shippingOption.Name,
Description = shippingOption.Description,
};
//calculate discounted and taxed rate
Discount appliedDiscount = null;
decimal shippingTotal = _orderTotalCalculationService.AdjustShippingRate(shippingOption.Rate,
cart, out appliedDiscount);
decimal rateBase = _taxService.GetShippingPrice(shippingTotal, _workContext.CurrentCustomer);
decimal rate = _currencyService.ConvertFromPrimaryStoreCurrency(rateBase, _workContext.WorkingCurrency);
soModel.Price = _priceFormatter.FormatShippingPrice(rate, true);
model.EstimateShipping.ShippingOptions.Add(soModel);
}
//pickup in store?
if (_shippingSettings.AllowPickUpInStore)
{
var soModel = new EstimateShippingModel.ShippingOptionModel()
{
Name = _localizationService.GetResource("Checkout.PickUpInStore"),
Description = _localizationService.GetResource("Checkout.PickUpInStore.Description"),
Price = _priceFormatter.FormatShippingPrice(decimal.Zero, true)
};
model.EstimateShipping.ShippingOptions.Add(soModel);
}
}
else
{
model.EstimateShipping.Warnings.Add(_localizationService.GetResource("Checkout.ShippingIsNotAllowed"));
}
}
}
return View(model);
}
示例4: UpdateCartForRemove
public ActionResult UpdateCartForRemove(FormCollection form)
{
if (!_permissionService.Authorize(StandardPermissionProvider.EnableShoppingCart))
return RedirectToRoute("HomePage");
var cart = _workContext.CurrentCustomer.ShoppingCartItems
.Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart)
.LimitPerStore(_storeContext.CurrentStore.Id)
.ToList();
var allIdsToRemove = form["removeProduct"] != null ? form["removeProduct"].Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToList() : new List<int>();
//current warnings <cart item identifier, warnings>
var innerWarnings = new Dictionary<int, IList<string>>();
foreach (var sci in cart)
{
bool remove = allIdsToRemove.Contains(sci.Id);
if (remove)
_shoppingCartService.DeleteShoppingCartItem(sci, ensureOnlyActiveCheckoutAttributes: true);
}
//updated cart
cart = _workContext.CurrentCustomer.ShoppingCartItems
.Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart)
.LimitPerStore(_storeContext.CurrentStore.Id)
.ToList();
var model = new ShoppingCartModel();
PrepareShoppingCartModel(model, cart);
//update current warnings
foreach (var kvp in innerWarnings)
{
//kvp = <cart item identifier, warnings>
var sciId = kvp.Key;
var warnings = kvp.Value;
//find model
var sciModel = model.Items.FirstOrDefault(x => x.Id == sciId);
if (sciModel != null)
foreach (var w in warnings)
if (!sciModel.Warnings.Contains(w))
sciModel.Warnings.Add(w);
}
return View(model);
}
示例5: PrepareShoppingCartModel
protected virtual void PrepareShoppingCartModel(ShoppingCartModel model,
IList<ShoppingCartItem> cart, bool isEditable = true,
bool validateCheckoutAttributes = false,
bool prepareEstimateShippingIfEnabled = true, bool setEstimateShippingDefaultAddress = true,
bool prepareAndDisplayOrderReviewData = false)
{
if (cart == null)
throw new ArgumentNullException("cart");
if (model == null)
throw new ArgumentNullException("model");
if (cart.Count == 0)
return;
#region Simple properties
model.IsEditable = isEditable;
model.ShowProductImages = _shoppingCartSettings.ShowProductImagesOnShoppingCart;
model.ShowSku = _catalogSettings.ShowProductSku;
var checkoutAttributesXml = _workContext.CurrentCustomer.GetAttribute<string>(SystemCustomerAttributeNames.CheckoutAttributes, _genericAttributeService, _storeContext.CurrentStore.Id);
model.CheckoutAttributeInfo = _checkoutAttributeFormatter.FormatAttributes(checkoutAttributesXml, _workContext.CurrentCustomer);
bool minOrderSubtotalAmountOk = _orderProcessingService.ValidateMinOrderSubtotalAmount(cart);
if (!minOrderSubtotalAmountOk)
{
decimal minOrderSubtotalAmount = _currencyService.ConvertFromPrimaryStoreCurrency(_orderSettings.MinOrderSubtotalAmount, _workContext.WorkingCurrency);
model.MinOrderSubtotalWarning = string.Format(_localizationService.GetResource("Checkout.MinOrderSubtotalAmount"), _priceFormatter.FormatPrice(minOrderSubtotalAmount, true, false));
}
model.TermsOfServiceOnShoppingCartPage = _orderSettings.TermsOfServiceOnShoppingCartPage;
model.TermsOfServiceOnOrderConfirmPage = _orderSettings.TermsOfServiceOnOrderConfirmPage;
model.OnePageCheckoutEnabled = _orderSettings.OnePageCheckoutEnabled;
//gift card and gift card boxes
model.DiscountBox.Display= _shoppingCartSettings.ShowDiscountBox;
var discountCouponCode = _workContext.CurrentCustomer.GetAttribute<string>(SystemCustomerAttributeNames.DiscountCouponCode);
var discount = _discountService.GetDiscountByCouponCode(discountCouponCode);
if (discount != null &&
discount.RequiresCouponCode &&
_discountService.IsDiscountValid(discount, _workContext.CurrentCustomer))
model.DiscountBox.CurrentCode = discount.CouponCode;
model.GiftCardBox.Display = _shoppingCartSettings.ShowGiftCardBox;
//cart warnings
var cartWarnings = _shoppingCartService.GetShoppingCartWarnings(cart, checkoutAttributesXml, validateCheckoutAttributes);
foreach (var warning in cartWarnings)
model.Warnings.Add(warning);
#endregion
#region Checkout attributes
var checkoutAttributes = _checkoutAttributeService.GetAllCheckoutAttributes(_storeContext.CurrentStore.Id, !cart.RequiresShipping());
foreach (var attribute in checkoutAttributes)
{
var caModel = new ShoppingCartModel.CheckoutAttributeModel()
{
Id = attribute.Id,
Name = attribute.GetLocalized(x => x.Name),
TextPrompt = attribute.GetLocalized(x => x.TextPrompt),
IsRequired = attribute.IsRequired,
AttributeControlType = attribute.AttributeControlType,
DefaultValue = attribute.DefaultValue
};
if (!String.IsNullOrEmpty(attribute.ValidationFileAllowedExtensions))
{
caModel.AllowedFileExtensions = attribute.ValidationFileAllowedExtensions
.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
.ToList();
}
if (attribute.ShouldHaveValues())
{
//values
var caValues = _checkoutAttributeService.GetCheckoutAttributeValues(attribute.Id);
foreach (var caValue in caValues)
{
var pvaValueModel = new ShoppingCartModel.CheckoutAttributeValueModel()
{
Id = caValue.Id,
Name = caValue.GetLocalized(x => x.Name),
ColorSquaresRgb = caValue.ColorSquaresRgb,
IsPreSelected = caValue.IsPreSelected,
};
caModel.Values.Add(pvaValueModel);
//display price if allowed
if (_permissionService.Authorize(StandardPermissionProvider.DisplayPrices))
{
decimal priceAdjustmentBase = _taxService.GetCheckoutAttributePrice(caValue);
decimal priceAdjustment = _currencyService.ConvertFromPrimaryStoreCurrency(priceAdjustmentBase, _workContext.WorkingCurrency);
if (priceAdjustmentBase > decimal.Zero)
pvaValueModel.PriceAdjustment = "+" + _priceFormatter.FormatPrice(priceAdjustment);
else if (priceAdjustmentBase < decimal.Zero)
pvaValueModel.PriceAdjustment = "-" + _priceFormatter.FormatPrice(-priceAdjustment);
}
}
}
//set already selected attributes
string selectedCheckoutAttributes = _workContext.CurrentCustomer.GetAttribute<string>(SystemCustomerAttributeNames.CheckoutAttributes, _genericAttributeService, _storeContext.CurrentStore.Id);
//.........这里部分代码省略.........
示例6: ApplyGiftCard
public ActionResult ApplyGiftCard(string giftcardcouponcode, FormCollection form)
{
var cart = _workContext.CurrentCustomer.ShoppingCartItems
.Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart)
.LimitPerStore(_storeContext.CurrentStore.Id)
.ToList();
//parse and save checkout attributes
ParseAndSaveCheckoutAttributes(cart, form);
var model = new ShoppingCartModel();
if (!cart.IsRecurring())
{
if (!String.IsNullOrWhiteSpace(giftcardcouponcode))
{
var giftCard = _giftCardService.GetAllGiftCards(giftCardCouponCode: giftcardcouponcode).FirstOrDefault();
bool isGiftCardValid = giftCard != null && giftCard.IsGiftCardValid();
if (isGiftCardValid)
{
_workContext.CurrentCustomer.ApplyGiftCardCouponCode(giftcardcouponcode);
_customerService.UpdateCustomer(_workContext.CurrentCustomer);
model.GiftCardBox.Message = _localizationService.GetResource("ShoppingCart.GiftCardCouponCode.Applied");
}
else
model.GiftCardBox.Message = _localizationService.GetResource("ShoppingCart.GiftCardCouponCode.WrongGiftCard");
}
else
model.GiftCardBox.Message = _localizationService.GetResource("ShoppingCart.GiftCardCouponCode.WrongGiftCard");
}
else
model.GiftCardBox.Message = _localizationService.GetResource("ShoppingCart.GiftCardCouponCode.DontWorkWithAutoshipProducts");
PrepareShoppingCartModel(model, cart);
return View(model);
}
示例7: PrepareShoppingCartModel
protected ShoppingCartModel PrepareShoppingCartModel(ShoppingCartModel model,
IList<ShoppingCartItem> cart, bool isEditable, bool setEstimateShippingDefaultAddress = true)
{
if (cart == null)
throw new ArgumentNullException("cart");
if (model == null)
throw new ArgumentNullException("model");
if (cart.Count == 0)
return model;
#region Simple properties
model.IsEditable = isEditable;
model.ShowProductImages = _shoppingCartSettings.ShowProductImagesOnShoppingCart;
model.ShowSku = _catalogSettings.ShowProductSku;
model.CheckoutAttributeInfo = _checkoutAttributeFormatter.FormatAttributes(_workContext.CurrentCustomer.CheckoutAttributes, _workContext.CurrentCustomer);
bool minOrderSubtotalAmountOk = _orderProcessingService.ValidateMinOrderSubtotalAmount(cart);
if (!minOrderSubtotalAmountOk)
{
decimal minOrderSubtotalAmount = _currencyService.ConvertFromPrimaryStoreCurrency(_orderSettings.MinOrderSubtotalAmount, _workContext.WorkingCurrency);
model.MinOrderSubtotalWarning = string.Format(_localizationService.GetResource("Checkout.MinOrderSubtotalAmount"), _priceFormatter.FormatPrice(minOrderSubtotalAmount, true, false));
}
model.TermsOfServiceEnabled = _orderSettings.TermsOfServiceEnabled;
//gift card and gift card boxes
model.ShowDiscountBox = _shoppingCartSettings.ShowDiscountBox;
var currentDiscountWithCode = _discountService.GetDiscountByCouponCode(_workContext.CurrentCustomer.DiscountCouponCode);
model.CurrentDiscountCode = currentDiscountWithCode != null && currentDiscountWithCode.RequiresCouponCode
? currentDiscountWithCode.CouponCode : null;
model.ShowGiftCardBox = _shoppingCartSettings.ShowGiftCardBox;
//cart warnings
var cartWarnings = _shoppingCartService.GetShoppingCartWarnings(cart, "", false);
foreach (var warning in cartWarnings)
model.Warnings.Add(warning);
#endregion
#region Checkout attributes
var checkoutAttributes = _checkoutAttributeService.GetAllCheckoutAttributes(!cart.RequiresShipping());
foreach (var attribute in checkoutAttributes)
{
var caModel = new ShoppingCartModel.CheckoutAttributeModel()
{
Id = attribute.Id,
Name = attribute.GetLocalized(x => x.Name),
TextPrompt = attribute.TextPrompt,
IsRequired = attribute.IsRequired,
AttributeControlType = attribute.AttributeControlType
};
if (attribute.ShouldHaveValues())
{
//values
var caValues = _checkoutAttributeService.GetCheckoutAttributeValues(attribute.Id);
foreach (var caValue in caValues)
{
var pvaValueModel = new ShoppingCartModel.CheckoutAttributeValueModel()
{
Id = caValue.Id,
Name = caValue.GetLocalized(x => x.Name),
IsPreSelected = caValue.IsPreSelected
};
caModel.Values.Add(pvaValueModel);
//display price if allowed
if (_permissionService.Authorize(StandardPermissionProvider.DisplayPrices))
{
decimal priceAdjustmentBase = _taxService.GetCheckoutAttributePrice(caValue);
decimal priceAdjustment = _currencyService.ConvertFromPrimaryStoreCurrency(priceAdjustmentBase, _workContext.WorkingCurrency);
if (priceAdjustmentBase > decimal.Zero)
pvaValueModel.PriceAdjustment = "+" + _priceFormatter.FormatPrice(priceAdjustment);
else if (priceAdjustmentBase < decimal.Zero)
pvaValueModel.PriceAdjustment = "-" + _priceFormatter.FormatPrice(-priceAdjustment);
}
}
}
//set already selected attributes
string selectedCheckoutAttributes = _workContext.CurrentCustomer.CheckoutAttributes;
switch (attribute.AttributeControlType)
{
case AttributeControlType.DropdownList:
case AttributeControlType.RadioList:
case AttributeControlType.Checkboxes:
{
if (!String.IsNullOrEmpty(selectedCheckoutAttributes))
{
//clear default selection
foreach (var item in caModel.Values)
item.IsPreSelected = false;
//select new values
var selectedCaValues = _checkoutAttributeParser.ParseCheckoutAttributeValues(selectedCheckoutAttributes);
foreach (var caValue in selectedCaValues)
foreach (var item in caModel.Values)
if (caValue.Id == item.Id)
//.........这里部分代码省略.........
示例8: StartCheckout
public ActionResult StartCheckout(FormCollection form)
{
var cart = _workContext.CurrentCustomer.ShoppingCartItems
.Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart)
.LimitPerStore(_storeContext.CurrentStore.Id)
.ToList();
//parse and save checkout attributes
ParseAndSaveCheckoutAttributes(cart, form);
//validate attributes
string checkoutAttributes = _workContext.CurrentCustomer.GetAttribute<string>(SystemCustomerAttributeNames.CheckoutAttributes, _genericAttributeService, _storeContext.CurrentStore.Id);
var checkoutAttributeWarnings = _shoppingCartService.GetShoppingCartWarnings(cart, checkoutAttributes, true);
if (checkoutAttributeWarnings.Count > 0)
{
//something wrong, redisplay the page with warnings
var model = new ShoppingCartModel();
PrepareShoppingCartModel(model, cart, validateCheckoutAttributes: true);
return View(model);
}
//everything is OK
if (_workContext.CurrentCustomer.IsGuest())
{
if (_orderSettings.AnonymousCheckoutAllowed)
{
return RedirectToRoute("LoginCheckoutAsGuest", new {returnUrl = Url.RouteUrl("ShoppingCart")});
}
else
{
return new HttpUnauthorizedResult();
}
}
else
{
return RedirectToRoute("Checkout");
}
}
示例9: PrepareShoppingCartModel
protected override void PrepareShoppingCartModel(ShoppingCartModel model,
IList<ShoppingCartItem> cart, bool isEditable = true,
bool validateCheckoutAttributes = false,
bool prepareEstimateShippingIfEnabled = true, bool setEstimateShippingDefaultAddress = true,
bool prepareAndDisplayOrderReviewData = false)
{
if (_promoSettings.Enabled)
{
List<string> cartWarnings = _promoService.ProcessShoppingCart();
// refresh the cart, in case any changes were made
cart = (from cartItem in _workContext.CurrentCustomer.ShoppingCartItems where cartItem.ShoppingCartType.Equals(ShoppingCartType.ShoppingCart) select cartItem).ToList();
foreach (string cartWarning in cartWarnings)
{
model.Warnings.Add(cartWarning);
}
}
// Get the base to do most of the work...
base.PrepareShoppingCartModel(model, cart, isEditable, validateCheckoutAttributes, prepareEstimateShippingIfEnabled, setEstimateShippingDefaultAddress, prepareAndDisplayOrderReviewData);
if (_promoSettings.Enabled)
{
var basketResponse = _promoUtilities.GetBasketResponse();
if (basketResponse.IsValid())
{
if (basketResponse.TotalDiscount != decimal.Zero)
{
cart.Where(sci => !sci.Product.CallForPrice)
.ToList()
.ForEach(sci =>
{
var cartItemModel = model.Items.Where(mi => mi.Id == sci.Id).FirstOrDefault();
//sub total
Discount scDiscount;
decimal shoppingCartItemDiscountBase;
decimal taxRate;
decimal tempSubTotal = _promosPriceCalculationService.GetSubTotal(sci, true, out shoppingCartItemDiscountBase, out scDiscount);
decimal shoppingCartItemSubTotalWithDiscountBase = _taxService.GetProductPrice(sci.Product, tempSubTotal, out taxRate);
decimal shoppingCartItemSubTotalWithDiscount = _currencyService.ConvertFromPrimaryStoreCurrency(shoppingCartItemSubTotalWithDiscountBase, _workContext.WorkingCurrency);
cartItemModel.SubTotal = _priceFormatter.FormatPrice(shoppingCartItemSubTotalWithDiscount);
//display an applied discount amount
if (scDiscount != null)
{
shoppingCartItemDiscountBase = _taxService.GetProductPrice(sci.Product, shoppingCartItemDiscountBase, out taxRate);
if (shoppingCartItemDiscountBase > decimal.Zero)
{
decimal shoppingCartItemDiscount = _currencyService.ConvertFromPrimaryStoreCurrency(shoppingCartItemDiscountBase, _workContext.WorkingCurrency);
cartItemModel.Discount = _priceFormatter.FormatPrice(shoppingCartItemDiscount);
}
}
});
}
model.DiscountBox.Message = string.Empty;
model.DiscountBox.CurrentCode = _workContext.CurrentCustomer.GetAttribute<string>(SystemCustomerAttributeNames.DiscountCouponCode);
if (!string.IsNullOrEmpty(model.DiscountBox.CurrentCode))
{
if (basketResponse.CouponIsValid(model.DiscountBox.CurrentCode))
{
model.DiscountBox.IsApplied = true;
model.DiscountBox.Message = _localizationService.GetResource("ShoppingCart.DiscountCouponCode.Applied");
}
else
{
model.DiscountBox.IsApplied = false;
model.DiscountBox.Message = _localizationService.GetResource("ShoppingCart.DiscountCouponCode.WrongDiscount");
}
}
}
}
}
示例10: ApplyDiscountCoupon
public ActionResult ApplyDiscountCoupon(string discountcouponcode, FormCollection form)
{
var cart = _workContext.CurrentCustomer.ShoppingCartItems
.Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart)
.LimitPerStore(_storeContext.CurrentStore.Id)
.ToList();
//parse and save checkout attributes
ParseAndSaveCheckoutAttributes(cart, form);
var model = new ShoppingCartModel();
if (!String.IsNullOrWhiteSpace(discountcouponcode))
{
//we find even hidden records here. this way we can display a user-friendly message if it's expired
var discount = _discountService.GetDiscountByCouponCode(discountcouponcode, true);
if (discount != null && discount.RequiresCouponCode)
{
var validationResult = _discountService.ValidateDiscount(discount, _workContext.CurrentCustomer, discountcouponcode);
if (validationResult.IsValid)
{
//valid
_genericAttributeService.SaveAttribute(_workContext.CurrentCustomer, SystemCustomerAttributeNames.DiscountCouponCode, discountcouponcode);
model.DiscountBox.Message = _localizationService.GetResource("ShoppingCart.DiscountCouponCode.Applied");
model.DiscountBox.IsApplied = true;
}
else
{
if (!String.IsNullOrEmpty(validationResult.UserError))
{
//some user error
model.DiscountBox.Message = validationResult.UserError;
model.DiscountBox.IsApplied = false;
}
else
{
//general error text
model.DiscountBox.Message = _localizationService.GetResource("ShoppingCart.DiscountCouponCode.WrongDiscount");
model.DiscountBox.IsApplied = false;
}
}
}
else
{
//discount cannot be found
model.DiscountBox.Message = _localizationService.GetResource("ShoppingCart.DiscountCouponCode.WrongDiscount");
model.DiscountBox.IsApplied = false;
}
}
else
{
//empty coupon code
model.DiscountBox.Message = _localizationService.GetResource("ShoppingCart.DiscountCouponCode.WrongDiscount");
model.DiscountBox.IsApplied = false;
}
PrepareShoppingCartModel(model, cart);
return View(model);
}
示例11: StartAlbionCheckout
//.........这里部分代码省略.........
selectedAttributes = _checkoutAttributeParser.AddCheckoutAttribute(selectedAttributes,
attribute, selectedAttributeId.ToString());
}
}
}
break;
case AttributeControlType.TextBox:
{
var txtAttribute = form[controlId];
if (!String.IsNullOrEmpty(txtAttribute))
{
string enteredText = txtAttribute.Trim();
selectedAttributes = _checkoutAttributeParser.AddCheckoutAttribute(selectedAttributes,
attribute, enteredText);
}
}
break;
case AttributeControlType.MultilineTextbox:
{
var txtAttribute = form[controlId];
if (!String.IsNullOrEmpty(txtAttribute))
{
string enteredText = txtAttribute.Trim();
selectedAttributes = _checkoutAttributeParser.AddCheckoutAttribute(selectedAttributes,
attribute, enteredText);
}
}
break;
case AttributeControlType.Datepicker:
{
var date = form[controlId + "_day"];
var month = form[controlId + "_month"];
var year = form[controlId + "_year"];
DateTime? selectedDate = null;
try
{
selectedDate = new DateTime(Int32.Parse(year), Int32.Parse(month), Int32.Parse(date));
}
catch { }
if (selectedDate.HasValue)
{
selectedAttributes = _checkoutAttributeParser.AddCheckoutAttribute(selectedAttributes,
attribute, selectedDate.Value.ToString("D"));
}
}
break;
case AttributeControlType.FileUpload:
{
var httpPostedFile = this.Request.Files[controlId];
if ((httpPostedFile != null) && (!String.IsNullOrEmpty(httpPostedFile.FileName)))
{
int fileMaxSize = _catalogSettings.FileUploadMaximumSizeBytes;
if (httpPostedFile.ContentLength > fileMaxSize)
{
//TODO display warning
//warnings.Add(string.Format(_localizationService.GetResource("ShoppingCart.MaximumUploadedFileSize"), (int)(fileMaxSize / 1024)));
}
else
{
//save an uploaded file
var download = new Download()
{
DownloadGuid = Guid.NewGuid(),
UseDownloadUrl = false,
DownloadUrl = "",
DownloadBinary = httpPostedFile.GetDownloadBits(),
ContentType = httpPostedFile.ContentType,
Filename = System.IO.Path.GetFileNameWithoutExtension(httpPostedFile.FileName),
Extension = System.IO.Path.GetExtension(httpPostedFile.FileName),
IsNew = true
};
_downloadService.InsertDownload(download);
//save attribute
selectedAttributes = _checkoutAttributeParser.AddCheckoutAttribute(selectedAttributes,
attribute, download.DownloadGuid.ToString());
}
}
}
break;
default:
break;
}
}
//save checkout attributes
_workContext.CurrentCustomer.CheckoutAttributes = selectedAttributes;
_customerService.UpdateCustomer(_workContext.CurrentCustomer);
//validate attributes
var checkoutAttributeWarnings = _shoppingCartService.GetShoppingCartWarnings(cart, _workContext.CurrentCustomer.CheckoutAttributes, true);
if (checkoutAttributeWarnings.Count > 0)
{
//something wrong, redisplay the page with warnings
var model = new ShoppingCartModel();
PrepareShoppingCartModel(model, cart, validateCheckoutAttributes: true);
return View(model);
}
return RedirectToRoute("Checkout");
}
示例12: Cart
public ActionResult Cart(int productid = 0)
{
if (!_permissionService.Authorize(StandardPermissionProvider.EnableShoppingCart))
return RedirectToRoute("HomePage");
IList<ShoppingCartItem> cart = new List<ShoppingCartItem>();
//check if cart contains gift card, if so then only show gift card in cart for checkout first
var gcCount = _workContext.CurrentCustomer.ShoppingCartItems
.Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart && sci.Product.AdminComment == "Gift Card")
.LimitPerStore(_storeContext.CurrentStore.Id)
.Count();
var regularCount = _workContext.CurrentCustomer.ShoppingCartItems
.Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart && sci.Product.AdminComment != "Gift Card")
.LimitPerStore(_storeContext.CurrentStore.Id)
.Count();
if (gcCount != 0)
{
cart = _workContext.CurrentCustomer.ShoppingCartItems
.Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart && sci.Product.AdminComment == "Gift Card")
.LimitPerStore(_storeContext.CurrentStore.Id)
.ToList();
}
else
{
cart = _workContext.CurrentCustomer.ShoppingCartItems
.Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart)
.LimitPerStore(_storeContext.CurrentStore.Id)
.ToList();
}
//if (productid != 0)
//{
// cart = _workContext.CurrentCustomer.ShoppingCartItems
// .Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart && sci.ProductId == productid)
// .LimitPerStore(_storeContext.CurrentStore.Id)
// .ToList();
// //cart[0].Quantity = 1;
//}
//else
//{
// cart = _workContext.CurrentCustomer.ShoppingCartItems
// .Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart)
// .LimitPerStore(_storeContext.CurrentStore.Id)
// .ToList();
//}
var model = new ShoppingCartModel();
if (gcCount != 0 && regularCount !=0)
{
model.ItemsInCartId = 3;
}
if (gcCount != 0 && regularCount == 0)
{
model.ItemsInCartId = 2;
}
if (gcCount == 0 && regularCount != 0)
{
model.ItemsInCartId = 1;
}
var customer = cart.GetCustomer();
string gcCode = _giftCardService.GetCustomerGiftCard(customer);
// string gcCode = "";
if (gcCode.Length > 0)
customer.ApplyGiftCardCouponCode(gcCode);
PrepareShoppingCartModel(model, cart);
return View(model);
}
示例13: OrderSummary
public ActionResult OrderSummary(bool? prepareAndDisplayOrderReviewData)
{
IList<ShoppingCartItem> cart = new List<ShoppingCartItem>();
//check if cart contains gift card, if so then only show gift card in cart for checkout first
var gcCount = _workContext.CurrentCustomer.ShoppingCartItems
.Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart && sci.Product.AdminComment == "Gift Card")
.LimitPerStore(_storeContext.CurrentStore.Id)
.Count();
var regularCount = _workContext.CurrentCustomer.ShoppingCartItems
.Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart && sci.Product.AdminComment != "Gift Card")
.LimitPerStore(_storeContext.CurrentStore.Id)
.Count();
if (gcCount != 0)
{
cart = _workContext.CurrentCustomer.ShoppingCartItems
.Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart && sci.Product.AdminComment == "Gift Card")
.LimitPerStore(_storeContext.CurrentStore.Id)
.ToList();
}
else
{
cart = _workContext.CurrentCustomer.ShoppingCartItems
.Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart)
.LimitPerStore(_storeContext.CurrentStore.Id)
.ToList();
}
var model = new ShoppingCartModel();
if (gcCount != 0 && regularCount != 0)
{
model.ItemsInCartId = 3;
}
if (gcCount != 0 && regularCount == 0)
{
model.ItemsInCartId = 2;
}
if (gcCount == 0 && regularCount != 0)
{
model.ItemsInCartId = 1;
}
//var cart = _workContext.CurrentCustomer.ShoppingCartItems
// .Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart)
// .LimitPerStore(_storeContext.CurrentStore.Id)
// .ToList();
//var model = new ShoppingCartModel();
PrepareShoppingCartModel(model, cart,
isEditable: false,
prepareEstimateShippingIfEnabled: false,
prepareAndDisplayOrderReviewData: prepareAndDisplayOrderReviewData.GetValueOrDefault());
return PartialView(model);
}
示例14: RemoveDiscountCoupon
public ActionResult RemoveDiscountCoupon()
{
var cart = _workContext.CurrentCustomer.ShoppingCartItems
.Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart)
.LimitPerStore(_storeContext.CurrentStore.Id)
.ToList();
var model = new ShoppingCartModel();
_genericAttributeService.SaveAttribute<string>(_workContext.CurrentCustomer,
SystemCustomerAttributeNames.DiscountCouponCode, null);
PrepareShoppingCartModel(model, cart);
return View(model);
}
示例15: ApplyDiscountCoupon
public ActionResult ApplyDiscountCoupon(string discountcouponcode)
{
var cart = _workContext.CurrentCustomer.ShoppingCartItems.Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart).ToList();
var model = new ShoppingCartModel();
if (!String.IsNullOrWhiteSpace(discountcouponcode))
{
var discount = _discountService.GetDiscountByCouponCode(discountcouponcode);
bool isDiscountValid = discount != null && discount.RequiresCouponCode;
if (isDiscountValid)
{
_workContext.CurrentCustomer.DiscountCouponCode = discountcouponcode;
_customerService.UpdateCustomer(_workContext.CurrentCustomer);
model.DiscountMessage = _localizationService.GetResource("ShoppingCart.DiscountCouponCode.Applied");
}
else
{
model.DiscountMessage = _localizationService.GetResource("ShoppingCart.DiscountCouponCode.WrongDiscount");
}
}
model = PrepareShoppingCartModel(model, cart, true);
return View(model);
}