private IProduct AddProduct(ProductDisplay product)
 {
     var p = _productService.CreateProduct(product.Name, product.Sku, product.Price);
     p = product.ToProduct(p);
     _productService.Save(p);
     return p;
 }
        ///// <summary>
        ///// Maps a <see cref="ProductDisplay"/> to <see cref="IProduct"/>
        ///// </summary>
        ///// <param name="productDisplay">
        ///// The product display.
        ///// </param>
        ///// <param name="name">
        ///// The name.
        ///// </param>
        ///// <param name="sku">
        ///// The SKU.
        ///// </param>
        ///// <param name="price">
        ///// The price.
        ///// </param>
        ///// <returns>
        ///// The <see cref="IProduct"/>.
        ///// </returns>
        //internal static IProduct ToProduct(this ProductDisplay productDisplay, string name, string sku, decimal price)
        //{
        //    var destination = MerchelloContext.Current.Services.ProductService.CreateProduct(name, sku, price);
        //    return ToProduct(productDisplay, destination);
        //}

        #endregion

        #region ProductDisplay

        /// <summary>
        /// Gets the <see cref="ProductVariantDisplay"/> with matching with attributes from the product.
        /// </summary>
        /// <param name="product">
        /// The product.
        /// </param>
        /// <param name="optionChoices">
        /// The option choices.
        /// </param>
        /// <returns>
        /// The <see cref="ProductVariantDisplay"/>.
        /// </returns>
        public static ProductVariantDisplay GetProductVariantDisplayWithAttributes(this ProductDisplay product, Guid[] optionChoices)
        {
            return
                (product.ProductVariants.FirstOrDefault(
                     x =>
                     x.Attributes.Count() == optionChoices.Count() &&
                     optionChoices.All(key => x.Attributes.FirstOrDefault(att => att.Key == key) != null)));
        }
 public static IProductContent AsProductContent(this ProductDisplay display, ProductContentFactory factory)
 {
     if (!display.HasVirtualContent())
     {
         return(null);
     }
     return(factory.BuildContent(display));
 }
        /// <summary>
        /// The to product display.
        /// </summary>
        /// <param name="result">
        /// The result.
        /// </param>
        /// <param name="getProductVariants">
        /// The get Product Variants.
        /// </param>
        /// <returns>
        /// The <see cref="ProductDisplay"/>.
        /// </returns>
        internal static ProductDisplay ToProductDisplay(this SearchResult result, Func <Guid, IEnumerable <ProductVariantDisplay> > getProductVariants)
        {
            // this should be the master variant
            var productDisplay = new ProductDisplay(result.ToProductVariantDisplay());

            productDisplay.ProductVariants = getProductVariants(productDisplay.Key);
            productDisplay.ProductOptions  = RawJsonFieldAsCollection <ProductOptionDisplay>(result, "productOptions");
            return(productDisplay);
        }
        /// <summary>
        /// The to product display.
        /// </summary>
        /// <param name="result">
        /// The result.
        /// </param>
        /// <param name="getProductVariants">
        /// The get Product Variants.
        /// </param>
        /// <param name="conversionType">
        /// The conversion Type.
        /// </param>
        /// <returns>
        /// The <see cref="ProductDisplay"/>.
        /// </returns>
        internal static ProductDisplay ToProductDisplay(this SearchResult result, Func <Guid, IEnumerable <ProductVariantDisplay> > getProductVariants, DetachedValuesConversionType conversionType = DetachedValuesConversionType.Db)
        {
            // this should be the master variant
            var productDisplay = new ProductDisplay(result.ToProductVariantDisplay());

            productDisplay.ProductVariants = getProductVariants(productDisplay.Key);
            productDisplay.ProductOptions  = RawJsonFieldAsCollection <ProductOptionDisplay>(result, "productOptions");
            productDisplay.EnsureValueConversion(conversionType);
            return(productDisplay);
        }
