public static string AssetSwatchUrl(this EntryContentBase entry)
        {
            if (entry != null)
            {
                var permanentLinkMapper = ServiceLocator.Current.GetInstance <IPermanentLinkMapper>();
                var urlResolver         = ServiceLocator.Current.GetInstance <UrlResolver>();

                if (entry.CommerceMediaCollection != null)
                {
                    foreach (var commerceMedia in entry.CommerceMediaCollection)
                    {
                        if (commerceMedia.GroupName != null && commerceMedia.GroupName.ToLower() == "swatch")
                        {
                            var contentLink = commerceMedia.AssetContentLink(permanentLinkMapper);
                            return(urlResolver.GetUrl(contentLink));
                        }
                    }

                    // Use first
                    string defaultImage = entry.GetDefaultImage("swatch");
                    return(defaultImage);
                }
            }
            return(null);
        }
 public FindProduct(EntryContentBase entryContentBase, string language)
 {
     IndexId            = entryContentBase.ContentLink.ID + "_" + language;
     Id                 = entryContentBase.ContentLink.ID;
     Name               = entryContentBase.Name;
     DisplayName        = entryContentBase.DisplayName;
     Language           = language;
     Description        = Description ?? null;
     ParentCategoryId   = entryContentBase.GetProductCategoryIds(language);
     ParentCategoryName = entryContentBase.GetParentCategoryNames(language);
     MainCategoryName   = entryContentBase.GetMainCategory(language);
     CategoryName       = entryContentBase.GetCategoryName(language);
     ProductUrl         = urlResolverInjected.Service.GetUrl(entryContentBase.ContentLink, language);
     DefaultImageUrl    = entryContentBase.GetDefaultImage();
 }
 public FindProduct(EntryContentBase entryContentBase, string language)
 {
     IndexId = entryContentBase.ContentLink.ID + "_" + language;
     Id = entryContentBase.ContentLink.ID;
     Code = entryContentBase.Code;
     Name = entryContentBase.Name;
     DisplayName = entryContentBase.DisplayName;
     Language = language;
     Description = Description ?? null;
     ParentCategoryId = entryContentBase.GetProductCategoryIds(language);
     ParentCategoryName = entryContentBase.GetParentCategoryNames(language);
     MainCategoryName = entryContentBase.GetMainCategory(language);
     CategoryName = entryContentBase.GetCategoryName(language);
     ProductUrl = urlResolverInjected.Service.GetUrl(entryContentBase.ContentLink, language);
     DefaultImageUrl = entryContentBase.GetDefaultImage();
 }
        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
            });
        }
Example #5
0
 public FindProduct(EntryContentBase entryContentBase, string language)
 {
     IndexId            = entryContentBase.ContentLink.ID + "_" + language;
     Id                 = entryContentBase.ContentLink.ID;
     Code               = entryContentBase.Code;
     Name               = entryContentBase.Name;
     DisplayName        = entryContentBase.DisplayName;
     Language           = language;
     Description        = Description ?? null;
     Overview           = Overview ?? null;
     ParentCategoryId   = entryContentBase.GetProductCategoryIds(language);
     ParentCategoryName = entryContentBase.GetParentCategoryNames(language);
     MainCategoryName   = entryContentBase.GetMainCategory(language);
     CategoryName       = entryContentBase.GetCategoryName(language);
     ProductUrl         = _urlResolver.Service.GetUrl(entryContentBase.ContentLink, language);
     DefaultImageUrl    = entryContentBase.GetDefaultImage();
     AverageRating      = entryContentBase.GetAverageRating();
     DefaultInventory   = entryContentBase.GetStock();
 }
 public FindProduct(EntryContentBase entryContentBase, string language)
 {
     IndexId = entryContentBase.ContentLink.ID + "_" + language;
     Id = entryContentBase.ContentLink.ID;
     Code = entryContentBase.Code;
     Name = entryContentBase.Name;
     DisplayName = entryContentBase.DisplayName;
     Language = language;
     Description = Description ?? null;
     Overview = Overview ?? null;
     ParentCategoryId = entryContentBase.GetProductCategoryIds(language);
     ParentCategoryName = entryContentBase.GetParentCategoryNames(language);
     MainCategoryName = entryContentBase.GetMainCategory(language);
     CategoryName = entryContentBase.GetCategoryName(language);
     ProductUrl = _urlResolver.Service.GetUrl(entryContentBase.ContentLink, language);
     DefaultImageUrl = entryContentBase.GetDefaultImage();
     AverageRating = entryContentBase.GetAverageRating();
     DefaultInventory = entryContentBase.GetStock();
 }
        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;
        }