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 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); }
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); }
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); }