public ResultModel Generate(YmlExportSettings settings) { _exportShopService.UpdateYmlExportSettings(settings); ExportTask task = _exportShopService.StartYmlExportTask(settings); return(new ResultModel(true, task)); }
public void UpdateYmlExportSettings(YmlExportSettings settings) { _settingsService.Set("SiteName", settings.SiteName); _settingsService.Set("SiteDescription", settings.SiteDescription); _settingsService.Set("SiteUrl", settings.SiteUrl); _settingsService.Set("ClickRate", settings.ClickRate); _settingsService.Set("Pickup", settings.Pickup); _settingsService.Set("DeliveryCost", settings.DeliveryCost); }
public ExportTask StartYmlExportTask(YmlExportSettings settings) { var task = new ExportTask() { StartDate = DateTime.UtcNow.ApplySiteTimezone(), Status = ExportStatus.Processing }; var dataTask = Mapper.Map <Data.Models.ShopDbExportTask>(task); int id = _exportTaskGateway.Insert(dataTask); task.TaskId = dataTask.TaskId = id; string filePath = HttpContext.Current.Server.MapPath("~/App_Data/shop.yml"); Task t = new Task(() => GenerateYmlFile(filePath, id)); t.Start(); return(task); }
private void AddElementToYml(XmlDocument resultDocument, XmlNode offersElement, decimal bid, string siteUrl, YmlExportSettings settings, GoodsItem goodsItem, GoodsPack goodsPack = null) { XmlNode offerElement = resultDocument.CreateElement("offer"); offersElement.AppendChild(offerElement); XmlAttribute currentAttribute = resultDocument.CreateAttribute("id"); currentAttribute.Value = goodsPack == null?goodsItem.HeartId.ToString() : $"{goodsItem.HeartId}p{goodsPack.PackInfo.Size}"; offerElement.Attributes.Append(currentAttribute); currentAttribute = resultDocument.CreateAttribute("available"); currentAttribute.Value = "true"; offerElement.Attributes.Append(currentAttribute); if (bid != 0) { currentAttribute = resultDocument.CreateAttribute("bid"); currentAttribute.Value = bid.ToString(CultureInfo.InvariantCulture); offerElement.Attributes.Append(currentAttribute); } var url = _heartService.GetCanonicalUrl(goodsItem.HeartId); if (goodsPack != null) { url = $"{url}#p{goodsPack.PackInfo.Size}"; } XmlNode currentElement = resultDocument.CreateElement("url"); offerElement.AppendChild(currentElement); currentElement.InnerText = $"{siteUrl}/{url}"; decimal price = goodsPack == null ? goodsItem.DiscountedPrice : goodsItem.DiscountedPriceForPack(goodsPack.PackId); currentElement = resultDocument.CreateElement("price"); offerElement.AppendChild(currentElement); currentElement.InnerText = price.ToString(CultureInfo.InvariantCulture); decimal oldPrice = goodsPack == null ? goodsItem.Price : goodsItem.PriceForPack(goodsPack.PackId); if (oldPrice > price) { currentElement = resultDocument.CreateElement("oldprice"); offerElement.AppendChild(currentElement); currentElement.InnerText = oldPrice.ToString(CultureInfo.InvariantCulture); } currentElement = resultDocument.CreateElement("currencyId"); offerElement.AppendChild(currentElement); currentElement.InnerText = "RUR"; currentElement = resultDocument.CreateElement("categoryId"); offerElement.AppendChild(currentElement); currentElement.InnerText = (goodsItem.ParentHeartId ?? goodsItem.Categories.First().ID).ToString(); if (!string.IsNullOrEmpty(goodsItem.MainImageId)) { currentElement = resultDocument.CreateElement("picture"); offerElement.AppendChild(currentElement); currentElement.InnerText = $"{siteUrl}/Gallery/Image/{goodsItem.MainImageId}"; } currentElement = resultDocument.CreateElement("pickup"); offerElement.AppendChild(currentElement); currentElement.InnerText = settings.Pickup.ToString().ToLower(); currentElement = resultDocument.CreateElement("delivery"); offerElement.AppendChild(currentElement); currentElement.InnerText = "true"; currentElement = resultDocument.CreateElement("name"); offerElement.AppendChild(currentElement); currentElement.InnerText = goodsPack == null ? goodsItem.Name : $"{goodsItem.Name} {goodsPack.PackInfo.Name}"; if (goodsItem.ManufacturerId.HasValue) { currentElement = resultDocument.CreateElement("vendor"); offerElement.AppendChild(currentElement); currentElement.InnerText = goodsItem.Manufacturer.Name; } currentElement = resultDocument.CreateElement("description"); offerElement.AppendChild(currentElement); currentElement.InnerText = goodsItem.Description; // Код ниже неверен if (goodsItem.CompatibleGoods.Any()) { List <int> ids = new List <int>(); foreach (var set in goodsItem.CompatibleGoods) { foreach (var pair in set.CompatibleGoods) { ids.Add(pair.ID); } } ids = ids.Distinct().ToList(); string recs = String.Join(",", ids.Distinct()); currentElement = resultDocument.CreateElement("rec"); offerElement.AppendChild(currentElement); currentElement.InnerText = recs; } foreach (var specVal in goodsItem.GoodsSpecs) { currentElement = resultDocument.CreateElement("param"); offerElement.AppendChild(currentElement); currentElement.InnerText = specVal.Value; currentAttribute = resultDocument.CreateAttribute("name"); currentAttribute.Value = specVal.Spec.Name; currentElement.Attributes.Append(currentAttribute); if (!String.IsNullOrEmpty(specVal.Spec.Postfix)) { currentAttribute = resultDocument.CreateAttribute("unit"); currentAttribute.Value = specVal.Spec.Postfix; currentElement.Attributes.Append(currentAttribute); } } if (goodsPack != null) { currentElement = resultDocument.CreateElement("param"); offerElement.AppendChild(currentElement); currentElement.InnerText = goodsPack.PackInfo.Size.ToString(CultureInfo.InvariantCulture); currentAttribute = resultDocument.CreateAttribute("name"); currentAttribute.Value = "Вес"; currentElement.Attributes.Append(currentAttribute); currentAttribute = resultDocument.CreateAttribute("unit"); currentAttribute.Value = goodsPack.PackInfo.Dimension.Short; currentElement.Attributes.Append(currentAttribute); } }
private void WriteGoods(XmlDocument resultDocument, XmlNode offersElement, YmlExportSettings settings) { decimal bid = settings.ClickRate; string siteUrl = settings.SiteUrl; int total; FilterCollections filterCollections; var goods = _shopService.GetGoodsSet( new GoodsFilter() { SortBy = SortCriterion.CreationDateAsc, ClientMode = true, }, 1, int.MaxValue, out total, out filterCollections, true); foreach (var goodsItem in goods) { try { if (!goodsItem.Categories.Any()) { continue; } if (goodsItem.NotAvailable) { continue; } if (goodsItem.Packs.Any()) { foreach (var pack in goodsItem.Packs) { AddElementToYml(resultDocument, offersElement, bid, siteUrl, settings, goodsItem, pack); } } else { AddElementToYml(resultDocument, offersElement, bid, siteUrl, settings, goodsItem); } } catch (Exception e) { _logService.LogError(e, "Ошибка при экспорте товара ID:" + goodsItem.HeartId); } } #region Пример товара // <offer id="12341" type="vendor.model" available="true" bid="13"> // <url>http://best.seller.ru/product_page.asp?pid=12344</url> // <price>16800</price> // <currencyId>USD</currencyId> // <categoryId>6</categoryId> // <picture>http://best.seller.ru/img/device12345.jpg</picture> // <store>false</store> // <pickup>false</pickup> // <delivery>true</delivery> // <local_delivery_cost>300</local_delivery_cost> // <typePrefix>Принтер</typePrefix> // <vendor>НP</vendor> // <vendorCode>CH366C</vendorCode> // <model>Deskjet D2663</model> // <description>Серия принтеров для людей, которым нужен надежный, простой в использовании // цветной принтер для повседневной печати. Формат А4. Технология печати: 4-цветная термальная струйная. // Разрешение при печати: 4800х1200 т/д. // </description> // <sales_notes>Необходима предоплата.</sales_notes> // <manufacturer_warranty>true</manufacturer_warranty> // <seller_warranty>P3Y</seller_warranty> // <country_of_origin>Япония</country_of_origin> // <barcode>1234567890120</barcode> // <cpa>1</cpa> // <rec>123123,1214,243</rec> // <expiry>P5Y</expiry> // <weight>2.07</weight> // <dimensions>100/25.45/11.112</dimensions> // <param name="Максимальный формат">А4</param> // <param name="Технология печати">термическая струйная</param> // <param name="Тип печати">Цветная</param> // <param name="Количество страниц в месяц" unit="стр">1000</param> // <param name="Потребляемая мощность" unit="Вт">20</param> // <param name="Вес" unit="кг">2.73</param> //</offer> #endregion }