Beispiel #1
0
 public ProductFactory(ProductAttributeCollection productAttributes,
                       CatalogInventoryCollection catalogInventories, ProductOptionCollection productOptions, ProductVariantCollection productVariantCollection)
 {
     _productVariantFactory    = new ProductVariantFactory(productAttributes, catalogInventories);
     _productOptionCollection  = productOptions;
     _productVariantCollection = productVariantCollection;
 }
Beispiel #2
0
        private ProductOptionCollection GetProductOptionCollection(Guid productKey)
        {
            var sql = new Sql();

            sql.Select("*")
            .From <ProductOptionDto>()
            .InnerJoin <Product2ProductOptionDto>()
            .On <ProductOptionDto, Product2ProductOptionDto>(left => left.Key, right => right.OptionKey)
            .Where <Product2ProductOptionDto>(x => x.ProductKey == productKey)
            .OrderBy <Product2ProductOptionDto>(x => x.SortOrder);

            var dtos = Database.Fetch <ProductOptionDto, Product2ProductOptionDto>(sql);

            var productOptions = new ProductOptionCollection();
            var factory        = new ProductOptionFactory();

            foreach (var option in dtos.Select(factory.BuildEntity))
            {
                var attributes = GetProductAttributeCollection(option.Key);
                option.Choices = attributes;
                productOptions.Insert(0, option);
            }

            return(productOptions);
        }
Beispiel #3
0
        public Product(IProductVariant variant, ProductOptionCollection productOptions, ProductVariantCollection productVariants)
        {
            Mandate.ParameterNotNull(variant, "variantMaster");
            Mandate.ParameterNotNull(productOptions, "optionCollection");
            Mandate.ParameterNotNull(productVariants, "productVariants");

            _variant = variant;
            _productOptions = productOptions;
            _productVariants = productVariants;
        }
 private static void IndexProductVariant(IProductVariant productVariant, ProductOptionCollection productOptions)
 {
     ExamineManager.Instance.IndexProviderCollection["MerchelloProductIndexer"].ReIndexNode(productVariant.SerializeToXml(productOptions).Root, IndexTypes.ProductVariant);
 }
Beispiel #5
0
 private static void IndexProductVariant(IProductVariant productVariant, ProductOptionCollection productOptions)
 {
     ExamineManager.Instance.IndexProviderCollection["MerchelloProductIndexer"].ReIndexNode(productVariant.SerializeToXml(productOptions).Root, IndexTypes.ProductVariant);
 }
Beispiel #6
0
 internal static string ToJsonProductOptions(this ProductOptionCollection productOptionCollection)
 {
     return(GetProductOptionsJson(productOptionCollection));
 }