Example #6
0
 /// <summary>
 /// Utility for setting the IsForBackOfficeEditor property.
 /// </summary>
 /// <param name="display">
 /// The display.
 /// </param>
 /// <param name="conversionType">
 /// The value conversion type.
 /// </param>
 internal static void EnsureValueConversion(this ProductDisplay display, DetachedValuesConversionType conversionType = DetachedValuesConversionType.Db)
 {
     ((ProductDisplayBase)display).EnsureValueConversion(conversionType);
     if (display.ProductVariants.Any())
     {
         foreach (var variant in display.ProductVariants)
         {
             variant.EnsureValueConversion(conversionType);
         }
     }
 }
        public ActionResult RenderAddToCart(ProductDisplay product)
        {
            var contentId = UmbracoContext.PageId != null ? UmbracoContext.PageId.Value : 0;

            var model = new AddItemModel()
                {
                    ProductKey = product.Key,
                    ContentId = contentId
                };

            return PartialView("RosettaAddToCart", model);
        }
        /// <summary>
        /// The build content.
        /// </summary>
        /// <param name="display">
        /// The display.
        /// </param>
        /// <returns>
        /// The <see cref="IProductContent"/>.
        /// </returns>
        public IProductContent BuildContent(ProductDisplay display)
        {
            if (!display.DetachedContents.Any(x => x.CanBeRendered)) return null;

            // assert there is at least one the can be rendered
            var detachedContent = display.DetachedContents.FirstOrDefault(x => x.CanBeRendered);

            if (detachedContent == null) return null;

            var publishedContentType = PublishedContentType.Get(PublishedItemType.Content, detachedContent.DetachedContentType.UmbContentType.Alias);

            return new ProductContent(publishedContentType, display, _parent);
        }
Example #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ProductContent"/> class.
        /// </summary>
        /// <param name="contentType">
        /// The content type.
        /// </param>
        /// <param name="display">
        /// The display.
        /// </param>
        /// <param name="parent">
        /// The parent <see cref="IPublishedContent"/>
        /// </param>
        /// <param name="specificCulture">
        /// The specific culture name
        /// </param>
        /// <param name="isPreviewing">
        /// The is previewing.
        /// </param>
        public ProductContent(
            PublishedContentType contentType,
            ProductDisplay display,           
            IPublishedContent parent = null,
            string specificCulture = "en-US",
            bool isPreviewing = false)
            : base(display, contentType, specificCulture)
        {
            this._display = display;
            this._parent = parent;
            this._isPreviewing = isPreviewing;

            this.Initialize();
        }
        private IProduct AddProduct(ProductDisplay product)
        {
            var p = _productService.CreateProduct(product.Name, product.Sku, product.Price);
            p = product.ToProduct(p);
            _productService.Save(p);

            if (!p.ProductOptions.Any()) return p;

            var attributeLists = p.GetPossibleProductAttributeCombinations();

            foreach (var list  in attributeLists)
            {
                _productVariantService.CreateProductVariantWithKey(p, list.ToProductAttributeCollection());
            }

            return p;
        }
        internal static ProductDisplay ToProductDisplay(this SearchResult result)
        {
            // this should be the master variant
            var productDisplay = new ProductDisplay(result.ToProductVariantDisplay());

            var searcher = ExamineManager.Instance.SearchProviderCollection["MerchelloProductSearcher"];
            var criteria = ExamineManager.Instance.CreateSearchCriteria(IndexTypes.ProductVariant);

            criteria.Field("productKey", productDisplay.Key.ToString()).Not().Field("master", "True");

            var variants = searcher.Search(criteria);

            productDisplay.ProductVariants = variants.Select(variant => variant.ToProductVariantDisplay()).ToList();
            productDisplay.ProductOptions  = RawJsonFieldAsCollection <ProductOptionDisplay>(result, "productOptions");

            return(productDisplay);
        }
