public ManagerResponse <CartResult, Cart> CreateOrResumeCart(string shopName, string userId, string customerId)
        {
            var request    = new CreateOrResumeCartRequest(shopName, userId, Constants.DefaultCartName, customerId);
            var cartResult = this.cartServiceProvider.CreateOrResumeCart(request);

            return(new ManagerResponse <CartResult, Cart>(cartResult, cartResult.Cart));
        }
Exemplo n.º 2
0
        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));
        }
        /// <summary>
        /// The promotion cart.
        /// </summary>
        /// <param name="userName">The user Name.</param>
        /// <returns>
        /// The <see cref="GetCart" />.
        /// </returns>
        private Cart GetCart(string userName)
        {
            var request = new CreateOrResumeCartRequest(this.shopName, userName);
            var result  = this._cartServiceProvider.CreateOrResumeCart(request);

            return(result.Cart);
        }
Exemplo n.º 4
0
        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 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);
        }
Exemplo n.º 6
0
        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);
        }