Exemplo n.º 1
0
        private CartActionResult AddToCart(string name, LineItem lineItem)
        {
            string code = lineItem.Code;

            if (lineItem.Quantity < 1)
            {
                lineItem.Quantity = 1;
            }

            string messages = string.Empty;
            ICart  cart     = LoadOrCreateCart(DefaultCartName);
            var    result   = AddToCart(cart, code, lineItem.Quantity, out messages);

            // Populate with additional fields before saving
            ILineItem addedLineItem = cart.GetAllLineItems().FirstOrDefault(x => x.Code == code);

            if (addedLineItem != null)
            {
                // Need content for easier access to more information
                ContentReference itemLink     = _referenceConverter.GetContentLink(code);
                EntryContentBase entryContent = _contentLoader.Get <EntryContentBase>(itemLink);

                AddPropertiesToLineItem(addedLineItem, lineItem, entryContent);

                AddCustomProperties(lineItem, addedLineItem);
            }

            _orderRepository.Save(cart);

            // TODO: Always returns success, if we get warnings, we need to show them
            return(new CartActionResult {
                Success = true, Message = messages
            });
        }
Exemplo n.º 2
0
        public CartActionResult UpdateCart(string name, LineItem product)
        {
            var    cart           = LoadOrCreateCart(name);
            string warningMessage = string.Empty;

            var lineItem = cart.GetAllLineItems().FirstOrDefault(i => i.Code == product.Code);

            if (lineItem != null)
            {
                var shipment = cart.GetFirstShipment();
                cart.UpdateLineItemQuantity(shipment, lineItem, product.Quantity > 0 ? product.Quantity : 0);

                var validationIssues = ValidateCart(cart);

                foreach (var validationIssue in validationIssues)
                {
                    warningMessage += String.Format("Line Item with code {0} ", lineItem.Code);
                    warningMessage  = validationIssue.Value.Aggregate(warningMessage, (current, issue) => current + String.Format("{0}, ", issue));
                    warningMessage  = warningMessage.Substring(0, warningMessage.Length - 2);
                }

                _orderRepository.Save(cart);
            }

            // TODO: Should we always return success? What if the messages indicate otherwise?
            return(new CartActionResult()
            {
                Success = true, Message = warningMessage
            });
        }
Exemplo n.º 3
0
        private CartActionResult AddToCart(string name, LineItem lineItem)
        {
            CartHelper ch       = new CartHelper(name);
            string     messages = string.Empty;

            if (lineItem.Quantity < 1)
            {
                lineItem.Quantity = 1;
            }

            var entry = CatalogContext.Current.GetCatalogEntry(lineItem.Code);

            ch.AddEntry(entry, lineItem.Quantity, false, new CartHelper[] { });

            lineItem.Name = TryGetDisplayName(entry);
            //lineItem.IsInventoryAllocated = true; // Will this be enough?

            AddCustomProperties(lineItem, ch.Cart);

            messages = RunWorkflowAndReturnFormattedMessage(ch.Cart, OrderGroupWorkflowManager.CartValidateWorkflowName);
            ch.Cart.AcceptChanges();

            return(new CartActionResult()
            {
                Success = true, Message = messages
            });
        }
Exemplo n.º 4
0
        public CartActionResult MoveBetweenCarts(string fromName, string toName, LineItem product)
        {
            var result1 = RemoveFromCart(fromName, product);

            if (result1.Success)
            {
                return(AddToCart(toName, product));
            }
            return(result1);
        }
Exemplo n.º 5
0
 public CartResult AddToCart(LineItem product)
 {
     var addToCartResult = Cart.Service.AddToCart(product);
     if (addToCartResult.Success)
     {
         return GetFullCartResult(Mediachase.Commerce.Orders.Cart.DefaultName, addToCartResult.Message);
     }
     else
     {
         return new CartResult() { Result = addToCartResult.Message };
     }
 }
Exemplo n.º 6
0
 public CartResult AddToWishList(LineItem product)
 {
     var addToCartResult = Cart.Service.AddToWishList(product);
     if (addToCartResult.Success)
     {
         return GetFullCartResult(CartHelper.WishListName, addToCartResult.Message);
     }
     else
     {
         return new CartResult() { Result = addToCartResult.Message };
     }
 }