Example #12
0
        /// <summary>
        /// Turns a product into an InvoiceLineItem
        /// </summary>
        /// <param name="product"></param>
        /// <param name="qty"></param>
        /// <param name="taxIncludedInProductPrice"></param>
        /// <returns></returns>
        internal static InvoiceLineItem ToInvoiceLineItem(this ProductDisplay product, int qty = 1, bool taxIncludedInProductPrice = false)
        {
            var extendedData = new ExtendedDataCollection();

            extendedData.AddProductValues(product);

            if (taxIncludedInProductPrice)
            {
                extendedData.TryAdd(Constants.ExtendedDataKeys.TaxIncludedInProductPrice, true.ToString());
            }

            // See if this variant is on sale
            var price = product.OnSale ? product.SalePrice : product.Price;

            // TODO - Can we remove this extra step to turn into a line item
            var itemCacheLineItem = new ItemCacheLineItem(LineItemType.Product, product.Name, product.Sku, qty, price, extendedData);

            return(itemCacheLineItem.AsLineItemOf <InvoiceLineItem>());
        }
        /// <summary>
        /// The product variants as product variant content.
        /// </summary>
        /// <param name="display">
        /// The display.
        /// </param>
        /// <param name="optionContentTypes">
        /// The option Content Types.
        /// </param>
        /// <param name="cultureName">
        /// The cultureName
        /// </param>
        /// <param name="parent">
        /// The parent.
        /// </param>
        /// <returns>
        /// The <see cref="IEnumerable{IProductVariantContent}"/>.
        /// </returns>
        internal static IEnumerable <IProductVariantContent> ProductVariantsAsProductVariantContent(this ProductDisplay display, IDictionary <Guid, PublishedContentType> optionContentTypes, string cultureName, IPublishedContent parent = null)
        {
            var variantContent = new List <IProductVariantContent>();


            // ReSharper disable once LoopCanBeConvertedToQuery
            foreach (var variant in display.ProductVariants)
            {
                var contentType = variant.DetachedContents.Any()
                                      ? PublishedContentType.Get(
                    PublishedItemType.Content,
                    variant.DetachedContentForCulture(cultureName).DetachedContentType.UmbContentType.Alias)
                                      : null;

                variantContent.Add(new ProductVariantContent(variant, contentType, optionContentTypes, cultureName, parent));
            }

            return(variantContent);
        }
        /// <summary>
        /// Maps a <see cref="ProductDisplay"/> to <see cref="IProduct"/>
        /// </summary>
        /// <param name="productDisplay">
        /// The product display.
        /// </param>
        /// <param name="destination">
        /// The destination.
        /// </param>
        /// <returns>
        /// The <see cref="IProduct"/>.
        /// </returns>
        internal static IProduct ToProduct(this ProductDisplay productDisplay, IProduct destination)
        {
            if (productDisplay.Key != Guid.Empty)
            {
                destination.Key = productDisplay.Key;
            }

            productDisplay.CatalogInventories = productDisplay.CatalogInventories ?? Enumerable.Empty <CatalogInventoryDisplay>();
            productDisplay.ProductOptions     = productDisplay.ProductOptions ?? Enumerable.Empty <ProductOptionDisplay>();

            destination.Name                    = productDisplay.Name;
            destination.Sku                     = productDisplay.Sku;
            destination.Price                   = productDisplay.Price;
            destination.CostOfGoods             = productDisplay.CostOfGoods;
            destination.SalePrice               = productDisplay.SalePrice;
            destination.OnSale                  = productDisplay.OnSale;
            destination.Manufacturer            = productDisplay.Manufacturer;
            destination.ManufacturerModelNumber = productDisplay.ManufacturerModelNumber;
            destination.Weight                  = productDisplay.Weight;
            destination.Length                  = productDisplay.Length;
            destination.Width                   = productDisplay.Width;
            destination.Height                  = productDisplay.Height;
            destination.Barcode                 = productDisplay.Barcode;
            destination.Available               = productDisplay.Available;
            destination.TrackInventory          = productDisplay.TrackInventory;
            destination.OutOfStockPurchase      = productDisplay.OutOfStockPurchase;
            destination.Taxable                 = productDisplay.Taxable;
            destination.Shippable               = productDisplay.Shippable;
            destination.Download                = productDisplay.Download;
            destination.DownloadMediaId         = productDisplay.DownloadMediaId;

            // We need to refactor the CatalogInventories to not be immutable if we are
            // going to need to do operations like this.  In the UI, the user "unchecks" a catalog that was
            // previously checked - so we need to remove it.
            var deletedCatalogKeys =
                destination.CatalogInventories.Where(
                    x => !productDisplay.CatalogInventories.Select(ci => ci.CatalogKey).Contains(x.CatalogKey)).Select(x => x.CatalogKey).ToArray();

            foreach (var deletedCatalogKey in deletedCatalogKeys)
            {
                ((Product)destination).MasterVariant.RemoveFromCatalogInventory(deletedCatalogKey);
            }

            foreach (var catalogInventory in productDisplay.CatalogInventories)
            {
                var catInv = destination.CatalogInventories.FirstOrDefault(x => x.CatalogKey == catalogInventory.CatalogKey);

                if (catInv != null)
                {
                    var destinationCatalogInventory = catInv;

                    destinationCatalogInventory = catalogInventory.ToCatalogInventory(destinationCatalogInventory);
                }
                else
                {
                    //// Add to a new catalog
                    ((Product)destination).MasterVariant.AddToCatalogInventory(new CatalogInventory(catalogInventory.CatalogKey, catalogInventory.ProductVariantKey)
                    {
                        Location = catalogInventory.Location,
                        Count    = catalogInventory.Count,
                        LowCount = catalogInventory.LowCount
                    });
                }
            }

            // Fix option deletion here #M-161
            // remove any product options that exist in destination and do not exist in productDisplay
            var removers = destination.ProductOptions.Where(x => !productDisplay.ProductOptions.Select(pd => pd.Key).Contains(x.Key)).Select(x => x.Key).ToList();

            foreach (var remove in removers)
            {
                destination.ProductOptions.RemoveItem(remove);
            }


            foreach (var option in productDisplay.ProductOptions)
            {
                IProductOption destinationProductOption;


                if (destination.ProductOptions.Contains(option.Key))
                {
                    destinationProductOption = destination.ProductOptions[option.Key];

                    destinationProductOption = option.ToProductOption(destinationProductOption);
                }
                else
                {
                    destinationProductOption = new ProductOption(option.Name, option.Required);

                    destinationProductOption = option.ToProductOption(destinationProductOption);
                }

                destination.ProductOptions.Add(destinationProductOption);
            }

            destination.AddOrUpdateDetachedContent(productDisplay);

            return(destination);
        }
        /// <summary>
        /// The build content.
        /// </summary>
        /// <param name="display">
        /// The display.
        /// </param>
        /// <returns>
        /// The <see cref="IProductContent"/>.
        /// </returns>
        public IProductContent BuildContent(ProductDisplay display)
        {
            if (!display.DetachedContents.Any(x => x.CanBeRendered)) return null;

            // assert there is at least one the can be rendered
            var detachedContent = display.DetachedContents.FirstOrDefault(x => x.CanBeRendered);

            if (detachedContent == null) return null;

            var publishedContentType = PublishedContentType.Get(PublishedItemType.Content, detachedContent.DetachedContentType.UmbContentType.Alias);

            var optionContentTypes = GetProductOptionContentTypes(display);

            var clone = CloneHelper.JsonClone<ProductDisplay>(display);

            return new ProductContent(publishedContentType, optionContentTypes, clone, _parent, _defaultStoreLanguage);
        }
        public ProductDisplay AddProduct(ProductDisplay product)
        {
            var merchProduct = _productService.CreateProduct(product.Name, product.Sku, product.Price);

            merchProduct = product.ToProduct(merchProduct);
            _productService.Save(merchProduct);
            return merchProduct.ToProductDisplay(DetachedValuesConversionType.Editor);
        }
