Example #1
0
        /// <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
            });
        }
        /// <summary>
        /// The convert data to source.
        /// </summary>
        /// <param name="propertyType">
        /// The property type.
        /// </param>
        /// <param name="source">
        /// The source.
        /// </param>
        /// <param name="preview">
        /// The preview.
        /// </param>
        /// <returns>
        /// The <see cref="object"/>.
        /// </returns>
        public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview)
        {
            var merchello = new MerchelloHelper();

            if (source == null)
                return null;

            var collectionKey = source.ToString();

            if (collectionKey.IsNullOrWhiteSpace())
            {

                var defaultCollection = merchello.Query.Product.Search(1, 10)
                    .Items.Select(x => merchello.TypedProductContent(((ProductDisplay)x).Key));

                return new ProductContentListView(Guid.Empty, defaultCollection);
            }

            try
            {
                var key = new Guid(collectionKey);
                return new ProductContentListView(key, merchello.TypedProductContentFromCollection(key));
            }
            catch (Exception ex)
            {
                MultiLogHelper.Error<ProductDisplayValueConverter>("Failed to Convert ProductDisplay property", ex);
                return null;
            }
        }
Example #3
0
        /// <summary>
        /// The convert data to source.
        /// </summary>
        /// <param name="propertyType">
        /// The property type.
        /// </param>
        /// <param name="source">
        /// The source.
        /// </param>
        /// <param name="preview">
        /// The preview.
        /// </param>
        /// <returns>
        /// The <see cref="object"/>.
        /// </returns>
        public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview)
        {
            var merchello = new MerchelloHelper();

            if (source == null)
            {
                return(null);
            }

            var collectionKey = source.ToString();

            if (collectionKey.IsNullOrWhiteSpace())
            {
                var defaultCollection = merchello.Query.Product.Search(1, 10)
                                        .Items.Select(x => merchello.TypedProductContent(((ProductDisplay)x).Key));

                return(new ProductContentListView(Guid.Empty, defaultCollection));
            }

            try
            {
                var key = new Guid(collectionKey);
                return(new ProductContentListView(key, merchello.TypedProductContentFromCollection(key)));
            }
            catch (Exception ex)
            {
                MultiLogHelper.Error <ProductDisplayValueConverter>("Failed to Convert ProductDisplay property", ex);
                return(null);
            }
        }
Example #4
0
        /// <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);
        }
Example #5
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));
        }
Example #6
0
        /// <summary>
        /// The build product payment details item type.
        /// </summary>
        /// <param name="item">
        /// The item.
        /// </param>
        /// <param name="factory">
        /// The <see cref="PayPalBasicAmountTypeFactory"/>.
        /// </param>
        /// <returns>
        /// The <see cref="PaymentDetailsItemType"/>.
        /// </returns>
        protected virtual PaymentDetailsItemType BuildProductPaymentDetailsItemType(ILineItem item, PayPalBasicAmountTypeFactory factory)
        {
            IProductContent product = null;

            if (_settings.UsesProductContent)
            {
                var productKey = item.ExtendedData.GetProductKey();
                product = _merchello.TypedProductContent(productKey);
            }

            var detailsItemType = new PaymentDetailsItemType
            {
                Name    = item.Name,
                ItemURL = product != null?
                          string.Format("{0}{1}", _settings.WebsiteUrl, product.Url) :
                              null,
                              Amount   = factory.Build(item.Price),
                              Quantity = item.Quantity
            };

            return(detailsItemType);
        }
Example #7
0
        /// <summary>
        /// Builds a <see cref="BasketLineItem"/>
        /// </summary>
        /// <param name="lineItem">
        /// The line item.
        /// </param>
        /// <returns>
        /// The <see cref="BasketLineItem"/>.
        /// </returns>
        public BasketLineItem Build(ILineItem lineItem)
        {
            var contentId = lineItem.ExtendedData.ContainsKey("umbracoContentId")
                                ? int.Parse(lineItem.ExtendedData["umbracoContentId"])
                                : 0;

            var          productKey = lineItem.ExtendedData.GetProductKey();
            ProductModel product    = null;

            if (!productKey.Equals(Guid.Empty))
            {
                var productContent = _merchello.TypedProductContent(productKey);
                if (productContent != null)
                {
                    product = new ProductModel(productContent)
                    {
                        CurrentCustomer = _currentCustomer,
                        Currency        = _currency
                    }
                }
                ;
            }


            var basketLineItem = new BasketLineItem
            {
                Key          = lineItem.Key,
                ContentId    = contentId,
                Name         = lineItem.Name,
                Sku          = lineItem.Sku,
                UnitPrice    = lineItem.Price,
                TotalPrice   = lineItem.TotalPrice,
                Quantity     = lineItem.Quantity,
                ExtendedData = lineItem.ExtendedData,
                Product      = product ?? this.HandleLegacyBazaarProductContent(contentId)
            };

            return(basketLineItem);
        }
        /// <summary>
        /// The convert data to source.
        /// </summary>
        /// <param name="propertyType">
        /// The property type.
        /// </param>
        /// <param name="source">
        /// The source.
        /// </param>
        /// <param name="preview">
        /// The preview.
        /// </param>
        /// <returns>
        /// The <see cref="object"/>.
        /// </returns>
        public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview)
        {
            var merchello = new MerchelloHelper();

            if (source == null)
                return null;

            var productKeys = JsonConvert.DeserializeObject<IEnumerable<Guid>>(source.ToString());

            try
            {
                var products = productKeys.Select(key => merchello.TypedProductContent(key)).ToList();

                return products;

            }
            catch (Exception ex)
            {
                LogHelper.Error<ProductDisplayValueConverter>("Failed to Convert ProductDisplay property", ex);
                return null;
            }
        }
Example #9
0
        /// <summary>
        /// The convert data to source.
        /// </summary>
        /// <param name="propertyType">
        /// The property type.
        /// </param>
        /// <param name="source">
        /// The source.
        /// </param>
        /// <param name="preview">
        /// The preview.
        /// </param>
        /// <returns>
        /// The <see cref="object"/>.
        /// </returns>
        public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview)
        {
            var merchello = new MerchelloHelper();

            if (source == null)
            {
                return(null);
            }

            var productKeys = JsonConvert.DeserializeObject <IEnumerable <Guid> >(source.ToString());

            try
            {
                var products = productKeys.Select(key => merchello.TypedProductContent(key)).ToList();

                return(products);
            }
            catch (Exception ex)
            {
                MultiLogHelper.WarnWithException <MultiProductPickerValueConverter>("Failed to Convert property to IProductContent", ex);
                return(null);
            }
        }