Exemplo n.º 7
0
        public CartActionResult RemoveFromCart(string name, LineItem product)
        {
            CartHelper ch   = new CartHelper(name);
            var        item = ch.Cart.OrderForms[0].LineItems.FindItemByCatalogEntryId(product.Code);

            ch.Cart.OrderForms[0].LineItems.Remove(item);
            ch.Cart.AcceptChanges();

            string messages = RunWorkflowAndReturnFormattedMessage(ch.Cart, OrderGroupWorkflowManager.CartValidateWorkflowName);

            return(new CartActionResult()
            {
                Success = true, Message = messages
            });
        }
Exemplo n.º 8
0
        private void AddCustomProperties(LineItem lineItem, ILineItem cartItem)
        {
            // Make sure we have all available data on the item before
            // we proceed
            // lineItem.UpdateData(item);

            //TODO: Let specific model implementation populate these fields, we need to know too much about the model here
            cartItem.Properties[Constants.Metadata.LineItem.DisplayName]   = lineItem.Name;
            cartItem.Properties[Constants.Metadata.LineItem.ImageUrl]      = lineItem.ImageUrl;
            cartItem.Properties[Constants.Metadata.LineItem.Size]          = lineItem.Size;
            cartItem.Properties[Constants.Metadata.LineItem.Description]   = lineItem.Description;
            cartItem.Properties[Constants.Metadata.LineItem.Color]         = lineItem.Color;
            cartItem.Properties[Constants.Metadata.LineItem.ColorImageUrl] = lineItem.ColorImageUrl;
            cartItem.Properties[Constants.Metadata.LineItem.ArticleNumber] = lineItem.ArticleNumber;
        }
Exemplo n.º 9
0
        private void AddCustomProperties(LineItem lineItem, Cart cart)
        {
            var item = cart.OrderForms[0].LineItems.FindItemByCatalogEntryId(lineItem.Code);

            //TODO: Let specific model implementation populate these fields, we need to know too much about the model here
            item[Constants.Metadata.LineItem.DisplayName]   = lineItem.Name;
            item[Constants.Metadata.LineItem.ImageUrl]      = lineItem.ImageUrl;
            item[Constants.Metadata.LineItem.Size]          = lineItem.Size;
            item[Constants.Metadata.LineItem.Description]   = lineItem.Description;
            item[Constants.Metadata.LineItem.Color]         = lineItem.Color;
            item[Constants.Metadata.LineItem.ColorImageUrl] = lineItem.ColorImageUrl;
            item[Constants.Metadata.LineItem.ArticleNumber] = lineItem.ArticleNumber;
            item[Constants.Metadata.LineItem.WineRegion]    = lineItem.WineRegion;

            cart.AcceptChanges();
        }
Exemplo n.º 10
0
        public List <LineItem> GetItems(string cart, string language)
        {
            CartHelper      ch    = new CartHelper(cart);
            List <LineItem> items = new List <LineItem>();

            if (ch.LineItems != null)
            {
                foreach (Mediachase.Commerce.Orders.LineItem lineItem in ch.LineItems)
                {
                    var item = new LineItem(lineItem, language);
                    item.UpdateData(lineItem);
                    items.Add(item);
                }
            }

            return(items);
        }
Exemplo n.º 11
0
        private void AddCustomProperties(LineItem lineItem, Cart cart)
        {
            var item = cart.OrderForms[0].LineItems.FindItemByCatalogEntryId(lineItem.Code);

            item[Constants.Metadata.LineItem.DisplayName]   = lineItem.Name;
            item[Constants.Metadata.LineItem.ImageUrl]      = lineItem.ImageUrl;
            item[Constants.Metadata.LineItem.Size]          = lineItem.Size;
            item[Constants.Metadata.LineItem.Description]   = lineItem.Description;
            item[Constants.Metadata.LineItem.Color]         = lineItem.Color;
            item[Constants.Metadata.LineItem.ColorImageUrl] = lineItem.ColorImageUrl;
            item[Constants.Metadata.LineItem.ArticleNumber] = lineItem.ArticleNumber;
            item[Constants.Metadata.LineItem.WineRegion]    = lineItem.WineRegion;



            cart.AcceptChanges();
        }
