/// <summary> /// Initializes a new instance of the <see cref="CartLineBaseJsonResult"/> class. /// </summary> /// <param name="line">The line.</param> /// <param name="productItemResolver"></param> public CartLineBaseJsonResult(CustomCommerceCartLine line, IProductResolver productItemResolver) { this.DiscountOfferNames = new List <string>(); var product = (CommerceCartProduct)line.Product; //var productItem = ProductItemResolver.ResolveCatalogItem(product.ProductId, product.ProductCatalog, true); var productItem = productItemResolver.ResolveCatalogItem(product.ProductId, product.ProductCatalog, true); if (line.Images.Count > 0) { this.Image = line.Images[0].GetImageUrl(100, 100); } var userCurrency = StorefrontManager.GetCustomerCurrency(); this.DisplayName = product.DisplayName; this.Color = product.Properties["Color"] as string; this.LineDiscount = ((CommerceTotal)line.Total).LineItemDiscountAmount.ToCurrency(this.GetCurrencyCode(userCurrency, ((CommerceTotal)line.Total).CurrencyCode)); this.Quantity = line.Quantity.ToString(Context.Language.CultureInfo); this.LinePrice = product.Price.Amount.ToCurrency(this.GetCurrencyCode(userCurrency, product.Price.CurrencyCode)); this.LineTotal = line.Total.Amount.ToCurrency(this.GetCurrencyCode(userCurrency, line.Total.CurrencyCode)); this.ExternalCartLineId = StringUtility.RemoveCurlyBrackets(line.ExternalCartLineId); this.ProductUrl = product.ProductId.Equals(StorefrontManager.CurrentStorefront.GiftCardProductId, StringComparison.OrdinalIgnoreCase) ? StorefrontManager.StorefrontUri("/buygiftcard") : LinkManager.GetDynamicUrl(productItem); }
/// <summary> /// Initializes this object based on the data contained in the provided cart. /// </summary> /// <param name="cart">The cart used to initialize this object.</param> public override void Initialize(Commerce.Entities.Carts.Cart cart, IProductResolver productResolver) { base.Initialize(cart, productResolver); CommerceCart commerceCart = cart as CommerceCart; if (commerceCart == null) { return; } if (commerceCart.OrderForms.Count > 0) { foreach (var promoCode in (commerceCart.OrderForms[0].PromoCodes ?? Enumerable.Empty <String>())) { this.PromoCodes.Add(promoCode); } } decimal totalSavings = 0; foreach (var lineitem in cart.Lines) { totalSavings += ((CommerceTotal)lineitem.Total).LineItemDiscountAmount; } this.Discount = totalSavings.ToCurrency(StorefrontManager.GetCustomerCurrency()); }
/// <summary> /// Initializes a new instance of the <see cref="CSCartLineBaseJsonResult"/> class. /// </summary> /// <param name="line">The line.</param> /// <param name="productResolver"></param> public CSCartLineBaseJsonResult(CustomCommerceCartLine line, IProductResolver productResolver) : base(line, productResolver) { if (line.Adjustments.Count > 0) { foreach (var adjustment in line.Adjustments) { this.DiscountOfferNames.Add(adjustment.Description); } } }
public ProductUploader(ILogger logger, IProductValidator validator, ICacheManager cacher, IProductResolver productResolver) { if (logger == null) throw new ArgumentNullException("logger"); if (validator == null) throw new ArgumentNullException("validator"); if (cacher == null) throw new ArgumentNullException("cacher"); if (productResolver == null) throw new ArgumentNullException("productResolver"); _logger = logger; _validator = validator; _cacher = cacher; _productResolver = productResolver; }
public CartRepository( IAccountManager accountManager, IContactFactory contactFactory, ICartManager cartManager, ICartCacheService cartCacheService, IProductResolver productResolver) : base(accountManager, contactFactory) { _cartManager = cartManager; _cartCacheService = cartCacheService; _productResolver = productResolver; }
public CheckoutRepository( IAccountManager accountManager, IContactFactory contactFactory, ICartManager cartManager, IOrderManager orderManager, IPaymentManager paymentManager, IShippingManager shippingManager, IProductResolver productResolver) : base(accountManager, contactFactory) { this._cartManager = cartManager; this._orderManager = orderManager; this._paymentManager = paymentManager; this._shippingManager = shippingManager; _productResolver = productResolver; }
/// <summary> /// Initializes this object based on the data contained in the provided cart. /// </summary> /// <param name="cart">The cart used to initialize this object.</param> /// <param name="productResolver"></param> public virtual void Initialize(Cart cart, IProductResolver productResolver) { this.Lines = new List <CartLineBaseJsonResult>(); this.Adjustments = new List <CartAdjustmentBaseJsonResult>(); this.PromoCodes = new List <string>(); var currencyCode = StorefrontManager.GetCustomerCurrency(); this.Subtotal = 0.0M.ToCurrency(currencyCode); this.TaxTotal = 0.0M.ToCurrency(currencyCode); this.Total = 0.0M.ToCurrency(currencyCode); this.TotalAmount = 0.0M; this.Discount = 0.0M.ToCurrency(currencyCode); this.ShippingTotal = 0.0M.ToCurrency(currencyCode); if (cart == null) { return; } foreach (var line in (cart.Lines ?? Enumerable.Empty <CartLine>())) { var cartLine = ContextTypeLoader.CreateInstance <CartLineBaseJsonResult>(line, productResolver); this.Lines.Add(cartLine); } foreach (var adjustment in (cart.Adjustments ?? Enumerable.Empty <CartAdjustment>())) { this.Adjustments.Add(new CartAdjustmentBaseJsonResult(adjustment)); } var commerceTotal = (CommerceTotal)cart.Total; this.Subtotal = commerceTotal.Subtotal.ToCurrency(currencyCode); this.TaxTotal = cart.Total.TaxTotal.Amount.ToCurrency(currencyCode); this.Total = cart.Total.Amount.ToCurrency(currencyCode); this.TotalAmount = cart.Total.Amount; this.Discount = commerceTotal.OrderLevelDiscountAmount.ToCurrency(currencyCode); this.ShippingTotal = commerceTotal.ShippingTotal.ToCurrency(currencyCode); }
public Mocks() { AccountManager = Substitute.For <IAccountManager>(); AccountManager.ResolveCommerceUser() .Returns(new ManagerResponse <GetUserResult, CommerceUser>(new GetUserResult(), new CommerceUser { Email = "testMail" })); AccountManager.GetCurrentCustomerParties( Arg.Any <CommerceStorefront>(), Arg.Any <IVisitorContext>()) .Returns(new ManagerResponse <GetPartiesResult, IEnumerable <CommerceParty> >( new GetPartiesResult(), new List <CommerceParty>())); ContactFactory = Substitute.For <IContactFactory>(); CartManager = Substitute.For <ICartManager>(); CartManager.AddLineItemsToCart( Arg.Any <CommerceStorefront>(), Arg.Any <IVisitorContext>(), Arg.Any <List <AddCartLineInputModel> >()) .Returns(new ManagerResponse <CartResult, bool>(new CartResult(), true)); CartManager.AddPromoCodeToCart( Arg.Any <CommerceStorefront>(), Arg.Any <IVisitorContext>(), Arg.Any <string>()) .Returns( new ManagerResponse <AddPromoCodeResult, CommerceCart>(new AddPromoCodeResult(), Models.CommerceCartStub)); CartManager.RemoveLineItemFromCart( Arg.Any <CommerceStorefront>(), Arg.Any <IVisitorContext>(), Arg.Any <string>()) .Returns( new ManagerResponse <CartResult, CommerceCart>(new CartResult(), Models.CommerceCartStub)); CartManager.GetCurrentCart( Arg.Any <CommerceStorefront>(), Arg.Any <IVisitorContext>(), Arg.Any <bool>()) .Returns(new ManagerResponse <CartResult, CommerceCart>(new CartResult { Cart = Models.CommerceCartStub, }, Models.CommerceCartStub)); CartManager.RemovePromoCodeFromCart( Arg.Any <CommerceStorefront>(), Arg.Any <IVisitorContext>(), Arg.Any <string>()) .Returns(new ManagerResponse <RemovePromoCodeResult, CommerceCart>(new RemovePromoCodeResult(), Models.CommerceCartStub)); CartManager.ChangeLineQuantity( Arg.Any <CommerceStorefront>(), Arg.Any <IVisitorContext>(), Arg.Any <UpdateCartLineInputModel>()) .Returns(new ManagerResponse <CartResult, CommerceCart>(new CartResult(), Models.CommerceCartStub)); CartManager.AddLineItemsToCart( Arg.Any <CommerceStorefront>(), Arg.Any <IVisitorContext>(), Arg.Is <List <AddCartLineInputModel> >(x => x.Single() == null)) .Returns(new ManagerResponse <CartResult, bool>(new CartResult { Success = false }, false)); CartManager.AddPromoCodeToCart( Arg.Any <CommerceStorefront>(), Arg.Any <IVisitorContext>(), Arg.Is <string>(x => x == string.Empty)) .Returns(new ManagerResponse <AddPromoCodeResult, CommerceCart>( new AddPromoCodeResult { Success = false }, Models.CommerceCartStub)); CartManager.RemoveLineItemFromCart( Arg.Any <CommerceStorefront>(), Arg.Any <IVisitorContext>(), Arg.Is <string>(x => x == null)) .Returns(new ManagerResponse <CartResult, CommerceCart>( new CartResult { Success = false }, Models.CommerceCartStub)); CartManager.RemovePromoCodeFromCart( Arg.Any <CommerceStorefront>(), Arg.Any <IVisitorContext>(), Arg.Is <string>(x => x == string.Empty)) .Returns(new ManagerResponse <RemovePromoCodeResult, CommerceCart>( new RemovePromoCodeResult { Success = false }, Models.CommerceCartStub)); CartManager.ChangeLineQuantity( Arg.Any <CommerceStorefront>(), Arg.Any <IVisitorContext>(), Arg.Is <UpdateCartLineInputModel>(x => x == null)) .Returns(new ManagerResponse <CartResult, CommerceCart>( new CartResult { Success = false }, Models.CommerceCartStub)); CartManager.RemovePartiesFromCart( Arg.Any <CommerceStorefront>(), Arg.Any <IVisitorContext>(), Arg.Any <CommerceCart>(), Arg.Any <List <Party> >()) .Returns(new ManagerResponse <CartResult, CommerceCart>(new AddPartiesResult(), new CommerceCart { Parties = new ReadOnlyCollection <Party>(new List <Party>()) })); CartManager.RemoveAllPaymentMethods( Arg.Any <CommerceStorefront>(), Arg.Any <IVisitorContext>(), Arg.Any <CommerceCart>()) .Returns(new ManagerResponse <CartResult, CommerceCart>(new AddPaymentInfoResult(), new CommerceCart { Payment = new ReadOnlyCollection <PaymentInfo>(new List <PaymentInfo>()) })); CartManager.RemoveAllShippingMethods( Arg.Any <CommerceStorefront>(), Arg.Any <IVisitorContext>(), Arg.Any <CommerceCart>()) .Returns(new ManagerResponse <CartResult, CommerceCart>( new AddPartiesResult(), new CommerceCart { Shipping = new ReadOnlyCollection <ShippingInfo>(new List <ShippingInfo>()) })); CartManager.SetPaymentMethods( Arg.Any <CommerceStorefront>(), Arg.Any <IVisitorContext>(), Arg.Is <PaymentInputModel>(x => x != null)) .Returns(new ManagerResponse <CartResult, CommerceCart>( new AddPaymentInfoResult(), Models.CommerceCartStub)); CartManager.SetPaymentMethods( Arg.Any <CommerceStorefront>(), Arg.Any <IVisitorContext>(), Arg.Is <PaymentInputModel>(x => x == null)) .Returns(new ManagerResponse <CartResult, CommerceCart>( new AddPaymentInfoResult { Success = false }, Models.CommerceCartStub)); CartManager.SetShippingMethods( Arg.Any <CommerceStorefront>(), Arg.Any <IVisitorContext>(), Arg.Is <SetShippingMethodsInputModel>(x => x != null)) .Returns(new ManagerResponse <AddShippingInfoResult, CommerceCart>( new AddShippingInfoResult(), Models.CommerceCartStub)); CartManager.SetShippingMethods( Arg.Any <CommerceStorefront>(), Arg.Any <IVisitorContext>(), Arg.Is <SetShippingMethodsInputModel>(x => x == null)) .Returns(new ManagerResponse <AddShippingInfoResult, CommerceCart>( new AddShippingInfoResult { Success = false }, Models.CommerceCartStub)); VisitorContext = Substitute.For <IVisitorContext>(); VisitorContext.GetCustomerId().Returns(Models.TestUserId); CommerceCart nullCart = null; CartCacheService = Substitute.For <ICartCacheService>(); CartCacheService.GetCart(Arg.Any <string>()).Returns(Models.CommerceCartStub); CartCacheService.GetCart(Arg.Is <string>(x => x.Equals(Models.UserWithEmptyCache))).Returns(nullCart); OrderManager = Substitute.For <IOrderManager>(); OrderManager.GetAvailableRegions( Arg.Any <CommerceStorefront>(), Arg.Any <IVisitorContext>(), Arg.Any <string>()) .Returns( new ManagerResponse <GetAvailableRegionsResult, Dictionary <string, string> >( new GetAvailableRegionsResult(), new Dictionary <string, string> { { "test", "test" } })); OrderManager.GetOrderDetails( Arg.Any <CommerceStorefront>(), Arg.Any <IVisitorContext>(), Arg.Any <string>()) .Returns(new ManagerResponse <GetVisitorOrderResult, CommerceOrder>(new GetVisitorOrderResult(), new CommerceOrder())); OrderManager.GetAvailableRegions( Arg.Any <CommerceStorefront>(), Arg.Any <IVisitorContext>(), Arg.Is <string>(x => x == null)) .Returns( new ManagerResponse <GetAvailableRegionsResult, Dictionary <string, string> >( new GetAvailableRegionsResult { Success = false }, new Dictionary <string, string>())); OrderManager.GetAvailableCountries() .Returns(new ManagerResponse <GetAvailableCountriesResult, Dictionary <string, string> >( new GetAvailableCountriesResult(), new Dictionary <string, string>())); OrderManager.SubmitVisitorOrder( Arg.Any <CommerceStorefront>(), Arg.Any <IVisitorContext>(), Arg.Is <SubmitOrderInputModel>(x => x != null)) .Returns(new ManagerResponse <SubmitVisitorOrderResult, CommerceOrder>( new SubmitVisitorOrderResult(), new CommerceOrder())); OrderManager.SubmitVisitorOrder( Arg.Any <CommerceStorefront>(), Arg.Any <IVisitorContext>(), Arg.Is <SubmitOrderInputModel>(x => x == null)) .Returns(new ManagerResponse <SubmitVisitorOrderResult, CommerceOrder>( new SubmitVisitorOrderResult { Success = false }, new CommerceOrder())); ShippingManager = Substitute.For <IShippingManager>(); ShippingManager.GetShippingPreferences( Arg.Any <CommerceCart>()) .Returns(new ManagerResponse <GetShippingOptionsResult, List <ShippingOption> >( new GetShippingOptionsResult { ShippingOptions = new ReadOnlyCollection <ShippingOption>(new List <ShippingOption>()), LineShippingPreferences = new ReadOnlyCollection <LineShippingOption>(new List <LineShippingOption>()) }, new List <ShippingOption>())); ShippingManager.GetShippingMethods( Arg.Any <CommerceStorefront>(), Arg.Any <IVisitorContext>(), Arg.Any <ShippingOption>()) .Returns(new ManagerResponse <GetShippingMethodsResult, IReadOnlyCollection <ShippingMethod> >( new GetShippingMethodsResult(), new HashSet <ShippingMethod>())); ShippingManager.GetShippingMethods( Arg.Any <CommerceStorefront>(), Arg.Any <IVisitorContext>(), Arg.Any <GetShippingMethodsInputModel>()) .Returns(new ManagerResponse <GetShippingMethodsResult, IReadOnlyCollection <ShippingMethod> >( new GetShippingMethodsResult { ShippingMethods = new ReadOnlyCollection <ShippingMethod>(Models.ShippingMethods.ToList()) }, Models.ShippingMethods)); PaymentManager = Substitute.For <IPaymentManager>(); PaymentManager.GetPaymentOptions( Arg.Any <CommerceStorefront>(), Arg.Any <IVisitorContext>()) .Returns(new ManagerResponse <GetPaymentOptionsResult, IEnumerable <PaymentOption> >( new GetPaymentOptionsResult(), new List <PaymentOption>())); PaymentManager.GetPaymentMethods( Arg.Any <CommerceStorefront>(), Arg.Any <IVisitorContext>(), Arg.Any <PaymentOption>()) .Returns( new ManagerResponse <GetPaymentMethodsResult, IEnumerable <PaymentMethod> >( new GetPaymentMethodsResult(), new List <PaymentMethod>())); ProductResolver = Substitute.For <IProductResolver>(); ProductResolver.ResolveCatalogItem( Arg.Any <string>(), Arg.Any <string>(), Arg.Any <bool>()) .Returns(new Item(ID.NewID, new ItemData(ItemDefinition.Empty, Language.Invariant, Version.First, new FieldList()), Database.GetDatabase("master"))); }
public async Task <bool> DeleteProductAsync(ClaimsPrincipal claimsPrincipal, [Service] IProductResolver productResolver, ProductFilterModel criterias) { return(await productResolver.DeleteProductAsync(claimsPrincipal, criterias)); }
public async Task <ProductModel> UpdateProductAsync(ClaimsPrincipal claimsPrincipal, [Service] IProductResolver productResolver, ProductModel criterias) { return(await productResolver.UpdateProductAsync(claimsPrincipal, criterias)); }
public async Task <IList <ProductModel> > GetRelevantProductsAsync([Service] IProductResolver productResolver, ProductFilterModel criterias) { return(await productResolver.GetRelevantProductsAsync(criterias)); }
public async Task <ProductPageListModel> GetProductsAsync([Service] IProductResolver productResolver, ProductFilterModel criterias) { return(await productResolver.GetProductsAsync(criterias)); }
public async Task <ProductPageListModel> GetUserProductsAsync(ClaimsPrincipal claimsPrincipal, [Service] IProductResolver productResolver, ProductFilterModel criterias) { return(await productResolver.GetUserProductsAsync(claimsPrincipal, criterias)); }
public ProductApplicationService(IProductResolver productResolver) { this.productResolver = productResolver; }