Beispiel #7
0
        internal static XDocument SerializeToXml(this IProductVariant productVariant, ProductOptionCollection productOptionCollection = null)
        {
            string xml;

            using (var sw = new StringWriter())
            {
                using (var writer = new XmlTextWriter(sw))
                {
                    writer.WriteStartDocument();
                    writer.WriteStartElement("productVariant");
                    // TODO construct the id
                    writer.WriteAttributeString("id", ((ProductVariant)productVariant).ExamineId.ToString(CultureInfo.InvariantCulture));
                    writer.WriteAttributeString("productKey", productVariant.ProductKey.ToString());
                    writer.WriteAttributeString("productVariantKey", productVariant.Key.ToString());
                    writer.WriteAttributeString("master", ((ProductVariant)productVariant).Master.ToString());
                    writer.WriteAttributeString("name", productVariant.Name);
                    writer.WriteAttributeString("sku", productVariant.Sku);
                    writer.WriteAttributeString("price", productVariant.Price.ToString(CultureInfo.InvariantCulture));
                    writer.WriteAttributeString("manufacturer", productVariant.Manufacturer);
                    writer.WriteAttributeString("modelNumber", productVariant.ManufacturerModelNumber);
                    writer.WriteAttributeString("costOfGoods", productVariant.CostOfGoods.ToString());
                    writer.WriteAttributeString("salePrice", productVariant.SalePrice.ToString());
                    writer.WriteAttributeString("onSale", productVariant.OnSale.ToString());
                    writer.WriteAttributeString("weight", productVariant.Weight.ToString());
                    writer.WriteAttributeString("length", productVariant.Length.ToString());
                    writer.WriteAttributeString("width", productVariant.Width.ToString());
                    writer.WriteAttributeString("height", productVariant.Height.ToString());
                    writer.WriteAttributeString("barcode", productVariant.Barcode);
                    writer.WriteAttributeString("available", productVariant.Available.ToString());
                    writer.WriteAttributeString("trackInventory", productVariant.TrackInventory.ToString());
                    writer.WriteAttributeString("outOfStockPurchase", productVariant.OutOfStockPurchase.ToString());
                    writer.WriteAttributeString("taxable", productVariant.Taxable.ToString());
                    writer.WriteAttributeString("shippable", productVariant.Shippable.ToString());
                    writer.WriteAttributeString("download", productVariant.Download.ToString());
                    writer.WriteAttributeString("downloadMediaId", productVariant.DownloadMediaId.ToString());
                    writer.WriteAttributeString("totalInventoryCount", productVariant.TotalInventoryCount.ToString());
                    writer.WriteAttributeString("attributes", GetAttributesJson(productVariant));
                    writer.WriteAttributeString("catalogInventories", GetCatalogInventoriesJson(productVariant));

                    writer.WriteAttributeString("productOptions", GetProductOptionsJson(productOptionCollection));

                    writer.WriteAttributeString("createDate", productVariant.CreateDate.ToString("s"));
                    writer.WriteAttributeString("updateDate", productVariant.UpdateDate.ToString("s"));
                    writer.WriteAttributeString("allDocs", "1");

                    writer.WriteEndElement(); // product variant
                    writer.WriteEndDocument();

                    xml = sw.ToString();
                }
            }

            return(XDocument.Parse(xml));
        }
