public void DeleteWishlist(WishListListPart wishlist)
        {
            var user = wishlist.ContentItem.As <CommonPart>().Owner;

            //remove all elements
            foreach (var element in GetItems(wishlist))
            {
                RemoveItemFromWishlist(wishlist, element);
            }
            //destroy wishlist
            //process extensions
            foreach (var ext in _wishListExtensionProviders)
            {
                ext.WishListCleanup(user, wishlist);
            }
            if (wishlist.IsDefault)  //user must still have a default
            {
                var otherLists = GetWishLists(user).Where(wl => wl.ContentItem.Id != wishlist.ContentItem.Id);
                if (otherLists.Any())
                {
                    otherLists.First().IsDefault = true;
                }
                else
                {
                    GetDefaultWishList(user); //create a new default wishlist
                }
                wishlist.IsDefault = false;
            }
            _contentManager.Destroy(wishlist.ContentItem);
        }
        public void AddProductToWishList(IUser user, WishListListPart wishlist, ProductPart product, IDictionary <int, ProductAttributeValueExtended> attributes)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }
            //we can add the product to the wishlist
            if (!ValidateAttributes(product.ContentItem.Id, attributes))
            {
                // If attributes don't validate, don't add the product, but notify
                _notifier.Warning(T("Couldn't add this product because of invalid attributes. Please refresh the page and try again."));
                return;
            }
            //compute the ShoppingCartItem for the product we are adding
            var item = new ShoppingCartItem(product.ContentItem.Id, 1, attributes);

            //check whether the product is in the wishlist already
            if (!ItemIsInWishlist(wishlist, item))
            {
                //create a new wishlist item and add it
                var newItem = _contentManager.New <WishListItemPart>("WishListItem");
                newItem.WishListId = wishlist.ContentItem.Id;
                newItem.Item       = item;
                _contentManager.Create(newItem.ContentItem);

                //process extensions
                foreach (var ext in _wishListExtensionProviders)
                {
                    ext.WishListAddedItem(user, wishlist, newItem);
                }
            }
        }
Beispiel #3
0
 protected void LazyLoadHandlers(WishListListPart part)
 {
     part.WishListItemsField.Loader(() =>
                                    _contentManager
                                    .Query <WishListItemPart, WishListItemPartRecord>()
                                    .Where(ipr => ipr.WishListId == part.ContentItem.Id)
                                    .List()
                                    .Select(ip => ip.ContentItem)
                                    );
 }
Beispiel #4
0
 private void AddProduct(IUser user, WishListListPart wishList, int productId)
 {
     if (productId > 0)
     {
         var productPart = _contentManager.Get <ProductPart>(productId);
         if (productPart != null)
         {
             var productattributes = ParseProductAttributes();
             _wishListServices.AddProductToWishList(user, wishList, productPart, productattributes);
         }
     }
 }
        private void RemoveItemFromWishlist(WishListListPart wishlist, WishListItemPart itemPart)
        {
            //process extensions
            foreach (var ext in _wishListExtensionProviders)
            {
                ext.WishListItemCleanup(wishlist, itemPart);
            }

            var elementId = itemPart.ContentItem.Id;

            _contentManager.Destroy(itemPart.ContentItem); //hard delete
        }
        public bool TryGetWishList(IUser user, out WishListListPart wishList, int wishListId = 0)
        {
            var ret = true;

            if (wishListId == 0)
            {
                wishList = GetDefaultWishList(user);
            }
            else
            {
                wishList = GetWishList(user, wishListId);
                ret      = wishListId == wishList.ContentItem.Id;
            }
            return(ret);
        }
 public void RemoveItemFromWishlist(WishListListPart wishlist, int itemId)
 {
     RemoveItemFromWishlist(wishlist, _contentManager.Get <WishListItemPart>(itemId));
 }
 public bool ItemIsInWishlist(WishListListPart wishlist, ShoppingCartItem item)
 {
     return(GetItems(wishlist).Any(wel =>
                                   ShoppingCartItem.ItemsAreEqual(wel.Item, item)));
 }
 private IEnumerable <WishListItemPart> GetItems(WishListListPart wishlist)
 {
     return(wishlist.WishListItems.Select(it => it.As <WishListItemPart>()));
 }
 public bool TryGetWishList(out WishListListPart wishList, int wishListId = 0)
 {
     wishList = GetWishList(wishListId);
     return(wishList != null);
 }