Example #17
0
 /// <summary>
 /// Adds a <see cref="ProductDisplay"/> to the item cache
 /// </summary>
 /// <param name="product">The <see cref="ProductDisplay"/> to be added</param>
 /// <param name="name">Override for the name of the product in the line item</param>
 /// <param name="quantity">The quantity to be represented</param>
 /// <remarks>
 /// If the product has variants, the "first" variant found will be added.
 /// </remarks>
 public void AddItem(ProductDisplay product, string name, int quantity)
 {
     AddItem(product, name, quantity, new ExtendedDataCollection());
 }
Example #18
0
 /// <summary>
 /// Adds a <see cref="ProductDisplay"/> to the item cache
 /// </summary>
 /// <param name="product">The <see cref="ProductDisplay"/> to be added</param>
 /// <remarks>
 /// If the product has variants, the "first" variant found will be added.
 /// </remarks>
 public void AddItem(ProductDisplay product)
 {
     AddItem(product, 1);
 }
        public ProductDisplay PutProduct(ProductDisplay product)
        {
            var merchProduct = _productService.GetByKey(product.Key);

            if (product.DetachedContents.Any())
            {
                foreach (var c in product.DetachedContents.Select(x => x.CultureName))
                {
                    var pcs = new ProductContentSave { CultureName = c, Display = product };
                    ProductVariantDetachedContentHelper<ProductContentSave, ProductDisplay>.MapDetachedProperties(pcs);
                }
            }

            merchProduct = product.ToProduct(merchProduct);

            _productService.Save(merchProduct);

            return merchProduct.ToProductDisplay(DetachedValuesConversionType.Editor);
        }
        /// <summary>
        /// The product variants as product variant content.
        /// </summary>
        /// <param name="display">
        /// The display.
        /// </param>
        /// <param name="optionContentTypes">
        /// The option Content Types.
        /// </param>
        /// <param name="optionWrappers">
        /// Product option content wrappers.
        /// </param>
        /// <param name="cultureName">
        /// The cultureName
        /// </param>
        /// <param name="parent">
        /// The parent.
        /// </param>
        /// <returns>
        /// The <see cref="IEnumerable{IProductVariantContent}"/>.
        /// </returns>
        internal static IEnumerable <IProductVariantContent> ProductVariantsAsProductVariantContent(this ProductDisplay display, IDictionary <Guid, PublishedContentType> optionContentTypes, IEnumerable <IProductOptionWrapper> optionWrappers, string cultureName, IPublishedContent parent = null)
        {
            var variantContent = new List <IProductVariantContent>();


            // ReSharper disable once LoopCanBeConvertedToQuery
            var optionWrapperArray = optionWrappers as IProductOptionWrapper[] ?? optionWrappers.ToArray();

            foreach (var variant in display.ProductVariants)
            {
                var contentType = variant.DetachedContents.Any()
                                      ? PublishedContentType.Get(
                    PublishedItemType.Content,
                    variant.DetachedContentForCulture(cultureName).DetachedContentType.UmbContentType.Alias)
                                      : null;

                var attributes = new List <IProductAttributeContent>();
                foreach (var o in optionWrapperArray)
                {
                    var att = o.Choices.FirstOrDefault(x => variant.Attributes.Select(y => y.Key).Contains(x.Key));
                    if (att != null)
                    {
                        attributes.Add(att);
                    }
                }

                variantContent.Add(new ProductVariantContent(variant, contentType, optionContentTypes, attributes, cultureName, parent));
            }

            return(variantContent);
        }
        internal static IProduct ToProduct(this ProductDisplay productDisplay, string name, string sku, decimal price)
        {
            var destination = MerchelloContext.Current.Services.ProductService.CreateProduct(name, sku, price);

            return(ToProduct(productDisplay, destination));
        }
        internal static IProduct ToProduct(this ProductDisplay productDisplay, IProduct destination)
        {
            if (productDisplay.Key != Guid.Empty)
            {
                destination.Key = productDisplay.Key;
            }
            destination.Name                    = productDisplay.Name;
            destination.Sku                     = productDisplay.Sku;
            destination.Price                   = productDisplay.Price;
            destination.CostOfGoods             = productDisplay.CostOfGoods;
            destination.SalePrice               = productDisplay.SalePrice;
            destination.OnSale                  = productDisplay.OnSale;
            destination.Manufacturer            = productDisplay.Manufacturer;
            destination.ManufacturerModelNumber = productDisplay.ManufacturerModelNumber;
            destination.Weight                  = productDisplay.Weight;
            destination.Length                  = productDisplay.Length;
            destination.Width                   = productDisplay.Width;
            destination.Height                  = productDisplay.Height;
            destination.Barcode                 = productDisplay.Barcode;
            destination.Available               = productDisplay.Available;
            destination.TrackInventory          = productDisplay.TrackInventory;
            destination.OutOfStockPurchase      = productDisplay.OutOfStockPurchase;
            destination.Taxable                 = productDisplay.Taxable;
            destination.Shippable               = productDisplay.Shippable;
            destination.Download                = productDisplay.Download;
            destination.DownloadMediaId         = productDisplay.DownloadMediaId;

            foreach (var catalogInventory in productDisplay.CatalogInventories)
            {
                ICatalogInventory destinationCatalogInventory;

                var catInv = destination.CatalogInventories.First(x => x.CatalogKey == catalogInventory.CatalogKey);
                if (catInv != null)
                {
                    destinationCatalogInventory = catInv;

                    destinationCatalogInventory = catalogInventory.ToCatalogInventory(destinationCatalogInventory);
                }
            }

            // Fix option deletion here #M-161
            // remove any product options that exist in destination and do not exist in productDisplay
            var removers = destination.ProductOptions.Where(x => !productDisplay.ProductOptions.Select(pd => pd.Key).Contains(x.Key)).Select(x => x.Key);

            foreach (var remove in removers)
            {
                destination.ProductOptions.RemoveItem(remove);
            }


            foreach (var option in productDisplay.ProductOptions)
            {
                IProductOption destinationProductOption;


                if (destination.ProductOptions.Contains(option.Key))
                {
                    destinationProductOption = destination.ProductOptions[option.Key];

                    destinationProductOption = option.ToProductOption(destinationProductOption);
                }
                else
                {
                    destinationProductOption = new ProductOption(option.Name, option.Required);

                    destinationProductOption = option.ToProductOption(destinationProductOption);
                }

                destination.ProductOptions.Add(destinationProductOption);
            }

            return(destination);
        }