Beispiel #8
0
        /// <summary>
        /// Serializes a product variant for Examine indexing.
        /// </summary>
        /// <param name="productVariant">
        /// The product variant.
        /// </param>
        /// <param name="productOptionCollection">
        /// The product option collection.
        /// </param>
        /// <param name="collections">
        /// Static collections keys product belongs
        /// </param>
        /// <returns>
        /// The <see cref="XDocument"/>.
        /// </returns>
        internal static XDocument SerializeToXml(this IProductVariant productVariant, ProductOptionCollection productOptionCollection = null, IEnumerable <Guid> collections = null)
        {
            string xml;

            using (var sw = new StringWriter())
            {
                using (var writer = new XmlTextWriter(sw))
                {
                    writer.WriteStartDocument();
                    writer.WriteStartElement("productVariant");
                    writer.WriteAttributeString("id", ((ProductVariant)productVariant).ExamineId.ToString(CultureInfo.InvariantCulture));
                    writer.WriteAttributeString("productKey", productVariant.ProductKey.ToString());
                    writer.WriteAttributeString("productVariantKey", productVariant.Key.ToString());
                    writer.WriteAttributeString("master", ((ProductVariant)productVariant).Master.ToString());
                    writer.WriteAttributeString("name", productVariant.Name);
                    writer.WriteAttributeString("sku", productVariant.Sku);
                    writer.WriteAttributeString("price", productVariant.Price.ToString(CultureInfo.InvariantCulture));
                    writer.WriteAttributeString("manufacturer", productVariant.Manufacturer);
                    writer.WriteAttributeString("modelNumber", productVariant.ManufacturerModelNumber);
                    writer.WriteAttributeString("costOfGoods", productVariant.CostOfGoods == null ? 0.ToString(CultureInfo.InvariantCulture) : ((decimal)productVariant.CostOfGoods).ToString(CultureInfo.InvariantCulture));
                    writer.WriteAttributeString("salePrice", productVariant.SalePrice == null ? 0.ToString(CultureInfo.InvariantCulture) : ((decimal)productVariant.SalePrice).ToString(CultureInfo.InvariantCulture));
                    writer.WriteAttributeString("onSale", productVariant.OnSale.ToString());
                    writer.WriteAttributeString("weight", productVariant.Weight == null ? 0.ToString(CultureInfo.InvariantCulture) : ((decimal)productVariant.Weight).ToString(CultureInfo.InvariantCulture));
                    writer.WriteAttributeString("length", productVariant.Length == null ? 0.ToString(CultureInfo.InvariantCulture) : ((decimal)productVariant.Length).ToString(CultureInfo.InvariantCulture));
                    writer.WriteAttributeString("width", productVariant.Width == null ? 0.ToString(CultureInfo.InvariantCulture) : ((decimal)productVariant.Width).ToString(CultureInfo.InvariantCulture));
                    writer.WriteAttributeString("height", productVariant.Height == null ? 0.ToString(CultureInfo.InvariantCulture) : ((decimal)productVariant.Height).ToString(CultureInfo.InvariantCulture));
                    writer.WriteAttributeString("barcode", productVariant.Barcode);
                    writer.WriteAttributeString("available", productVariant.Available.ToString());
                    writer.WriteAttributeString("trackInventory", productVariant.TrackInventory.ToString());
                    writer.WriteAttributeString("outOfStockPurchase", productVariant.OutOfStockPurchase.ToString());
                    writer.WriteAttributeString("taxable", productVariant.Taxable.ToString());
                    writer.WriteAttributeString("shippable", productVariant.Shippable.ToString());
                    writer.WriteAttributeString("download", productVariant.Download.ToString());
                    writer.WriteAttributeString("downloadMediaId", productVariant.DownloadMediaId.ToString());
                    writer.WriteAttributeString("totalInventoryCount", productVariant.TotalInventoryCount.ToString(CultureInfo.InvariantCulture));
                    writer.WriteAttributeString("attributes", GetAttributesJson(productVariant));
                    writer.WriteAttributeString("catalogInventories", GetCatalogInventoriesJson(productVariant));
                    writer.WriteAttributeString("productOptions", GetProductOptionsJson(productOptionCollection));
                    writer.WriteAttributeString("slugs", string.Join(" ", productVariant.DetachedContents.Select(x => x.Slug)));
                    writer.WriteAttributeString("detachedContents", GetDetachedContentsJson(((ProductVariant)productVariant).DetachedContents));
                    writer.WriteAttributeString("versionKey", productVariant.VersionKey.ToString());

                    // 1.11.0 - static collections
                    if (collections != null)
                    {
                        var collectionKeys = collections as Guid[] ?? collections.ToArray();
                        if (collectionKeys.Any())
                        {
                            writer.WriteAttributeString("staticCollectionKeys", string.Join(" ", collectionKeys));
                        }
                    }

                    writer.WriteAttributeString("createDate", productVariant.CreateDate.ToString("s"));
                    writer.WriteAttributeString("updateDate", productVariant.UpdateDate.ToString("s"));
                    writer.WriteAttributeString("allDocs", "1");

                    writer.WriteEndElement(); // product variant
                    writer.WriteEndDocument();

                    xml = sw.ToString();
                }
            }

            return(XDocument.Parse(xml));
        }
