public virtual async Task <IActionResult> StartCheckout(IFormCollection form = null) { var cart = _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, ShoppingCartType.ShoppingCart, ShoppingCartType.Auctions); var checkoutAttributes = new List <CustomAttribute>(); //parse and save checkout attributes if (form != null && form.Count > 0) { checkoutAttributes = (await _mediator.Send(new SaveCheckoutAttributesCommand() { Customer = _workContext.CurrentCustomer, Store = _workContext.CurrentStore, Cart = cart, Form = form })).ToList(); } else { checkoutAttributes = _workContext.CurrentCustomer.GetUserFieldFromEntity <List <CustomAttribute> >(SystemCustomerFieldNames.CheckoutAttributes, _workContext.CurrentStore.Id); } var checkoutAttributeWarnings = await _shoppingCartValidator.GetShoppingCartWarnings(cart, checkoutAttributes, true); if (checkoutAttributeWarnings.Any()) { return(RedirectToRoute("ShoppingCart", new { checkoutAttributes = true })); } //everything is OK if (await _groupService.IsGuest(_workContext.CurrentCustomer)) { if (!_orderSettings.AnonymousCheckoutAllowed) { return(Challenge()); } return(RedirectToRoute("LoginCheckoutAsGuest", new { returnUrl = Url.RouteUrl("ShoppingCart") })); } return(RedirectToRoute("Checkout")); }
public async Task <WishlistModel> Handle(GetWishlist request, CancellationToken cancellationToken) { var model = new WishlistModel { EmailWishlistEnabled = _shoppingCartSettings.EmailWishlistEnabled, IsEditable = request.IsEditable, DisplayAddToCart = await _permissionService.Authorize(StandardPermission.EnableShoppingCart), }; if (!request.Cart.Any()) { return(model); } #region Simple properties model.CustomerGuid = request.Customer.CustomerGuid; model.CustomerFullname = request.Customer.GetFullName(); model.ShowProductImages = _shoppingCartSettings.ShowProductImagesOnWishList; model.ShowSku = _catalogSettings.ShowSkuOnProductDetailsPage; //cart warnings var cartWarnings = await _shoppingCartValidator.GetShoppingCartWarnings(request.Cart, null, false); foreach (var warning in cartWarnings) { model.Warnings.Add(warning); } #endregion #region Cart items foreach (var sci in request.Cart) { var product = await _productService.GetProductById(sci.ProductId); if (!_aclService.Authorize(product, request.Customer)) { continue; } var sename = product.GetSeName(request.Language.Id); var cartItemModel = new WishlistModel.ShoppingCartItemModel { Id = sci.Id, Sku = product.FormatSku(sci.Attributes, _productAttributeParser), ProductId = product.Id, ProductName = product.GetTranslation(x => x.Name, request.Language.Id), ProductSeName = sename, ProductUrl = _linkGenerator.GetUriByRouteValues(_httpContextAccessor.HttpContext, "Product", new { SeName = sename }), Quantity = sci.Quantity, AttributeInfo = await _productAttributeFormatter.FormatAttributes(product, sci.Attributes), }; cartItemModel.AllowItemEditing = _shoppingCartSettings.AllowCartItemEditing && product.ProductTypeId == ProductType.SimpleProduct && (!String.IsNullOrEmpty(cartItemModel.AttributeInfo) || product.IsGiftVoucher) && product.VisibleIndividually; //allowed quantities var allowedQuantities = product.ParseAllowedQuantities(); foreach (var qty in allowedQuantities) { cartItemModel.AllowedQuantities.Add(new SelectListItem { Text = qty.ToString(), Value = qty.ToString(), Selected = sci.Quantity == qty }); } //recurring info if (product.IsRecurring) { cartItemModel.RecurringInfo = string.Format(_translationService.GetResource("ShoppingCart.RecurringPeriod"), product.RecurringCycleLength, product.RecurringCyclePeriodId.GetTranslationEnum(_translationService, request.Language.Id)); } //unit prices if (product.CallForPrice) { cartItemModel.UnitPrice = _translationService.GetResource("Products.CallForPrice"); } else { var productprice = await _taxService.GetProductPrice(product, (await _pricingService.GetUnitPrice(sci, product)).unitprice); double taxRate = productprice.taxRate; cartItemModel.UnitPrice = _priceFormatter.FormatPrice(productprice.productprice); } //subtotal, discount if (product.CallForPrice) { cartItemModel.SubTotal = _translationService.GetResource("Products.CallForPrice"); } else { //sub total var subtotal = await _pricingService.GetSubTotal(sci, product, true); double shoppingCartItemDiscountBase = subtotal.discountAmount; List <ApplyDiscount> scDiscounts = subtotal.appliedDiscounts; var productprices = await _taxService.GetProductPrice(product, subtotal.subTotal); double taxRate = productprices.taxRate; cartItemModel.SubTotal = _priceFormatter.FormatPrice(productprices.productprice); //display an applied discount amount if (shoppingCartItemDiscountBase > 0) { shoppingCartItemDiscountBase = (await _taxService.GetProductPrice(product, shoppingCartItemDiscountBase)).productprice; if (shoppingCartItemDiscountBase > 0) { cartItemModel.Discount = _priceFormatter.FormatPrice(shoppingCartItemDiscountBase); } } } //picture if (_shoppingCartSettings.ShowProductImagesOnWishList) { cartItemModel.Picture = await PrepareCartItemPicture(request, product, sci.Attributes); } //item warnings var itemWarnings = await _shoppingCartValidator.GetShoppingCartItemWarnings(request.Customer, sci, product, new ShoppingCartValidatorOptions()); foreach (var warning in itemWarnings) { cartItemModel.Warnings.Add(warning); } model.Items.Add(cartItemModel); } #endregion return(model); }
private async Task PrepareSimpleProperties(ShoppingCartModel model, GetShoppingCart request) { #region Simple properties model.IsEditable = request.IsEditable; model.IsAllowOnHold = _shoppingCartSettings.AllowOnHoldCart; model.TermsOfServicePopup = _commonSettings.PopupForTermsOfServiceLinks; model.ShowProductImages = _shoppingCartSettings.ShowProductImagesOnShoppingCart; model.ShowSku = _catalogSettings.ShowSkuOnProductDetailsPage; model.IsGuest = await _groupService.IsGuest(request.Customer); model.ShowCheckoutAsGuestButton = model.IsGuest && _orderSettings.AnonymousCheckoutAllowed; var checkoutAttributes = request.Customer.GetUserFieldFromEntity <List <CustomAttribute> >(SystemCustomerFieldNames.CheckoutAttributes, request.Store.Id); model.CheckoutAttributeInfo = await _checkoutAttributeFormatter.FormatAttributes(checkoutAttributes, request.Customer); if (!request.Cart.Where(x => x.ShoppingCartTypeId == ShoppingCartType.ShoppingCart || x.ShoppingCartTypeId == ShoppingCartType.Auctions).ToList().Any()) { model.MinOrderSubtotalWarning = _translationService.GetResource("Checkout.MinOrderOneProduct"); } else { var minOrderSubtotalAmountOk = await _mediator.Send(new ValidateMinShoppingCartSubtotalAmountCommand() { Customer = request.Customer, Cart = request.Cart.Where(x => x.ShoppingCartTypeId == ShoppingCartType.ShoppingCart || x.ShoppingCartTypeId == ShoppingCartType.Auctions).ToList() }); if (!minOrderSubtotalAmountOk) { decimal minOrderSubtotalAmount = await _currencyService.ConvertFromPrimaryStoreCurrency(_orderSettings.MinOrderSubtotalAmount, request.Currency); model.MinOrderSubtotalWarning = string.Format(_translationService.GetResource("Checkout.MinOrderSubtotalAmount"), _priceFormatter.FormatPrice(minOrderSubtotalAmount, false)); } } model.TermsOfServiceOnShoppingCartPage = _orderSettings.TermsOfServiceOnShoppingCartPage; model.TermsOfServiceOnOrderConfirmPage = _orderSettings.TermsOfServiceOnOrderConfirmPage; model.DiscountBox.Display = _shoppingCartSettings.ShowDiscountBox; var discountCouponCodes = request.Customer.ParseAppliedCouponCodes(SystemCustomerFieldNames.DiscountCoupons); foreach (var couponCode in discountCouponCodes) { var discount = await _discountService.GetDiscountByCouponCode(couponCode); if (discount != null && discount.RequiresCouponCode && (await _discountService.ValidateDiscount(discount, request.Customer, request.Currency)).IsValid) { model.DiscountBox.AppliedDiscountsWithCodes.Add(new ShoppingCartModel.DiscountBoxModel.DiscountInfoModel() { Id = discount.Id, CouponCode = couponCode }); } } model.GiftVoucherBox.Display = _shoppingCartSettings.ShowGiftVoucherBox; //cart warnings var cartWarnings = await _shoppingCartValidator.GetShoppingCartWarnings(request.Cart, checkoutAttributes, request.ValidateCheckoutAttributes); foreach (var warning in cartWarnings) { model.Warnings.Add(warning); } #endregion }