Example #23
0
        public ProductDisplay PutProduct(ProductDisplay product)
        {            
            var merchProduct = _productService.GetByKey(product.Key);         
            merchProduct = product.ToProduct(merchProduct);
            _productService.Save(merchProduct);

            if (!merchProduct.ProductOptions.Any()) return merchProduct.ToProductDisplay();



            // verify that all attributes have been created
            var attributeLists = merchProduct.GetPossibleProductAttributeCombinations().ToArray();
            foreach (var list in from list in attributeLists let variant = merchProduct.GetProductVariantForPurchase(list) where variant == null select list)
            {
                _productVariantService.CreateProductVariantWithKey(merchProduct, list.ToProductAttributeCollection());
            }

            return merchProduct.ToProductDisplay();
        }
Example #24
0
        public ProductDisplay AddProduct(ProductDisplay product)
        {
            var merchProduct = _productService.CreateProduct(product.Name, product.Sku, product.Price);

            merchProduct = product.ToProduct(merchProduct);
            _productService.Save(merchProduct);

            // special case where a catalog was associated before the creation of the product
            if (product.CatalogInventories.Any())
            {
                foreach (var cat in product.CatalogInventories)
                {
                    ((Product)merchProduct).MasterVariant.AddToCatalogInventory(cat.CatalogKey);
                }
            }

            _productService.Save(merchProduct);

            if (!merchProduct.ProductOptions.Any()) return merchProduct.ToProductDisplay();

            var attributeLists = merchProduct.GetPossibleProductAttributeCombinations();

            foreach (var list in attributeLists)
            {
                _productVariantService.CreateProductVariantWithKey(merchProduct, list.ToProductAttributeCollection());
            }

            return merchProduct.ToProductDisplay();
        }
 /// <summary>
 /// Returns a value indicating whether or not this object can be rendered as virtual content.
 /// </summary>
 /// <param name="display">
 /// The display.
 /// </param>
 /// <returns>
 /// The <see cref="bool"/>.
 /// </returns>
 public static bool HasVirtualContent(this ProductDisplay display)
 {
     return(display.Available && display.DetachedContents.Any(x => x.CanBeRendered));
 }
