/// <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 query = merchello.ProductContentQuery().Page(1).ItemsPerPage(10).OrderBy(ProductSortField.Name);

               //var defaultCollection = merchello.Query.Product.TypedProductContentSearch(1, 10);

                return new ProductContentListView(Guid.Empty, query.Execute().Items);
            }

            try
            {
                var key = new Guid(collectionKey);

                var query = merchello.ProductContentQuery().Page(1).ItemsPerPage(long.MaxValue).ConstrainByCollectionKey(key);

                return new ProductContentListView(key, query.Execute().Items);
            }
            catch (Exception ex)
            {
                MultiLogHelper.Error<ProductListViewValueConverter>("Failed to Convert Merchello.ProductListView property", ex);
                return null;
            }
        }
Beispiel #2
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 query = merchello.ProductContentQuery().Page(1).ItemsPerPage(10).OrderBy(ProductSortField.Name);

                //var defaultCollection = merchello.Query.Product.TypedProductContentSearch(1, 10);

                return(new ProductContentListView(Guid.Empty, query.Execute().Items));
            }

            try
            {
                var key = new Guid(collectionKey);

                var query = merchello.ProductContentQuery().Page(1).ItemsPerPage(long.MaxValue).ConstrainByCollectionKey(key);

                return(new ProductContentListView(key, query.Execute().Items));
            }
            catch (Exception ex)
            {
                MultiLogHelper.Error <ProductListViewValueConverter>("Failed to Convert Merchello.ProductListView property", ex);
                return(null);
            }
        }