protected override Dictionary <Product, IEnumerable <decimal> > GetValues(List <Product> objs) { PriceList list = null; var priceLists = _session.QueryOver <ProductVariant>() .SelectList(builder => builder .Select(variant => variant.BasePrice).WithAlias(() => list.BasePrice) .Select(variant => variant.TaxRate.Id).WithAlias(() => list.TaxRateId) .Select(variant => variant.Product.Id).WithAlias(() => list.ProductId) ) .TransformUsing(Transformers.AliasToBean <PriceList>()) .Cacheable() .List <PriceList>(); var taxRates = _session.QueryOver <TaxRate>().Cacheable().List(); foreach (var priceList in priceLists) { priceList.SetTaxRate(taxRates); priceList.Price = _productPricingMethod.GetPrice(priceList.BasePrice, priceList.TaxRatePercentage, 0m, 0m); } var groupedPrices = priceLists.GroupBy(skuList => skuList.ProductId) .ToDictionary(lists => lists.Key, lists => lists.Select(skuList => skuList.Price).OrderBy(x => x).Take(1)); return(objs.ToDictionary(product => product, product => groupedPrices.ContainsKey(product.Id) ? groupedPrices[product.Id] : Enumerable.Empty <decimal>())); }
/// <summary> /// Export Google BaseProduct /// </summary> /// <param name="xml"></param> /// <param name="productVariant"></param> /// <param name="ns"></param> /// <param name="googleBaseProduct"></param> /// <param name="options"></param> /// <param name="categories"></param> /// <param name="product"></param> /// <param name="brand"></param> /// <param name="images"></param> private void ExportGoogleBaseProduct(ref XmlTextWriter xml, ProductVariant productVariant, string ns, GoogleBaseProduct googleBaseProduct, List <ProductOptionValue> options, List <Category> categories, Product product, Brand brand, List <MediaFile> images) { xml.WriteStartElement("item"); var optionValues = options.GroupBy(y => y.ProductOption.Name).ToDictionary(y => y.Key, y => y.First().Value, StringComparer.OrdinalIgnoreCase); //TITLE string title = String.Empty; var displayName = GetFullName(productVariant, options); if (!String.IsNullOrWhiteSpace(displayName)) { title = displayName; } if (title.Length > 70) { title = title.Substring(0, 70); } xml.WriteElementString("title", title); //LINK if (product != null && !String.IsNullOrWhiteSpace(displayName)) { xml.WriteElementString("link", GeneralHelper.GetValidProductVariantUrl(productVariant)); } //DESCRIPTION xml.WriteStartElement("description"); string description = String.Empty; if (product != null) { if (!String.IsNullOrWhiteSpace(displayName)) { description = product.BodyContent.StripHtml().TruncateString(480); } if (String.IsNullOrEmpty(description)) { description = product.ProductAbstract.StripHtml().TruncateString(480); } if (String.IsNullOrEmpty(description)) { description = displayName.StripHtml().TruncateString(480); } } description = XmlCharacterWhitelist(description); byte[] descriptionBytes = Encoding.Default.GetBytes(description.StripHtml()); description = Encoding.UTF8.GetString(descriptionBytes); xml.WriteCData(description); xml.WriteEndElement(); //CONDITION xml.WriteElementString("g", "condition", ns, googleBaseProduct != null ? googleBaseProduct.Condition.ToString() : ProductCondition.New.ToString()); //PRICE xml.WriteElementString("g", "price", ns, _productPricingMethod.GetPrice(productVariant).ToCurrencyFormat()); //AVAILABILITY string availability = "In Stock"; if (productVariant.TrackingPolicy == TrackingPolicy.Track && _getStockRemainingQuantity.Get(productVariant) <= 0) { availability = "Out of Stock"; } xml.WriteElementString("g", "availability", ns, availability); //GOOGLE PRODUCT CATEGORY if (googleBaseProduct != null) { xml.WriteElementString("g", "google_product_category", ns, googleBaseProduct.Category); } //PRODUCT CATEGORY if (product != null && categories.Any() && !String.IsNullOrWhiteSpace(categories.First().Name)) { xml.WriteElementString("g", "product_type", ns, categories.First().Name); } else if (googleBaseProduct != null) { xml.WriteElementString("g", "product_type", ns, googleBaseProduct.Category); } //IMAGES if (product != null && images.Any() && !String.IsNullOrWhiteSpace(images.First().FileUrl)) { xml.WriteElementString("g", "image_link", ns, GeneralHelper.GetValidImageUrl(images.First().FileUrl)); } if (product != null && images.Count() > 1 && !String.IsNullOrWhiteSpace(images.ToList()[1].FileUrl)) { xml.WriteElementString("g", "additional_image_link", ns, GeneralHelper.GetValidImageUrl(images.ToList()[1].FileUrl)); } //BRAND if (brand != null && !String.IsNullOrWhiteSpace(brand.Name)) { xml.WriteElementString("g", "brand", ns, brand.Name); } //ID xml.WriteElementString("g", "id", ns, productVariant.Id.ToString(new CultureInfo("en-GB", false).NumberFormat)); //GTIN if (!String.IsNullOrWhiteSpace(productVariant.Barcode)) { xml.WriteElementString("g", "gtin", ns, productVariant.Barcode); } //MPN if (!String.IsNullOrWhiteSpace(productVariant.ManufacturerPartNumber)) { xml.WriteElementString("g", "mpn", ns, productVariant.ManufacturerPartNumber); } if (googleBaseProduct != null) { //GENDER xml.WriteElementString("g", "gender", ns, googleBaseProduct.Gender.ToString()); //AGE GROUP xml.WriteElementString("g", "age_group", ns, googleBaseProduct.AgeGroup.ToString()); } //ITEM GROUP ID if (product != null) { xml.WriteElementString("g", "item_group_id", ns, product.Id.ToString(new CultureInfo("en-GB", false).NumberFormat)); } //COLOR if (optionValues.ContainsKey("color")) { xml.WriteElementString("g", "color", ns, optionValues["color"]); } else if (optionValues.ContainsKey("colour")) { xml.WriteElementString("g", "color", ns, optionValues["colour"]); } //SIZE if (optionValues.ContainsKey("size")) { xml.WriteElementString("g", "color", ns, optionValues["size"]); } //PATTERN if (optionValues.ContainsKey("pattern")) { xml.WriteElementString("g", "color", ns, optionValues["pattern"]); } //MATERIAL if (optionValues.ContainsKey("material")) { xml.WriteElementString("g", "color", ns, optionValues["material"]); } //SHIPPING SetGoogleBaseShipping(ref xml, productVariant, ns); //WEIGHT xml.WriteElementString("g", "shipping_weight", ns, string.Format(CultureInfo.InvariantCulture, "{0} {1}", productVariant.Weight.ToString(new CultureInfo("en-GB", false).NumberFormat), "kg")); //ADWORDS if (googleBaseProduct != null) { if (!String.IsNullOrWhiteSpace(googleBaseProduct.Grouping)) { xml.WriteElementString("g", "adwords_grouping", ns, googleBaseProduct.Grouping); } if (!String.IsNullOrWhiteSpace(googleBaseProduct.Labels)) { xml.WriteElementString("g", "adwords_labels", ns, googleBaseProduct.Labels); } if (!String.IsNullOrWhiteSpace(googleBaseProduct.Redirect)) { xml.WriteElementString("g", "adwords_redirect", ns, googleBaseProduct.Redirect); } } xml.WriteEndElement(); }