/// <summary>
        /// Maps <see cref="IItemCacheLineItem"/> to <see cref="BasketItem"/>.
        /// </summary>
        /// <param name="item">
        /// The item.
        /// </param>
        /// <param name="merchello">
        /// The <see cref="MerchelloHelper"/>.
        /// </param>
        /// <returns>
        /// The <see cref="BasketItem"/>.
        /// </returns>
        public static BasketItem AsBasketItem(this ILineItem item, MerchelloHelper merchello)
        {
            var product = merchello.TypedProductContent(item.ExtendedData.GetProductKey());

            var productItem = item.AsProductLineItem(merchello);

            var basketItem = AutoMapper.Mapper.Map<BasketItem>(productItem);
            basketItem.ProductKey = product.Key;
            basketItem.ProductUrl = product.Url;

            return basketItem;
        }
        /// <summary>
        /// The as product line item.
        /// </summary>
        /// <param name="item">
        /// The item.
        /// </param>
        /// <param name="merchello">
        /// The merchello.
        /// </param>
        /// <returns>
        /// The <see cref="ProductLineItem"/>.
        /// </returns>
        public static ProductLineItem AsProductLineItem(this ILineItem item, MerchelloHelper merchello)
        {
            if (!item.ExtendedData.ContainsProductKey()) return null;
            var product = merchello.TypedProductContent(item.ExtendedData.GetProductKey());
            if (product == null) return null;

            var images = product.GetPropertyValue<IEnumerable<IPublishedContent>>("images").ToArray();

            return new ProductLineItem()
            {
                Key = item.Key,
                FormattedUnitPrice = StoreHelper.FormatCurrency(item.Price),
                FormattedPrice = StoreHelper.FormatCurrency(item.TotalPrice),
                Image = images.Any() ? images.First().GetCropUrl(50, 50) : string.Empty,
                Name = item.Name,
                Quantity = item.Quantity
            };
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets the list of recently viewed items.
        /// </summary>
        /// <param name="context">
        /// The context.
        /// </param>
        /// <param name="siteAlias">
        /// The site alias.
        /// </param>
        /// <returns>
        /// The <see>
        ///         <cref>IEnumerable</cref>
        ///     </see>
        ///     .
        /// </returns>
        internal static IEnumerable<ProductBoxModel> GetRecentlyViewedProducts(this ICustomerContext context, string siteAlias = "Bazaar")
        {
            var keys = context.DeserializeRecentlyViewed().Keys;

            // Get the Merchello helper
            var merchelloHelper = new MerchelloHelper();

            // Get the products as IProductContent
            var listOfIProductContent = keys.Select(
                                            x =>
                                            merchelloHelper.TypedProductContent(x))
                                                .Reverse();

            return BazaarContentHelper.GetProductBoxModels(listOfIProductContent);
        }