public PipelineExecutionResult Execute(IPipelineArgs <CreateBasketRequest, CreateBasketResponse> subject) { if (subject.Request.Properties.ContainsKey("FromUCommerce")) { if (!(bool)subject.Request.Properties["FromUCommerce"]) { return(PipelineExecutionResult.Success); } } if (subject.Response.PurchaseOrder == null) { return(PipelineExecutionResult.Success); } var contactFactory = new ContactFactory(); string userId = contactFactory.GetContact(); subject.Response.PurchaseOrder["CommerceConnectUserIdentifier"] = userId; var cartServiceProvider = new CartServiceProvider(); var createCartRequest = new CreateOrResumeCartRequest(Context.GetSiteName(), userId); //should it do anything??? cartServiceProvider.CreateOrResumeCart(createCartRequest); return(PipelineExecutionResult.Success); }
public ActionResult CreateShipment(ShippingPickerViewModel createShipmentViewModel) { var cartService = new CartServiceProvider(); var cart = GetCart(); if (cart.Shipping.Any()) { var removeRequest = new RemoveShippingInfoRequest(cart, cart.Shipping.ToList()); var removeResult = cartService.RemoveShippingInfo(removeRequest); } var shippingParty = cart.Parties.FirstOrDefault(x => x.PartyId == Constants.DefaultShipmentAddressName); var shippingList = new List <ShippingInfo> { new ShippingInfo() { ShippingMethodID = createShipmentViewModel.SelectedShippingMethodId.ToString(), PartyID = shippingParty.PartyId } }; var addRequest = new AddShippingInfoRequest(cart, shippingList); var addResult = cartService.AddShippingInfo(addRequest); return(Redirect("/payment")); }
public ActionResult AddToBasket(AddToBasketButtonAddToBasketViewModel viewModel) { var cartServiceProvider = new CartServiceProvider(); var contactFactory = new ContactFactory(); string userId = contactFactory.GetContact(); var createCartRequest = new CreateOrResumeCartRequest(Context.GetSiteName(), userId); var cart = cartServiceProvider.CreateOrResumeCart(createCartRequest).Cart; var cartProduct = new CartProduct { ProductId = viewModel.ProductSku, Price = new Price(Convert.ToDecimal(viewModel.Price), cart.CurrencyCode) }; cartProduct.Properties.Add("VariantSku", viewModel.VariantSku); var cartLines = new ReadOnlyCollection <CartLine>( new Collection <CartLine> { new CartLine { Product = cartProduct, Quantity = (uint)viewModel.Quantity } } ); var request = new AddCartLinesRequest(cart, cartLines); cartServiceProvider.AddCartLines(request); return(Json(_miniBasketService.Refresh(), JsonRequestBehavior.AllowGet)); }
public PipelineExecutionResult Execute(IPipelineArgs <AddToBasketRequest, AddToBasketResponse> subject) { if (subject.Request.Properties.ContainsKey("FromUCommerce")) { if (!(bool)subject.Request.Properties["FromUCommerce"]) { return(PipelineExecutionResult.Success); } } //var cart = MappingLibrary.MapPurchaseOrderToCart(subject.Request.PurchaseOrder); var contactFactory = new ContactFactory(); string userId = contactFactory.GetContact(); var cartServiceProvider = new CartServiceProvider(); var createCartRequest = new CreateOrResumeCartRequest(Context.GetSiteName(), userId); //should it do anything??? var cart = cartServiceProvider.CreateOrResumeCart(createCartRequest).Cart; var cartLine = MappingLibrary.MapOrderLineToCartLine(subject.Response.OrderLine); var request = new AddCartLinesRequest(cart, new Collection <CartLine> { cartLine }); request.Properties["FromUCommerce"] = true; var serviceProvider = new CartServiceProvider(); serviceProvider.AddCartLines(request); return(PipelineExecutionResult.Success); }
public PipelineExecutionResult Execute(IPipelineArgs <AddAddressRequest, AddAddressResult> subject) { if (subject.Request.Properties.ContainsKey("FromUCommerce")) { if (!(bool)subject.Request.Properties["FromUCommerce"]) { return(PipelineExecutionResult.Success); } } var cartServiceProvider = new CartServiceProvider(); var cart = _mappingLibraryInternal.MapPurchaseOrderToCart(subject.Request.PurchaseOrder); var party = _orderAddressMapper.Map(subject.Response.OrderAddress); var partyList = new List <Party> { party }; if (subject.Request.ExistingOrderAddress == null) { var addPartiesRequest = new AddPartiesRequest(cart, partyList); addPartiesRequest.Properties["FromUCommerce"] = true; var addPartiesResult = cartServiceProvider.AddParties(addPartiesRequest); return(PipelineExecutionResult.Success); } var updatePartiesRequest = new UpdatePartiesRequest(cart, partyList); updatePartiesRequest.Properties["FromUCommerce"] = true; var updatePartiesResult = cartServiceProvider.UpdateParties(updatePartiesRequest); return(PipelineExecutionResult.Success); }
private void EditBillingInformation(AddressSaveViewModel.Address billingAddress) { var cartServiceProvider = new CartServiceProvider(); var cart = GetCart(); var party = new Party() { Address1 = billingAddress.Line1, Address2 = billingAddress.Line2, City = billingAddress.City, Company = billingAddress.CompanyName, Country = _countries.Select().First(x => x.CountryId == billingAddress.CountryId).Name, Email = billingAddress.EmailAddress, FirstName = billingAddress.FirstName, LastName = billingAddress.LastName, PartyId = "Billing", PhoneNumber = billingAddress.PhoneNumber, State = billingAddress.State, ZipPostalCode = billingAddress.PostalCode }; var partyList = new List <Party> { party }; if (cart.Parties.Any(x => x.PartyId == party.PartyId)) { var updatePartiesRequest = new UpdatePartiesRequest(cart, partyList); var updatePartiesResult = cartServiceProvider.UpdateParties(updatePartiesRequest); return; } var addPartiesRequest = new AddPartiesRequest(cart, partyList); var addPartiesResult = cartServiceProvider.AddParties(addPartiesRequest); }
public PipelineExecutionResult Execute(IPipelineArgs <RemoveShipmentRequest, RemoveShipmentResult> subject) { if (subject.Request.Properties.ContainsKey("FromUCommerce")) { if (!(bool)subject.Request.Properties["FromUCommerce"]) { return(PipelineExecutionResult.Success); } } var cart = MappingLibrary.MapPurchaseOrderToCart(subject.Request.PurchaseOrder); var cartService = new CartServiceProvider(); var shippingList = new List <ShippingInfo> { new ShippingInfo() { ExternalId = subject.Request.Shipment.ShipmentId.ToString(), PartyID = subject.Request.Shipment.ShipmentAddress.OrderAddressId.ToString(), ShippingMethodID = subject.Request.Shipment.ShippingMethod.ShippingMethodId.ToString() } }; var request = new RemoveShippingInfoRequest(cart, shippingList); request.Properties["FromUCommerce"] = true; var result = cartService.RemoveShippingInfo(request); return(PipelineExecutionResult.Success); }
public ActionResult Index(BasketRenderingViewModel model) { var cartServiceProvider = new CartServiceProvider(); var cart = GetCart(); foreach (var orderLine in model.OrderLines) { var newQuantity = orderLine.Quantity; if (model.RemoveOrderlineId == orderLine.OrderLineId) { newQuantity = 0; } var bmw = cart.Lines.First(i => i.Product.ProductId == orderLine.Sku); bmw.Quantity = (uint)newQuantity; if (newQuantity > 0) { var updateCartLinesRequest = new UpdateCartLinesRequest(cart, new Collection <CartLine> { bmw }); cartServiceProvider.UpdateCartLines(updateCartLinesRequest); } else { var request = new RemoveCartLinesRequest(cart, cart.Lines.Where(l => l.Product.ProductId == bmw.Product.ProductId).ToArray()); cartServiceProvider.RemoveCartLines(request); } } return(Redirect("/Cart")); }
private Cart GetCart() { var cartServiceProvider = new CartServiceProvider(); var contactFactory = new ContactFactory(); string userId = contactFactory.GetContact(); var createCartRequest = new CreateOrResumeCartRequest(Context.GetSiteName(), userId); return(cartServiceProvider.CreateOrResumeCart(createCartRequest).Cart); }
/// <summary> /// Initializes a new instance of the <see cref="CartService" /> class. /// </summary> /// <param name="cartServiceProvider">The service provider.</param> /// <param name="wishListServiceProvider">The wish list service provider.</param> /// <param name="pricingServiceProvider">The pricing service provider.</param> /// <param name="shopName">Name of the shop.</param> /// <param name="contactFactory">The visitor factory.</param> /// <param name="inventoryServiceProvider">The inventory service provider.</param> /// <param name="customerServiceProvider">The customer service provider.</param> public CartService([NotNull] CartServiceProvider cartServiceProvider, [NotNull] WishListServiceProvider wishListServiceProvider, [NotNull] PricingServiceProvider pricingServiceProvider, [NotNull] string shopName, ContactFactory contactFactory, [NotNull] InventoryServiceProvider inventoryServiceProvider, [NotNull] CustomerServiceProvider customerServiceProvider) { Assert.ArgumentNotNull(cartServiceProvider, "cartServiceProvider"); Assert.ArgumentNotNull(wishListServiceProvider, "wishListServiceProvider"); Assert.ArgumentNotNull(pricingServiceProvider, "pricingServiceProvider"); Assert.ArgumentNotNull(customerServiceProvider, "customerServiceProvider"); Assert.ArgumentNotNullOrEmpty(shopName, "shopName"); this._cartServiceProvider = cartServiceProvider; this._pricingServiceProvider = pricingServiceProvider; this.shopName = shopName; this.contactFactory = contactFactory; this._inventoryServiceProvider = inventoryServiceProvider; this._customerServiceProvider = customerServiceProvider; this._wishListServiceProvider = wishListServiceProvider; }
/// <summary> /// Initializes a new instance of the <see cref="CartsServiceTest"/> class. /// </summary> public CartsServiceTest() { this.cart = new Cart(); this.cartFromAnonymous = new Cart(); this.result = new CartResult { Cart = this.cart }; this.resultFromAnonymous = new CartResult { Cart = this.cartFromAnonymous }; this.cartServiceProvider = Substitute.For <CartServiceProvider>(); this.cartServiceProvider.CreateOrResumeCart(Arg.Is <CreateOrResumeCartRequest>(r => r.UserId == "John Carter")).Returns(this.result); var pricesResult = new GetProductPricesResult(); pricesResult.Prices.Add("List", new Price(0, "USD")); this.pricingService = Substitute.For <PricingServiceProvider>(); this.pricingService.GetProductPrices(Arg.Any <GetProductPricesRequest>()).Returns(pricesResult); this.contactId = Guid.NewGuid(); this.cartServiceProvider.CreateOrResumeCart(Arg.Is <CreateOrResumeCartRequest>(r => r.UserId == ID.Parse(this.contactId).ToString())).Returns(this.resultFromAnonymous); this.cartServiceProvider.GetCarts(Arg.Any <GetCartsRequest>()).Returns(new GetCartsResult { Carts = Enumerable.Empty <CartBase>() }); this.contactFactory = Substitute.For <ContactFactory>(); this.contactFactory.GetContact().Returns("John Carter"); var inventoryResult = new GetStockInformationResult(); inventoryResult.StockInformation.ToList().Add(new StockInformation { Product = new InventoryProduct { ProductId = "1001" }, Status = StockStatus.InStock }); this._inventoryService = Substitute.For <InventoryServiceProvider>(); this._inventoryService.GetStockInformation(Arg.Any <GetStockInformationRequest>()).Returns(inventoryResult); this._customerService = Substitute.For <CustomerServiceProvider>(); this._wishListServiceProvider = Substitute.For <WishListServiceProvider>(); this.service = new CartService(this.cartServiceProvider, this._wishListServiceProvider, this.pricingService, "autohaus", this.contactFactory, this._inventoryService, this._customerService); }
public PipelineExecutionResult Execute(PurchaseOrder subject) { var cartServiceProvider = new CartServiceProvider(); var contactFactory = new ContactFactory(); string userId = contactFactory.GetContact(); var createCartRequest = new CreateOrResumeCartRequest(Context.GetSiteName(), userId); var cart = cartServiceProvider.CreateOrResumeCart(createCartRequest).Cart; var orderService = new OrderServiceProvider(); var request = new SubmitVisitorOrderRequest(cart); // Pass the PurchaseOrder object to Commerce Connect, so it can set use the data for // the page events, etc. request.Properties.Add("UCommerceOrder", subject); var result = orderService.SubmitVisitorOrder(request); return(PipelineExecutionResult.Success); }
public override void Process(ServicePipelineArgs args) { UpdateCartLinesRequest request; CartResult result; CheckParametersAndSetupRequestAndResult(args, out request, out result); using (new DisposableThreadLifestyleScope()) { if (IsFromUcommerce(request) || !args.Result.Success) { return; } var basket = _basketService.GetBasketByCartExternalId(request.Cart.ExternalId); var existingOrderLines = basket.PurchaseOrder.OrderLines; var query = (from updatedOrderLine in request.Lines join originalOrderLine in existingOrderLines on updatedOrderLine.ExternalCartLineId equals originalOrderLine.OrderLineId.ToString() into matchedOrderLines from matchedOrderLine in matchedOrderLines.DefaultIfEmpty() where matchedOrderLine == null select new { NewCartLine = updatedOrderLine }).ToList(); if (!query.Any()) { return; } var newCartLines = query.Select(x => x.NewCartLine).ToList(); var cartServiceProvider = new CartServiceProvider(); var addCartLinesRequest = new AddCartLinesRequest(request.Cart, newCartLines); cartServiceProvider.AddCartLines(addCartLinesRequest); } }
public ActionResult CreatePayment(PaymentPickerViewModel createPaymentViewModel) { var cartService = new CartServiceProvider(); var cart = GetCart(); // First remove all the existing payment info's associated with the cart. var removeRequest = new RemovePaymentInfoRequest(cart, cart.Payment.ToList()); cartService.RemovePaymentInfo(removeRequest); var paymentList = new List <PaymentInfo> { new PaymentInfo() { PaymentMethodID = createPaymentViewModel.SelectedPaymentMethodId.ToString(), } }; var addRequest = new AddPaymentInfoRequest(cart, paymentList); cartService.AddPaymentInfo(addRequest); return(Redirect("/preview")); }
public PipelineExecutionResult Execute(IPipelineArgs <UpdateLineItemRequest, UpdateLineItemResponse> subject) { if (subject.Request.Properties.ContainsKey("FromUCommerce")) { if (!(bool)subject.Request.Properties["FromUCommerce"]) { return(PipelineExecutionResult.Success); } } if (subject.Request.Quantity == 0) { var cart = MappingLibrary.MapPurchaseOrderToCart(subject.Request.OrderLine.PurchaseOrder); var cartLine = MappingLibrary.MapOrderLineToCartLine(subject.Request.OrderLine); var cartServiceProvider = new CartServiceProvider(); var request = new RemoveCartLinesRequest(cart, new Collection <CartLine> { cartLine }); request.Properties["FromUCommerce"] = true; cartServiceProvider.RemoveCartLines(request); } return(PipelineExecutionResult.Success); }
public MockCartManager(IInventoryManager inventoryManager, CartServiceProvider cartServiceProvider) { _inventoryManager = inventoryManager; _cartServiceProvider = cartServiceProvider; }
public BaseCartStringOperatorCondition() { this.CartService = (CartServiceProvider)Factory.CreateObject("cartServiceProvider", true); this.CustomerService = (CustomerServiceProvider)Factory.CreateObject("customerServiceProvider", true); }
public SampleController() { _cartServiceProvider = new CartServiceProvider(); _orderServiceProvider = new OrderServiceProvider(); }
public BraintreeController() { _cartServiceProvider = new CartServiceProvider(); _orderServiceProvider = new OrderServiceProvider(); }
/// <summary> /// Initializes a new instance of the <see cref="CartsController"/> class. /// </summary> /// <param name="cartService">The cart service.</param> public CartsController(CartServiceProvider cartService) { this.cartService = cartService; }