private ICartItemViewModel CustomJewelCartItemViewModelBuilderMethod(ICartItem cartItem, int index) { try { var customJewel = cartItem as CustomJewelCartItem; jewelRepository.FilterMediaByMetal(customJewel.MediaType); var diamond = diamondRepository.GetDiamondByID(customJewel.DiamondID); var jewel = jewelRepository.GetJewelByID(customJewel.SettingID); var twoObjects = new MergeDiamondAndJewel() { First = diamond, Second = jewel }; var viewModel = mapper.Map<MergeDiamondAndJewel, CustomJewelCartItemViewModel>(twoObjects); viewModel.CartID = index; viewModel.Size = customJewel.GetSize(); return viewModel; } catch (Exception ex) { throw new Exception(ex.Message + "\n When asked to build a view model for jewelcartitem we had a problem explained above"); } }
public void RemoveFromCart(ICartItem cartItem) { var currentCart = GetAllCart(); if (currentCart.Any(x => x.ProductId == cartItem.ProductId)) { var product = currentCart.FirstOrDefault(x => x.ProductId == cartItem.ProductId); currentCart.Remove(product); SessionHelper.SetSessionObject(currentCart, CartSessionStorageKey); } }
internal static Dictionary <string, object> ToDictionary(this ICartItem cartItem) { return(new Dictionary <string, object> { { "type", cartItem.Type }, { "reference", cartItem.Reference }, { "name", cartItem.Name }, { "quantity", cartItem.Quantity }, { "unit_price", cartItem.UnitPrice }, { "discount_rate", cartItem.DiscountRate }, { "tax_rate", cartItem.TaxRate } }); }
protected string GetItemName(object cartItem) { ICartItem item = (ICartItem)cartItem; OrderCalculator orderCalculator = new OrderCalculator(); OrderAmountPackage orderAmountPackage = orderCalculator.CalculatePackage( StoreContext.CheckoutDetails, new CartItemGroup(item), StoreContext.Customer); return(item.GetOrderItemName( StoreContext.Culture, StoreContext.Currency, orderAmountPackage)); }
public void ShouldHaveFifteenPercentDiscountWhenAmountIsGreaterThanFive() { var cartItem = new CartItem(new Product { Name = "iPhone X", Price = 12000M }, 3); ICartItem.SetDefaultDiscountAmount(2, 0.15M); ICartItem ci = cartItem; var discount = ci.Discount(); Assert.IsTrue(discount == 0.15M); }
public void ShouldApplyDefaultDiscount() { var cartItem = new CartItem(new Product { Name = "Samsun A70", Price = 10000M }, 3); ICartItem.SetDefaultDiscountAmount(2, 0.15M); ICartItem ci = cartItem; var discount = ci.Discount(); Assert.IsTrue(discount == 0.15M); }
public void ShouldHaveTwentyPercentDiscount() { var cartItem = new CartItem(new Product { Name = "LG 4K TV", Price = 16000M }, 3); ICartItem.SetDefaultDiscountAmount(2, 0.15M); ICartItem ci = cartItem; var discount = ci.Discount(); Assert.IsTrue(discount == 0.20M); }
public static OrderLineItem FromShoppingCartItem(ICartItem cartItem) { // Creates a new one ( ready for the db ) return new OrderLineItem { ProductId = cartItem.Id, Quantity = cartItem.Quantity, TaxTotal = cartItem.CalculateTotalTax(), TotalValue = cartItem.CalculateSubTotalWithoutTax(), UnitPrice = cartItem.PriceWithoutTax, CreatedDateTime = DateTime.Now, ProductName = cartItem.Title }; }
protected void uxWishListGrid_RowUpdating(object sender, GridViewUpdateEventArgs e) { string cartItemID = GetCartItemIDFromGrid(e.RowIndex); ICartItem cartItem = CurrentWishListCart.FindCartItemByID(cartItemID); StoreContext.ShoppingCart.AddItem(cartItem); CurrentWishListCart.DeleteItem(cartItemID); DataAccessContext.CartRepository.UpdateWhole(CurrentWishListCart); RefreshGrid(); uxStatusHidden.Value = "AddedToCart"; }
protected string GetItemImage(object cartItem) { ICartItem baseCartItem = (ICartItem)cartItem; ProductImage details = baseCartItem.Product.GetPrimaryProductImage(); if (String.IsNullOrEmpty(details.ThumbnailImage)) { return("~/Images/Products/Thumbnail/DefaultNoImage.gif"); } else { return("~/" + details.ThumbnailImage); } }
private ICartItemViewModel DiamondCartItemViewModelBuilderMethod(ICartItem cartItem, int index) { try { var diamond = diamondRepository.GetDiamondByID(cartItem.ID); var viewModel = mapper.Map <Diamond, DiamondCartItemViewModel>(diamond); viewModel.CartID = index; return(viewModel); } catch (Exception ex) { throw new Exception(ex.Message + "\n When asked to build a view model for jewelcartitem we had a problem explained above"); } }
protected string GetLink(object cartItem) { ICartItem baseCartItem = ( ICartItem )cartItem; if (baseCartItem.IsPromotion) { CartItemPromotion cartItemPromotion = (CartItemPromotion)baseCartItem; PromotionGroup promotion = cartItemPromotion.PromotionSelected.GetPromotionGroup(); return(UrlManager.GetPromotionUrl(promotion.PromotionGroupID, promotion.Locales[StoreContext.Culture].UrlName)); } else { Product product = baseCartItem.Product; return(UrlManager.GetProductUrl(product.ProductID, product.Locales[StoreContext.Culture].UrlName)); } }
public void AddItem(ICartItem cartItem) { if (CartItems.ContainsKey(cartItem.PLU)) { CartItems[cartItem.PLU] = CartItems[cartItem.PLU] + 1; } else { CartItems.Add(cartItem.PLU, 1); } if (!_cartItemDescription.ContainsKey(cartItem.PLU)) { _cartItemDescription.Add(cartItem.PLU, cartItem); } }
private void AddItem(ICartItem item) { if (item.IsValid()) { var cartItem = _cartItems.FirstOrDefault(x => x.Product.Category.Title == item.Product.Category.Title && x.Product.Title == item.Product.Title && x.Product.Amount == item.Product.Amount); if (cartItem != null) { cartItem.IncreaseQuantity(item.Quantity); } else { _cartItems.Add(item); } } }
public int AddProduct(IProduct product, int amount = 1) { bool exist = CartProductIds.Contains(product.GetId()); if (exist) { ICartItem item = CartItems.Find(cartItem => cartItem.GetProduct().Equals(product)); if (item == null) { throw new InvalidOperationException("Item exist in HashSet but not in CartItems"); } return(item.IncreaseAmountOn(amount)); } CartProductIds.Add(product.GetId()); CartItems.Add(new CartItem(product, this, amount)); return(amount); }
public void UpdateItemQuantityInCart(ICartItem cartItem) { var currentCart = GetAllCart(); if (currentCart == null) { currentCart = new List <ICartItem>(); } if (currentCart.Any(x => x.ProductId == cartItem.ProductId)) { var product = currentCart.FirstOrDefault(x => x.ProductId == cartItem.ProductId); product.Quantity = cartItem.Quantity; } SessionHelper.SetSessionObject(currentCart, CartSessionStorageKey); }
public void MoveSessionCartToDb() { if (SessionUser.UserLoggedIn()) { ECommerceEntities et = new ECommerceEntities(); Customer customer = et.Customer.Where(x => x.CustomerID == SessionUser.Current.CustomerID).FirstOrDefault(); if (customer != null) { List <ShoppingCartDetail> details = et.ShoppingCartDetail.Where(x => x.ShoppingCartId == customer.ShoppingCartID).ToList(); List <ShoppingCartDetail> newItems = new List <ShoppingCartDetail>(); foreach (ShoppingCartDetail detail in details) { ICartItem cartItem = SessionUser.Current.CartItems.Where(x => x.Product.ProductID == detail.ProductId).FirstOrDefault(); if (cartItem != null) { detail.ItemCount += cartItem.ItemCount; } } foreach (ICartItem item in SessionUser.Current.CartItems) { ShoppingCartDetail itemDetail = new ShoppingCartDetail(); itemDetail.CreationTime = DateTime.Now; itemDetail.ItemCount = item.ItemCount; itemDetail.ProductId = item.Product.ProductID; itemDetail.ShoppingCartId = customer.ShoppingCartID; newItems.Add(itemDetail); } foreach (ShoppingCartDetail detail in newItems) { et.ShoppingCartDetail.Add(detail); } et.SaveChanges(); SessionUser.Current.CartItems.Clear(); } } }
private JewelCartItemViewModel JewelCartItemViewModelBuilderMethod(ICartItem cartItem, int index) { try { var jewelCartItem = cartItem as JewelCartItem; jewelRepository.FilterMediaByMetal(jewelCartItem.MediaType); var jewel = jewelRepository.GetJewelByID(cartItem.ID); var viewModel = mapper.Map <Jewel, JewelCartItemViewModel>(jewel); viewModel.JewelSize = jewelCartItem.Size; viewModel.CartID = index; return(viewModel); } catch (Exception ex) { throw new Exception(ex.Message + "\n When asked to build a view model for jewelcartitem we had a problem explained above"); } }
public int RemoveProduct(IProduct product, int amount = 1) { if (!CartProductIds.Contains(product.GetId())) { throw new InvalidOperationException("No such product in a cart"); } ICartItem item = CartItems.Find(cartItem => cartItem.GetProduct().Equals(product)); if (item == null) { throw new InvalidOperationException("Item exist in HashSet but not in CartItems"); } if (item.GetAmount() != amount) { return(item.DecreaseAmountOn(amount)); } // here item should be deleted CartProductIds.Remove(product.GetId()); CartItems.RemoveAll(cartItem => cartItem.GetProduct().Equals(product)); return(0); }
public virtual void AddProduct(ICartItem cartItem) { Cart.AddProduct(cartItem); }
private JewelCartItemViewModel JewelCartItemViewModelBuilderMethod(ICartItem cartItem, int index) { try { var jewelCartItem = cartItem as JewelCartItem; jewelRepository.FilterMediaByMetal(jewelCartItem.MediaType); var jewel = jewelRepository.GetJewelByID(cartItem.ID); var viewModel = mapper.Map<Jewel, JewelCartItemViewModel>(jewel); viewModel.JewelSize = jewelCartItem.Size; viewModel.CartID = index; return viewModel; } catch (Exception ex) { throw new Exception(ex.Message + "\n When asked to build a view model for jewelcartitem we had a problem explained above"); } }
public void AddItem(ICartItem item) { }
public void PopulateControls() { uxEnterAmountTextRequired.ValidationGroup = SetValidGroup; uxEnterAmountTextCompare.ValidationGroup = SetValidGroup; uxQuantityRequiredValidator.ValidationGroup = SetValidGroup; uxQuantityCompare.ValidationGroup = SetValidGroup; if (IsProductKit(ProductID)) { uxMessageLabel.Visible = true; uxMessageLabel.Text = "Product Kit cannot be added."; uxMessageLabel.ForeColor = System.Drawing.Color.Red; } else { uxMessageLabel.Visible = false; } uxMinQuantityLabel.Visible = false; uxMaxQuantityLabel.Visible = false; uxCustomPriceNote.Visible = false; uxSpecialTrialPanel.Visible = false; uxProductNameLabel.Text = CurrentProduct.Name; uxProductImage.ImageUrl = AdminConfig.UrlFront + CurrentProduct.ImageSecondary; PopulateProductImage(CurrentProduct.ImageSecondary); Currency currency = DataAccessContext.CurrencyRepository.GetOne(CurrencyCode); if (CurrentProduct.IsRecurring) { uxSpecialTrialPanel.Visible = IsShowRecurringPeriod(); uxRecurringPeriodTR.Visible = IsShowRecurringPeriod(); uxRecurringCyclesLabel.Text = ShowRecurringCycles(); uxTrialPeriodMoreTR.Visible = IsShowTrialPeriodMore(); uxTrialPeriodTR.Visible = IsShowTrialPeriod(); uxFreeTrialPeriodTR.Visible = IsShowFreeTrialPeriod(); uxFreeTrialPeriodMoreTR.Visible = IsShowFreeTrialPeriodMore(); uxRecurringTrialMoreAmountLabel.Text = currency.FormatPrice(CurrentProduct.ProductRecurring.RecurringTrialAmount); uxRecurringTrialAmountLabel.Text = currency.FormatPrice(CurrentProduct.ProductRecurring.RecurringTrialAmount); uxRecurringMoreNumberOfTrialCyclesLabel.Text = CurrentProduct.ProductRecurring.RecurringNumberOfTrialCycles.ToString(); uxRecurringNumberOfTrialCyclesLabel.Text = CurrentProduct.ProductRecurring.RecurringNumberOfTrialCycles.ToString(); } if (!IsEditMode()) { if (!CurrentProduct.IsCustomPrice) { uxEnterAmountText.Text = currency.FormatPriceWithOutSymbol(GetProductPrice(CurrentProduct)); uxEnterAmountTextCompare.ValueToCompare = "0"; } else { uxEnterAmountText.Text = currency.FormatPriceWithOutSymbol(CurrentProduct.ProductCustomPrice.DefaultPrice); uxEnterAmountTextCompare.ValueToCompare = Convert.ToDecimal(CurrentProduct.ProductCustomPrice.MinimumPrice).ToString(); uxMinPriceLabel.Text = String.Format("Minimum Price: {0}", currency.FormatPrice(CurrentProduct.ProductCustomPrice.MinimumPrice)); uxCustomPriceNote.Visible = true; } uxQuantityText.Text = CurrentProduct.MinQuantity.ToString(); uxQuantityDiscount.DiscountGroupID = CurrentProduct.DiscountGroupID; uxQuantityDiscount.PopulateControls(); if (CurrentProduct.DiscountGroupID == "0") { uxQuantityDiscountPanel.Visible = false; } else { uxQuantityDiscountPanel.Visible = true; } uxProductOptionGroupDetails.ProductID = ProductID; uxProductOptionGroupDetails.CultureID = CultureID; uxProductOptionGroupDetails.StoreID = StoreID; uxProductOptionGroupDetails.CurrencyCode = CurrencyCode; uxProductOptionGroupDetails.ValidGroup = SetValidGroup; uxProductOptionGroupDetails.PopulateControls(); if (CurrentProduct.ProductOptionGroups.Count <= 0) { uxProductOptionGroupPanel.Visible = false; } else { uxProductOptionGroupPanel.Visible = true; } uxGiftCertificateDetails.ProductID = ProductID; uxGiftCertificateDetails.CultureID = CultureID; uxGiftCertificateDetails.StoreID = StoreID; uxGiftCertificateDetails.PopulateControls(); if (!CurrentProduct.IsGiftCertificate) { uxGiftPanel.Visible = false; uxCustomPriceDiv.Visible = true; } else { uxCustomPriceDiv.Visible = false; uxGiftPanel.Visible = true; } } else { ICartItem cartItem = StoreContext.ShoppingCart.FindCartItemByID(CartItemID); uxQuantityText.Text = cartItem.Quantity.ToString(); if (cartItem.Product.IsCustomPrice) { uxEnterAmountText.Text = currency.FormatPriceWithOutSymbol(cartItem.ProductCustomPrice); uxEnterAmountTextCompare.ValueToCompare = Convert.ToDecimal(cartItem.Product.ProductCustomPrice.MinimumPrice).ToString(); uxMinPriceLabel.Text = String.Format("Minimum Price: {0}", currency.FormatPrice(cartItem.Product.ProductCustomPrice.MinimumPrice)); } else if (cartItem.IsEnterPrice) { uxEnterAmountText.Text = currency.FormatPriceWithOutSymbol(cartItem.EnteredPrice); uxEnterAmountTextCompare.ValueToCompare = "0"; } else { uxEnterAmountText.Text = currency.FormatPriceWithOutSymbol(GetProductPrice(cartItem.Product)); uxEnterAmountTextCompare.ValueToCompare = "0"; } uxProductOptionGroupDetails.ProductID = cartItem.Product.ProductID; uxProductOptionGroupDetails.CultureID = CultureID; uxProductOptionGroupDetails.StoreID = StoreID; uxProductOptionGroupDetails.CurrencyCode = CurrencyCode; uxProductOptionGroupDetails.ValidGroup = SetValidGroup; uxProductOptionGroupDetails.PopulateControls(cartItem.Options); if (CurrentProduct.ProductOptionGroups.Count <= 0) { uxProductOptionGroupPanel.Visible = false; } else { uxProductOptionGroupPanel.Visible = true; } } }
// public ShoppingCart GetShoppingCart(HttpContextBase httpContext) // { // var session = httpContext.Session; // if (session["cart"] != null) // { // return (ShoppingCart)session["cart"]; // } // return new ShoppingCart(new FakeHttpContext()); // } // // public static void Persist(HttpContextBase httpContext,IShoppingCart shoppingCart) // { // var session = httpContext.Session; // if (shoppingCart != null) // { // session["cart"] = shoppingCart; // } // // } public void AddItem(ICartItem standardItemViewModel) { cartItems.Add(standardItemViewModel); }
protected string GetSubtotalText(ICartItem cartItem) { return(CurrenntCurrency.FormatPrice(cartItem.GetSubtotal(StoreContext.WholesaleStatus))); }
public CheckoutModel(IPaymentHandler payment, ICart cart, UserManager <ApplicationUser> userManager, IOrder order, IOrderItem orderItem, ICartItem cartItem, IEmail email) { _payment = payment; _cart = cart; _cartItem = cartItem; _userManager = userManager; _order = order; _orderItem = orderItem; _email = email; }
public void AddItem(ICartItem cartItem) { this._items.Add(cartItem); }
public virtual void RemoveProduct(ICartItem cartItem) { Cart.RemoveProduct(cartItem); }
protected string GetUnitPriceText(ICartItem cartItem) { return(CurrenntCurrency.FormatPrice(cartItem.GetCheckoutUnitPrice(StoreContext.WholesaleStatus))); }
public IndexModel(ICart cart, ICartItem cartItem, IProduct product) { _cart = cart; _cartItem = cartItem; _product = product; }
protected CartItemInheritorBase(ICartItem cartItem) { CartItem = cartItem; }
public ShoppingCart(ICartItem[] items) { _items = items; }
public void Update(int cartId, ICartItem updatedCartItem) { cartItems[cartId] = updatedCartItem; }
public bool UpdateCartItem(bool isSubscriptionable, out string errMsg) { errMsg = String.Empty; if (!VerifyValidInput(out errMsg)) { if (!String.IsNullOrEmpty(errMsg)) { DisplayErrorMessage(errMsg); return(false); } } //string errMsg; if (!VerifyQuantity(out errMsg)) { DisplayErrorMessage(errMsg); return(false); } if (!IsMatchQuantity()) { return(false); } ICartItem item = StoreContext.ShoppingCart.FindCartItemByID(CartItemID); OptionItemValueCollection selectedOptions = uxProductOptionGroupDetails.GetSelectedOptions(); CartItemGiftDetails giftDetails = CreateGiftDetails(); Currency currency = DataAccessContext.CurrencyRepository.GetOne(CurrencyCode); decimal enterPrice = ConvertUtilities.ToDecimal(currency.FormatPriceWithOutSymbolInvert(ConvertUtilities.ToDecimal(uxEnterAmountText.Text))); if (enterPrice == item.Product.GetProductPrice(StoreID).Price) { enterPrice = 0; } decimal customPrice = 0; if (item.Product.IsCustomPrice) { customPrice = ConvertUtilities.ToDecimal(currency.FormatPriceWithOutSymbolInvert(ConvertUtilities.ToDecimal(uxEnterAmountText.Text))); } int currentStock; string errorOptionName; StoreContext.ShoppingCart.DeleteItem(CartItemID); CartAddItemService addToCartService = new CartAddItemService( StoreContext.Culture, StoreContext.ShoppingCart); bool stockOK = addToCartService.AddToCartByAdmin( item.Product, selectedOptions, ConvertUtilities.ToInt32(uxQuantityText.Text), giftDetails, customPrice, enterPrice, StoreID, out errorOptionName, out currentStock, isSubscriptionable); if (stockOK) { return(true); } else { errMsg = DisplayOutOfStockError(currentStock, errorOptionName); return(false); } }
/// <summary> /// Instantiates a CartService object. /// </summary> /// <param name="context"> /// StoreDBContext: an object that inherits from DbContext /// </param> public CartService(StoreDbContext context, ICartItem cartItem) { _context = context; _cartItem = cartItem; }
private ICartItemViewModel DiamondCartItemViewModelBuilderMethod(ICartItem cartItem, int index) { try { var diamond = diamondRepository.GetDiamondByID(cartItem.ID); var viewModel = mapper.Map<Diamond, DiamondCartItemViewModel>(diamond); viewModel.CartID = index; return viewModel; } catch (Exception ex) { throw new Exception(ex.Message + "\n When asked to build a view model for jewelcartitem we had a problem explained above"); } }