public WishListJsonResult GetWishList(IStorefrontContext storefrontContext, IVisitorContext visitorContext)
        {
            Assert.ArgumentNotNull((object)storefrontContext, nameof(storefrontContext));
            Assert.ArgumentNotNull((object)visitorContext, nameof(visitorContext));
            WishListJsonResult model             = this.ModelProvider.GetModel <WishListJsonResult>();
            CommerceStorefront currentStorefront = storefrontContext.CurrentStorefront;
            ManagerResponse <GetWishListResult, WishList> currentWishList = this.WishListManager.GetWishList(visitorContext, storefrontContext);

            if (!currentWishList.ServiceProviderResult.Success || currentWishList.Result == null)
            {
                string systemMessage = "Wish List not found.";
                currentWishList.ServiceProviderResult.SystemMessages.Add(new SystemMessage()
                {
                    Message = systemMessage
                });
                model.SetErrors((ServiceProviderResult)currentWishList.ServiceProviderResult);
                return(model);
            }

            if (!currentWishList.ServiceProviderResult.Success)
            {
                model.SetErrors((ServiceProviderResult)currentWishList.ServiceProviderResult);
                return(model);
            }
            model.Initialize(currentWishList.Result);
            model.Success = true;
            return(model);
        }
Beispiel #2
0
        public virtual WishListJsonResult RemoveWishListLines(IStorefrontContext storefrontContext, IVisitorContext visitorContext, List <string> wishListLineIds)
        {
            Assert.ArgumentNotNull(storefrontContext, nameof(storefrontContext));
            Assert.ArgumentNotNull(visitorContext, nameof(visitorContext));
            Assert.ArgumentNotNull(wishListLineIds, nameof(wishListLineIds));
            WishListJsonResult model             = _modelProvider.GetModel <WishListJsonResult>();
            CommerceStorefront currentStorefront = storefrontContext.CurrentStorefront;
            ManagerResponse <GetWishListResult, WishList> currentWishList = _wishListManager.GetWishList(visitorContext, storefrontContext);

            if (!currentWishList.ServiceProviderResult.Success || currentWishList.Result == null)
            {
                string systemMessage = "Wish List not found.";
                currentWishList.ServiceProviderResult.SystemMessages.Add(new SystemMessage
                {
                    Message = systemMessage
                });

                model.SetErrors(currentWishList.ServiceProviderResult);
                return(model);
            }
            ManagerResponse <RemoveWishListLinesResult, WishList> managerResponse = _wishListManager.RemoveWishListLines(currentStorefront, visitorContext, currentWishList.Result, wishListLineIds);

            if (!managerResponse.ServiceProviderResult.Success)
            {
                model.SetErrors(managerResponse.ServiceProviderResult);
                return(model);
            }
            model.Initialize(managerResponse.Result);
            model.Success = true;
            return(model);
        }
        // Not implemented
        public virtual WishListJsonResult UpdateWishListLines(IStorefrontContext storefrontContext, IVisitorContext visitorContext, string lineNumber, Decimal quantity)
        {
            Assert.ArgumentNotNull((object)storefrontContext, nameof(storefrontContext));
            Assert.ArgumentNotNull((object)visitorContext, nameof(visitorContext));
            Assert.ArgumentNotNull((object)lineNumber, nameof(lineNumber));
            Assert.IsTrue(quantity > Decimal.Zero, "quantity > 0");
            WishListJsonResult model             = this.ModelProvider.GetModel <WishListJsonResult>();
            CommerceStorefront currentStorefront = storefrontContext.CurrentStorefront;
            ManagerResponse <GetWishListResult, WishList> currentWishList = this.WishListManager.GetWishList(visitorContext, storefrontContext);

            if (!currentWishList.ServiceProviderResult.Success || currentWishList.Result == null)
            {
                string systemMessage = "Wish List not found.";
                currentWishList.ServiceProviderResult.SystemMessages.Add(new SystemMessage()
                {
                    Message = systemMessage
                });
                model.SetErrors((ServiceProviderResult)currentWishList.ServiceProviderResult);
                return(model);
            }
            CartLineUpdateArgument lineUpdateArgument = new CartLineUpdateArgument()
            {
                ExternalLineId = lineNumber,
                LineArguments  =
                {
                    Quantity = quantity
                }
            };
            ManagerResponse <UpdateWishListLinesResult, WishList> managerResponse = this.WishListManager.UpdateWishListLines(currentStorefront, currentWishList.Result, new List <CartLineUpdateArgument>()
            {
                lineUpdateArgument
            });

            if (!managerResponse.ServiceProviderResult.Success)
            {
                model.SetErrors((ServiceProviderResult)managerResponse.ServiceProviderResult);
                return(model);
            }
            model.Initialize(managerResponse.Result);
            model.Success = true;
            return(model);
        }
        public virtual WishListJsonResult AddWishListLine(IStorefrontContext storefrontContext, IVisitorContext visitorContext, string catalogName, string productId, string variantId, Decimal quantity)
        {
            Assert.ArgumentNotNull((object)storefrontContext, nameof(storefrontContext));
            Assert.ArgumentNotNull((object)visitorContext, nameof(visitorContext));
            WishListJsonResult model             = this.ModelProvider.GetModel <WishListJsonResult>();
            CommerceStorefront currentStorefront = storefrontContext.CurrentStorefront;
            ManagerResponse <GetWishListResult, WishList> currentWishList = this.WishListManager.GetWishList(visitorContext, storefrontContext);

            if (!currentWishList.ServiceProviderResult.Success || currentWishList.Result == null)
            {
                string systemMessage = "Wish List not found.";
                currentWishList.ServiceProviderResult.SystemMessages.Add(new SystemMessage()
                {
                    Message = systemMessage
                });
                model.SetErrors((ServiceProviderResult)currentWishList.ServiceProviderResult);
                return(model);
            }

            List <WishListLine> wishListLines = new List <WishListLine>();
            var wishlistLine = new WishListLine()
            {
                Quantity = quantity, Product = new Commerce.Entities.Carts.CartProduct()
                {
                    ProductId = catalogName + "|" + productId + "|" + variantId,
                }
            };

            wishListLines.Add(wishlistLine);

            ManagerResponse <AddLinesToWishListResult, WishList> managerResponse = this.WishListManager.AddLinesToWishList(currentStorefront, visitorContext, currentWishList.Result, wishListLines);

            if (!managerResponse.ServiceProviderResult.Success)
            {
                model.SetErrors((ServiceProviderResult)managerResponse.ServiceProviderResult);
                return(model);
            }
            model.Initialize(managerResponse.Result);
            model.Success = true;
            return(model);
        }