Exemplo n.º 12
0
        private CartActionResult AddToCart(string name, LineItem lineItem)
        {
            CartHelper ch       = new CartHelper(name);
            string     messages = string.Empty;

            if (lineItem.Quantity < 1)
            {
                lineItem.Quantity = 1;
            }

            // Need entry for adding to cart
            var entry = CatalogContext.Current.GetCatalogEntry(lineItem.Code);

            ch.AddEntry(entry, lineItem.Quantity, false, new CartHelper[] { });

            // Need content for easier access to more information
            ContentReference itemLink = _referenceConverter.GetContentLink(entry.CatalogEntryId,
                                                                           CatalogContentType.CatalogEntry, 0);
            EntryContentBase entryContent = _contentLoader.Get <EntryContentBase>(itemLink);

            // Populate line item with as much as we can find
            if (string.IsNullOrEmpty(lineItem.ImageUrl))
            {
                lineItem.ImageUrl = entryContent.GetDefaultImage();
            }

            if (string.IsNullOrEmpty(lineItem.ArticleNumber))
            {
                lineItem.ArticleNumber = entry.ID;
            }

            lineItem.Name = TryGetDisplayName(entry);
            //lineItem.IsInventoryAllocated = true; // Will this be enough?

            AddCustomProperties(lineItem, ch.Cart);


            messages = RunWorkflowAndReturnFormattedMessage(ch.Cart, OrderGroupWorkflowManager.CartValidateWorkflowName);
            ch.Cart.AcceptChanges();

            // TODO: Always returns success, if we get warnings, we need to show them
            return(new CartActionResult()
            {
                Success = true, Message = messages
            });
        }
Exemplo n.º 13
0
        private void AddCustomProperties(LineItem lineItem, Cart cart)
        {
            Mediachase.Commerce.Orders.LineItem item = cart.OrderForms[0].LineItems.FindItemByCatalogEntryId(lineItem.Code);

            // Make sure we have all available data on the item before
            // we proceed
            lineItem.UpdateData(item);

            //TODO: Let specific model implementation populate these fields, we need to know too much about the model here
            item[Constants.Metadata.LineItem.DisplayName]   = lineItem.Name;
            item[Constants.Metadata.LineItem.ImageUrl]      = lineItem.ImageUrl;
            item[Constants.Metadata.LineItem.Size]          = lineItem.Size;
            item[Constants.Metadata.LineItem.Description]   = lineItem.Description;
            item[Constants.Metadata.LineItem.Color]         = lineItem.Color;
            item[Constants.Metadata.LineItem.ColorImageUrl] = lineItem.ColorImageUrl;
            item[Constants.Metadata.LineItem.ArticleNumber] = lineItem.ArticleNumber;

            cart.AcceptChanges();
        }
Exemplo n.º 14
0
        public CartActionResult UpdateCart(string name, LineItem product)
        {
            CartHelper ch       = new CartHelper(name);
            string     messages = string.Empty;

            var item = ch.LineItems.FirstOrDefault(i => i.CatalogEntryId == product.Code);

            if (item != null)
            {
                item.Quantity = product.Quantity > 0 ? product.Quantity : 0;

                messages = RunWorkflowAndReturnFormattedMessage(ch.Cart, OrderGroupWorkflowManager.CartValidateWorkflowName);

                ch.Cart.AcceptChanges();
            }

            return(new CartActionResult()
            {
                Success = true, Message = messages
            });
        }
Exemplo n.º 15
0
        public CartActionResult UpdateCart(string name, LineItem product)
        {
            CartHelper ch       = new CartHelper(name);
            string     messages = string.Empty;

            var item = ch.LineItems.FirstOrDefault(i => i.Code == product.Code);

            if (item != null)
            {
                item.Quantity = product.Quantity > 0 ? product.Quantity : 0;

                messages = RunWorkflowAndReturnFormattedMessage(ch.Cart, OrderGroupWorkflowManager.CartValidateWorkflowName);

                ch.Cart.AcceptChanges();
            }

            // TODO: Should we always return success? What if the messages indicate otherwise?
            return(new CartActionResult()
            {
                Success = true, Message = messages
            });
        }