Example #26
0
        public HttpResponseMessage PutProduct(ProductDisplay product)
        {
            var response = Request.CreateResponse(HttpStatusCode.OK);

            try
            {
                IProduct merchProduct = _productService.GetByKey(product.Key);
                merchProduct = product.ToProduct(merchProduct);

                _productService.Save(merchProduct);
            }
            catch (Exception ex)
            {
                response = Request.CreateResponse(HttpStatusCode.NotFound, String.Format("{0}", ex.Message));
            }

            return response;
        }
 public static IProductContent AsProductContent(this ProductDisplay display)
 {
     return(display.AsProductContent(new ProductContentFactory()));
 }
Example #28
0
        public ProductDisplay AddProduct(ProductDisplay product)
        {
            var merchProduct = _productService.CreateProduct(product.Name, product.Sku, product.Price);

            merchProduct = product.ToProduct(merchProduct);
            _productService.Save(merchProduct);

            _productService.Save(merchProduct);

            return merchProduct.ToProductDisplay();
        }
        public ProductDisplay CreateProduct(ProductDisplay product)
        {
            // we need to remove the detached content to generate the product to begin with due to db foreign keys
            var detachedContents = product.DetachedContents.ToArray();
            product.DetachedContents = Enumerable.Empty<ProductVariantDetachedContentDisplay>();

            // First create the product record and save it
            var merchProduct = _productService.CreateProduct(product.Name, product.Sku, product.Price);
            merchProduct = product.ToProduct(merchProduct);

            // we don't want to raise events here since we will be saving again and there is no sense
            // in having examine index it twice. Use the detached contents to determine whether we need to fire event
            _productService.Save(merchProduct, !detachedContents.Any());

            if (!detachedContents.Any()) return merchProduct.ToProductDisplay(DetachedValuesConversionType.Editor);

            // convert the product back so we can reassociate the detached content.
            product = merchProduct.ToProductDisplay();

            // asscociate the product variant key (master variant) with the detached content
            foreach (var pvdc in detachedContents)
            {
                pvdc.ProductVariantKey = merchProduct.ProductVariantKey;
            }

            // add the detached contents back
            product.DetachedContents = detachedContents;

            // this adds the detached content to the product
            merchProduct = product.ToProduct(merchProduct);
            _productService.Save(merchProduct);

            return merchProduct.ToProductDisplay(DetachedValuesConversionType.Editor);
        }