Beispiel #9
0
        internal static XDocument SerializeToXml(this IProductVariant productVariant, ProductOptionCollection productOptionCollection = null)
        {
            string xml;
            using (var sw = new StringWriter())
            {
                using (var writer = new XmlTextWriter(sw))
                {
                    writer.WriteStartDocument();
                    writer.WriteStartElement("productVariant");
                   // TODO construct the id
                    writer.WriteAttributeString("id", ((ProductVariant)productVariant).ExamineId.ToString(CultureInfo.InvariantCulture));
                    writer.WriteAttributeString("productKey", productVariant.ProductKey.ToString());
                    writer.WriteAttributeString("productVariantKey", productVariant.Key.ToString());
                    writer.WriteAttributeString("master", ((ProductVariant)productVariant).Master.ToString());
                    writer.WriteAttributeString("name", productVariant.Name);
                    writer.WriteAttributeString("sku", productVariant.Sku);
                    writer.WriteAttributeString("price", productVariant.Price.ToString(CultureInfo.InvariantCulture));
                    writer.WriteAttributeString("manufacturer", productVariant.Manufacturer);
                    writer.WriteAttributeString("modelNumber", productVariant.ManufacturerModelNumber);
                    writer.WriteAttributeString("costOfGoods", productVariant.CostOfGoods.ToString());
                    writer.WriteAttributeString("salePrice", productVariant.SalePrice.ToString());
                    writer.WriteAttributeString("onSale", productVariant.OnSale.ToString());
                    writer.WriteAttributeString("weight", productVariant.Weight.ToString());
                    writer.WriteAttributeString("length", productVariant.Length.ToString());
                    writer.WriteAttributeString("width", productVariant.Width.ToString());
                    writer.WriteAttributeString("height", productVariant.Height.ToString());
                    writer.WriteAttributeString("barcode", productVariant.Barcode);
                    writer.WriteAttributeString("available", productVariant.Available.ToString());
                    writer.WriteAttributeString("trackInventory", productVariant.TrackInventory.ToString());
                    writer.WriteAttributeString("outOfStockPurchase", productVariant.OutOfStockPurchase.ToString());
                    writer.WriteAttributeString("taxable", productVariant.Taxable.ToString());
                    writer.WriteAttributeString("shippable", productVariant.Shippable.ToString());
                    writer.WriteAttributeString("download", productVariant.Download.ToString());
                    writer.WriteAttributeString("downloadMediaId", productVariant.DownloadMediaId.ToString());
                    writer.WriteAttributeString("totalInventoryCount", productVariant.TotalInventoryCount.ToString());
                    writer.WriteAttributeString("attributes", GetAttributesJson(productVariant));
                    writer.WriteAttributeString("catalogInventories", GetCatalogInventoriesJson(productVariant));
                    writer.WriteAttributeString("productOptions", GetProductOptionsJson(productOptionCollection));
                    writer.WriteAttributeString("versionKey", productVariant.VersionKey.ToString());
                    writer.WriteAttributeString("createDate", productVariant.CreateDate.ToString("s"));
                    writer.WriteAttributeString("updateDate", productVariant.UpdateDate.ToString("s"));
                    writer.WriteAttributeString("allDocs", "1");

                    writer.WriteEndElement(); // product variant
                    writer.WriteEndDocument();

                    xml = sw.ToString();
                }
            }

            return XDocument.Parse(xml);
        }
        /// <summary>
        /// Serializes a product variant for Examine indexing.
        /// </summary>
        /// <param name="productVariant">
        /// The product variant.
        /// </param>
        /// <param name="productOptionCollection">
        /// The product option collection.
        /// </param>
        /// <param name="collections">
        /// Static collections keys product belongs 
        /// </param>
        /// <returns>
        /// The <see cref="XDocument"/>.
        /// </returns>
        internal static XDocument SerializeToXml(this IProductVariant productVariant, ProductOptionCollection productOptionCollection = null, IEnumerable<Guid> collections = null)
        {
            string xml;
            using (var sw = new StringWriter())
            {
                using (var writer = new XmlTextWriter(sw))
                {
                    writer.WriteStartDocument();
                    writer.WriteStartElement("productVariant");
                    writer.WriteAttributeString("id", ((ProductVariant)productVariant).ExamineId.ToString(CultureInfo.InvariantCulture));
                    writer.WriteAttributeString("productKey", productVariant.ProductKey.ToString());
                    writer.WriteAttributeString("productVariantKey", productVariant.Key.ToString());
                    writer.WriteAttributeString("master", ((ProductVariant)productVariant).Master.ToString());
                    writer.WriteAttributeString("name", productVariant.Name);
                    writer.WriteAttributeString("sku", productVariant.Sku);
                    writer.WriteAttributeString("price", productVariant.Price.ToString(CultureInfo.InvariantCulture));
                    writer.WriteAttributeString("manufacturer", productVariant.Manufacturer);
                    writer.WriteAttributeString("modelNumber", productVariant.ManufacturerModelNumber);
                    writer.WriteAttributeString("costOfGoods", productVariant.CostOfGoods == null ? 0.ToString(CultureInfo.InvariantCulture) : ((decimal)productVariant.CostOfGoods).ToString(CultureInfo.InvariantCulture));
                    writer.WriteAttributeString("salePrice", productVariant.SalePrice==null ? 0.ToString(CultureInfo.InvariantCulture) : ((decimal)productVariant.SalePrice).ToString(CultureInfo.InvariantCulture));
                    writer.WriteAttributeString("onSale", productVariant.OnSale.ToString());
                    writer.WriteAttributeString("weight", productVariant.Weight == null ? 0.ToString(CultureInfo.InvariantCulture) : ((decimal)productVariant.Weight).ToString(CultureInfo.InvariantCulture));
                    writer.WriteAttributeString("length", productVariant.Length == null ? 0.ToString(CultureInfo.InvariantCulture) : ((decimal)productVariant.Length).ToString(CultureInfo.InvariantCulture));
                    writer.WriteAttributeString("width", productVariant.Width == null ? 0.ToString(CultureInfo.InvariantCulture) : ((decimal)productVariant.Width).ToString(CultureInfo.InvariantCulture));
                    writer.WriteAttributeString("height", productVariant.Height == null ? 0.ToString(CultureInfo.InvariantCulture) : ((decimal)productVariant.Height).ToString(CultureInfo.InvariantCulture));
                    writer.WriteAttributeString("barcode", productVariant.Barcode);
                    writer.WriteAttributeString("available", productVariant.Available.ToString());
                    writer.WriteAttributeString("trackInventory", productVariant.TrackInventory.ToString());
                    writer.WriteAttributeString("outOfStockPurchase", productVariant.OutOfStockPurchase.ToString());
                    writer.WriteAttributeString("taxable", productVariant.Taxable.ToString());
                    writer.WriteAttributeString("shippable", productVariant.Shippable.ToString());
                    writer.WriteAttributeString("download", productVariant.Download.ToString());
                    writer.WriteAttributeString("downloadMediaId", productVariant.DownloadMediaId.ToString());
                    writer.WriteAttributeString("totalInventoryCount", productVariant.TotalInventoryCount.ToString(CultureInfo.InvariantCulture));
                    writer.WriteAttributeString("attributes", GetAttributesJson(productVariant));
                    writer.WriteAttributeString("catalogInventories", GetCatalogInventoriesJson(productVariant));
                    writer.WriteAttributeString("productOptions", GetProductOptionsJson(productOptionCollection));
                    writer.WriteAttributeString("slugs", string.Join(" ", productVariant.DetachedContents.Select(x => x.Slug)));
                    writer.WriteAttributeString("detachedContents", GetDetachedContentsJson(((ProductVariant)productVariant).DetachedContents));
                    writer.WriteAttributeString("versionKey", productVariant.VersionKey.ToString());

                    // 1.11.0 - static collections
                    if (collections != null)
                    {
                        var collectionKeys = collections as Guid[] ?? collections.ToArray();
                        if (collectionKeys.Any())
                        {
                            writer.WriteAttributeString("staticCollectionKeys", string.Join(" ", collectionKeys));
                        }
                    }

                    writer.WriteAttributeString("createDate", productVariant.CreateDate.ToString("s"));
                    writer.WriteAttributeString("updateDate", productVariant.UpdateDate.ToString("s"));
                    writer.WriteAttributeString("allDocs", "1");

                    writer.WriteEndElement(); // product variant
                    writer.WriteEndDocument();

                    xml = sw.ToString();
                }
            }

            return XDocument.Parse(xml);
        }