Exemplo n.º 16
0
        private void AddPropertiesToLineItem(ILineItem cartItem, LineItem addedItem, EntryContentBase entryContent)
        {
            string imageUrl = null;

            // Populate line item with as much as we can find
            if (string.IsNullOrEmpty(addedItem.ImageUrl) == false)
            {
                imageUrl = addedItem.ImageUrl;
            }
            else
            {
                imageUrl = entryContent.GetDefaultImage();
            }

            cartItem.Properties["ImageUrl"] = imageUrl;

            //if (string.IsNullOrEmpty(lineItem.ArticleNumber))
            //{
            //    lineItem.ArticleNumber = entry.ID;
            //}

            cartItem.DisplayName = entryContent.DisplayName;
        }
Exemplo n.º 17
0
 public CartResult Update(LineItem lineItem, string cartName = null)
 {
     if (string.IsNullOrEmpty(cartName))
     {
         cartName = Mediachase.Commerce.Orders.Cart.DefaultName;
     }
     var result = Cart.Service.UpdateCart(cartName, lineItem);
     return GetFullCartResult(cartName, result.Message);
 }
Exemplo n.º 18
0
 public CartResult Remove(LineItem product, string cartName = null)
 {
     if (string.IsNullOrEmpty(cartName))
     {
         cartName = Mediachase.Commerce.Orders.Cart.DefaultName;
     }
     var result = Cart.Service.RemoveFromCart(cartName, product);
     return GetFullCartResult(cartName, result.Message);
 }
Exemplo n.º 19
0
 public CartResult MoveToWishlist(LineItem product)
 {
     var result = Cart.Service.MoveBetweenCarts(Mediachase.Commerce.Orders.Cart.DefaultName, CartHelper.WishListName, product);
     return GetFullCartResult(Mediachase.Commerce.Orders.Cart.DefaultName, result.Message);
 }
Exemplo n.º 20
0
        public List<LineItem> GetItems(string cart, string language)
        {
            CartHelper ch = new CartHelper(cart);
            List<LineItem> items = new List<LineItem>();
            if (ch.LineItems != null)
            {
                foreach (Mediachase.Commerce.Orders.LineItem lineItem in ch.LineItems)
                {
                    var item = new LineItem(lineItem, language);
                    item.UpdateData(lineItem);
                    items.Add(item);
                }
            }

            return items;
        }
Exemplo n.º 21
0
 public CartActionResult AddToWishList(LineItem lineItem)
 {
     return(AddToCart(CartHelper.WishListName, lineItem));
 }
Exemplo n.º 22
0
 public CartActionResult AddToCart(LineItem lineItem)
 {
     return(AddToCart(Cart.DefaultName, lineItem));
 }
Exemplo n.º 23
0
 public CartActionResult MoveBetweenCarts(string fromName, string toName, LineItem product)
 {
     var result1 = RemoveFromCart(fromName, product);
     if (result1.Success)
     {
         return AddToCart(toName, product);
     }
     return result1;
 }
Exemplo n.º 24
0
        private void AddCustomProperties(LineItem lineItem, Cart cart)
        {
            var item = cart.OrderForms[0].LineItems.FindItemByCatalogEntryId(lineItem.Code);

            //TODO: Let specific model implementation populate these fields, we need to know too much about the model here
            item[Constants.Metadata.LineItem.DisplayName] = lineItem.Name;
            item[Constants.Metadata.LineItem.ImageUrl] = lineItem.ImageUrl;
            item[Constants.Metadata.LineItem.Size] = lineItem.Size;
            item[Constants.Metadata.LineItem.Description] = lineItem.Description;
            item[Constants.Metadata.LineItem.Color] = lineItem.Color;
            item[Constants.Metadata.LineItem.ColorImageUrl] = lineItem.ColorImageUrl;
            item[Constants.Metadata.LineItem.ArticleNumber] = lineItem.ArticleNumber;
            item[Constants.Metadata.LineItem.WineRegion] = lineItem.WineRegion;

            cart.AcceptChanges();
        }
Exemplo n.º 25
0
 public CartActionResult AddToWishList(LineItem lineItem)
 {
     return AddToCart(CartHelper.WishListName, lineItem);
 }