Example #30
0
        public ProductDisplay PutProduct(ProductDisplay product)
        {
            var merchProduct = _productService.GetByKey(product.Key);

            merchProduct = product.ToProduct(merchProduct);

            _productService.Save(merchProduct);

            return merchProduct.ToProductDisplay();
        }
Example #31
0
 /// <summary>
 /// Adds a <see cref="ProductDisplay"/> to the item cache
 /// </summary>
 /// <param name="product">The <see cref="ProductDisplay"/> to be added</param>
 /// <param name="quantity">The quantity to be represented</param>
 /// <remarks>
 /// If the product has variants, the "first" variant found will be added.
 /// </remarks>
 public void AddItem(ProductDisplay product, int quantity)
 {
     AddItem(product, product.Name, quantity);
 }
Example #32
0
        public ProductDisplay NewProductFromProduct(ProductDisplay product)
        {
            IProduct newProduct = null;

            try
            {
                newProduct = _productService.CreateProduct(product.Name, product.Sku, product.Price);
                _productService.Save(newProduct);

                newProduct.AddToCatalogInventory(_warehouseService.GetDefaultWarehouse().DefaultCatalog());

                newProduct = product.ToProduct(newProduct);
                _productService.Save(newProduct);
            }
            catch (Exception ex)
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.InternalServerError));
            }

            return newProduct.ToProductDisplay();
        }
