private void PopulateControls() { DateTime?startDate = null; if (txtDays.Text.Length > 0) { int days = -1; int.TryParse(txtDays.Text, out days); if (days > 0) { DateTime localTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0).AddDays(-days); if (timeZone != null) { startDate = localTime.ToUtc(timeZone); } else { startDate = localTime.AddHours(-timeOffset); } } } List <OrderItem> lstOrderItems = OrderItem.GetPageBySearch(siteSettings.SiteId, -1, -1, -1, -1, startDate, null, null, null, siteUser.UserGuid, null, pageNumber, pageSize); if (lstOrderItems.Count > 0) { string productGuids = string.Empty; string attribute = string.Empty; foreach (OrderItem orderItem in lstOrderItems) { productGuids += orderItem.ProductGuid.ToString() + ";"; string tmp = orderItem.AttributesXml; if (tmp.Length > 0) { tmp += ";"; } //if (orderItem.AttributeDescription.Length > 0) // tmp += orderItem.AttributeDescription + ";"; attribute += tmp; } if (attribute.Length > 0) { lstOptions = CustomFieldOption.GetByOptionIds(siteSettings.SiteId, attribute); } List <Product> lstProducts = Product.GetByGuids(siteSettings.SiteId, productGuids, -1, WorkingCulture.LanguageId); XmlDocument doc = new XmlDocument(); doc.LoadXml("<ProductList></ProductList>"); XmlElement root = doc.DocumentElement; lstOrderItems.ForEach(orderItem => { Product product = ProductHelper.GetProductFromList(lstProducts, orderItem.ProductId); if (product != null) { XmlElement productXml = doc.CreateElement("Product"); root.AppendChild(productXml); ProductHelper.BuildProductDataXml(doc, productXml, product, null); // Order detail XmlHelper.AddNode(doc, productXml, "OrderCode", orderItem.Order.OrderCode); XmlHelper.AddNode(doc, productXml, "OrderDate", FormatDate(orderItem.Order.CreatedUtc, "dd/MM/yyyy")); XmlHelper.AddNode(doc, productXml, "OrderStatus", ProductHelper.GetOrderStatus(orderItem.Order.OrderStatus)); XmlHelper.AddNode(doc, productXml, "OrderTotal", ProductHelper.FormatPrice(orderItem.Quantity * orderItem.Price - orderItem.DiscountAmount, true)); } }); XmlHelper.XMLTransform(xmlTransformer, SiteUtils.GetXsltBasePath("Product", "PurchaseHistory.xslt"), doc); } }
private void BuildProductMediaXml( XmlDocument doc, XmlElement root) { string imageFolderPath = ProductHelper.MediaFolderPath(CacheHelper.GetCurrentSiteSettings().SiteId, product.ProductId); string thumbnailImageFolderPath = imageFolderPath + "thumbs/"; string siteRoot = WebUtils.GetSiteRoot(); Regex youtubeVideoRegex = new Regex("youtu(?:\\.be|be\\.com)/(?:.*v(?:/|=)|(?:.*/)?)([a-zA-Z0-9-_]+)"); List <ContentMedia> listMedia = ContentMedia.GetByContentDesc(product.ProductGuid); List <int> mediaTypes = new List <int>(); List <CustomFieldOption> listOptions = new List <CustomFieldOption>(); foreach (ContentMedia media in listMedia) { if (media.MediaType > 0 && !mediaTypes.Contains(media.MediaType)) { mediaTypes.Add(media.MediaType); } } if (mediaTypes.Count > 0) { listOptions = CustomFieldOption.GetByOptionIds(product.SiteId, string.Join(";", mediaTypes.ToArray())); } if (listOptions.Count > 0) { foreach (CustomFieldOption option in listOptions) { XmlElement element = doc.CreateElement("ProductColors"); root.AppendChild(element); XmlHelper.AddNode(doc, element, "Title", option.Name); XmlHelper.AddNode(doc, element, "Color", option.OptionColor); XmlHelper.AddNode(doc, element, "ColorId", option.CustomFieldOptionId.ToString()); foreach (ContentMedia media in listMedia) { if ( (option.CustomFieldOptionId == media.MediaType) && (media.LanguageId == -1 || media.LanguageId == languageId) && (media.MediaType != (int)ProductMediaType.Video) ) { BuildProductImagesXml(doc, element, media, imageFolderPath, thumbnailImageFolderPath); } } } } foreach (ContentMedia media in listMedia) { if (media.LanguageId == -1 || media.LanguageId == languageId) { if (media.MediaType != (int)ProductMediaType.Video) { BuildProductImagesXml(doc, root, media, imageFolderPath, thumbnailImageFolderPath); if (media.MediaType != (int)ProductMediaType.Image) { string relativePath = siteRoot + ProductHelper.GetMediaFilePath(imageFolderPath, media.MediaFile); basePage.AdditionalMetaMarkup += "\n<meta property=\"og:image\" content=\"" + relativePath + "\" />"; basePage.AdditionalMetaMarkup += "\n<meta itemprop=\"image\" content=\"" + relativePath + "\" />"; } } else { XmlElement element = doc.CreateElement("ProductVideos"); root.AppendChild(element); XmlHelper.AddNode(doc, element, "Title", media.Title); XmlHelper.AddNode(doc, element, "DisplayOrder", media.DisplayOrder.ToString()); XmlHelper.AddNode(doc, element, "Type", media.MediaType.ToString()); XmlHelper.AddNode(doc, element, "VideoUrl", ProductHelper.GetMediaFilePath(imageFolderPath, media.MediaFile)); string thumbnailPath = ProductHelper.GetMediaFilePath(thumbnailImageFolderPath, media.ThumbnailFile); if (media.ThumbnailFile.Length == 0 && media.MediaFile.ContainsCaseInsensitive("youtu")) { Match youtubeMatch = youtubeVideoRegex.Match(media.MediaFile); string videoId = string.Empty; if (youtubeMatch.Success) { videoId = youtubeMatch.Groups[1].Value; } thumbnailPath = "http://img.youtube.com/vi/" + videoId + "/0.jpg"; } XmlHelper.AddNode(doc, element, "ThumbnailUrl", thumbnailPath); } if (displaySettings.ShowVideo) { XmlElement element = doc.CreateElement("ProductMedia"); root.AppendChild(element); XmlHelper.AddNode(doc, element, "Title", media.Title); XmlHelper.AddNode(doc, element, "DisplayOrder", media.DisplayOrder.ToString()); XmlHelper.AddNode(doc, element, "Type", media.MediaType.ToString()); XmlHelper.AddNode(doc, element, "MediaUrl", ProductHelper.GetMediaFilePath(imageFolderPath, media.MediaFile)); XmlHelper.AddNode(doc, element, "ThumbnailUrl", ProductHelper.GetMediaFilePath(thumbnailImageFolderPath, media.ThumbnailFile)); } } } }