Exemplo n.º 26
0
        public CartActionResult RemoveFromCart(string name, LineItem product)
        {
            CartHelper ch = new CartHelper(name);
            var item = ch.Cart.OrderForms[0].LineItems.FindItemByCatalogEntryId(product.Code);
            ch.Cart.OrderForms[0].LineItems.Remove(item);
            ch.Cart.AcceptChanges();

            string messages = RunWorkflowAndReturnFormattedMessage(ch.Cart, OrderGroupWorkflowManager.CartValidateWorkflowName);

            return new CartActionResult() { Success = true, Message = messages };
        }
Exemplo n.º 27
0
        private CartActionResult AddToCart(string name, LineItem lineItem)
        {
            CartHelper ch = new CartHelper(name);
            string messages = string.Empty;

            if (lineItem.Quantity < 1)
            {
                lineItem.Quantity = 1;
            }

            // Need entry for adding to cart
            var entry = CatalogContext.Current.GetCatalogEntry(lineItem.Code);
            ch.AddEntry(entry, lineItem.Quantity, false, new CartHelper[] { });

            // Need content for easier access to more information
            ContentReference itemLink = _referenceConverter.GetContentLink(entry.CatalogEntryId,
                CatalogContentType.CatalogEntry, 0);
            EntryContentBase entryContent = _contentLoader.Get<EntryContentBase>(itemLink);

            // Populate line item with as much as we can find
            if (string.IsNullOrEmpty(lineItem.ImageUrl))
            {
                lineItem.ImageUrl = entryContent.GetDefaultImage();
            }

            if (string.IsNullOrEmpty(lineItem.ArticleNumber))
            {
                lineItem.ArticleNumber = entry.ID;
            }

            lineItem.Name = TryGetDisplayName(entry);
            //lineItem.IsInventoryAllocated = true; // Will this be enough?

            AddCustomProperties(lineItem, ch.Cart);

            messages = RunWorkflowAndReturnFormattedMessage(ch.Cart, OrderGroupWorkflowManager.CartValidateWorkflowName);
            ch.Cart.AcceptChanges();

            // TODO: Always returns success, if we get warnings, we need to show them
            return new CartActionResult() { Success = true, Message = messages };
        }
Exemplo n.º 28
0
        public CartActionResult UpdateCart(string name, LineItem product)
        {
            CartHelper ch = new CartHelper(name);
            string messages = string.Empty;

            var item = ch.LineItems.FirstOrDefault(i => i.Code == product.Code);

            if (item != null)
            {
                item.Quantity = product.Quantity > 0 ? product.Quantity : 0;

                messages = RunWorkflowAndReturnFormattedMessage(ch.Cart, OrderGroupWorkflowManager.CartValidateWorkflowName);

                ch.Cart.AcceptChanges();
            }

            // TODO: Should we always return success? What if the messages indicate otherwise?
            return new CartActionResult() { Success = true, Message = messages };
        }
Exemplo n.º 29
0
        private void AddCustomProperties(LineItem lineItem, Cart cart)
        {
            Mediachase.Commerce.Orders.LineItem item = cart.OrderForms[0].LineItems.FindItemByCatalogEntryId(lineItem.Code);

            // Make sure we have all available data on the item before
            // we proceed
            lineItem.UpdateData(item);

            //TODO: Let specific model implementation populate these fields, we need to know too much about the model here
            item[Constants.Metadata.LineItem.DisplayName] = lineItem.Name;
            item[Constants.Metadata.LineItem.ImageUrl] = lineItem.ImageUrl;
            item[Constants.Metadata.LineItem.Size] = lineItem.Size;
            item[Constants.Metadata.LineItem.Description] = lineItem.Description;
            item[Constants.Metadata.LineItem.Color] = lineItem.Color;
            item[Constants.Metadata.LineItem.ColorImageUrl] = lineItem.ColorImageUrl;
            item[Constants.Metadata.LineItem.ArticleNumber] = lineItem.ArticleNumber;

            cart.AcceptChanges();
        }
Exemplo n.º 30
0
 public CartActionResult AddToCart(LineItem lineItem)
 {
     return AddToCart(Cart.DefaultName, lineItem);
 }