Example #33
0
 /// <summary>
 /// Adds a <see cref="ProductDisplay"/> to the item cache
 /// </summary>
 /// <param name="product">
 /// The <see cref="ProductDisplay"/> to be added
 /// </param>
 /// <param name="name">
 /// Override for the name of the product in the line item
 /// </param>
 /// <param name="quantity">
 /// The quantity to be represented
 /// </param>
 /// <param name="extendedData">
 /// The extended Data.
 /// </param>
 /// <remarks>
 /// If the product has variants, the "first" variant found will be added.
 /// </remarks>
 public void AddItem(ProductDisplay product, string name, int quantity, ExtendedDataCollection extendedData)
 {
     var variant = product.ProductVariants.Any() ?
                 product.ProductVariants.First() :
                 product.AsMasterVariantDisplay();
     AddItem(variant, name == product.Name ? variant.Name : name, quantity, extendedData);
 }
 /// <summary>
 /// Maps a <see cref="ProductDisplay"/> to <see cref="ProductVariantDisplay"/>.
 /// </summary>
 /// <param name="product">
 /// The product.
 /// </param>
 /// <returns>
 /// The <see cref="ProductVariantDisplay"/>.
 /// </returns>
 /// <remarks>
 /// Used for adding items to item caches in <see cref="CustomerItemCacheBase"/>
 /// </remarks>
 public static ProductVariantDisplay AsMasterVariantDisplay(this ProductDisplay product)
 {
     return(AutoMapper.Mapper.Map <ProductVariantDisplay>(product));
 }
 /// <summary>
 /// Adds product values
 /// </summary>
 /// <param name="extendedData">
 /// The extended data
 /// </param>
 /// <param name="product">
 /// The product variant
 /// </param>
 public static void AddProductValues(this ExtendedDataCollection extendedData, ProductDisplay product)
 {
     extendedData.SetValue(Constants.ExtendedDataKeys.ProductKey, product.Key.ToString());
     extendedData.SetValue(Constants.ExtendedDataKeys.ProductVariantKey, product.ProductVariantKey.ToString());
     AddBaseProductValues(extendedData, product);
 }
        /// <summary>
        /// Gets the collection of <see cref="PublishedContentType"/> associated with product options.
        /// </summary>
        /// <param name="display">
        /// The display.
        /// </param>
        /// <returns>
        /// The <see cref="IEnumerable{PublishedItemType}"/>.
        /// </returns>
        private IDictionary<Guid, PublishedContentType> GetProductOptionContentTypes(ProductDisplay display)
        {
            var keys =
                display.ProductOptions.Where(x => !x.DetachedContentTypeKey.Equals(Guid.Empty))
                    .Select(x => x.DetachedContentTypeKey)
                    .Distinct().ToArray();

            var publishedContentTypes = new Dictionary<Guid, PublishedContentType>();

            if (!keys.Any()) return publishedContentTypes;

            var contentTypeKeys = _detachedContentTypes.Value
                    .Where(x => keys.Any(y => y == x.Key)).Where(x => x.ContentTypeKey != null)
                    .Select(x => x.ContentTypeKey.Value);

            var contentTypes = ApplicationContext.Current.Services.ContentTypeService.GetAllContentTypes(contentTypeKeys);

            foreach (var ct in contentTypes)
            {
                var dct = _detachedContentTypes.Value.FirstOrDefault(x => x.ContentTypeKey != null && x.ContentTypeKey.Value == ct.Key);
                if (dct != null)
                publishedContentTypes.Add(dct.Key, PublishedContentType.Get(PublishedItemType.Content, ct.Alias));
            }

            return publishedContentTypes;
        }