public virtual void CreateOffersDocumentEnd() { if (OffersXmlTextWriter == null) { return; } OffersXmlTextWriter.WriteEndElement(); OffersXmlTextWriter.WriteEndDocument(); OffersXmlTextWriter.Flush(); OffersXmlTextWriter.Close(); }
protected override bool ProcessProduct(ProductItem productItem) { var result = true; var documentType = YandexDocumentType.Simple; var partnerType = PartnerType.None; if (Settings != null && Settings.State != null && Settings.State is YandexDocumentSettings) { var yandexSettings = Settings.State as YandexDocumentSettings; documentType = yandexSettings.DocumentType; partnerType = yandexSettings.PartnerType; } var virtualCategoryId = CanWriteCurrentProductAndGetVirtualCategoryId(productItem); if (virtualCategoryId != null) { OffersXmlTextWriter.WriteStartElement(OfferFieldName); OffersXmlTextWriter.WriteAttributeString(OFFER_FIELD_ID_ATTRIBUTE_NAME, productItem.ItemId); if (documentType == YandexDocumentType.VendorModel) { OffersXmlTextWriter.WriteAttributeString(OFFER_FIELD_TYPE_ATTRIBUTE_NAME, OFFER_FIELD_TYPE_ATTRIBUTE_CONTENT); } if (productItem.DetailProductUrl != null) { var absolutePath = new Uri(Settings.ShopUrl, productItem.DetailProductUrl).ToString(); if (absolutePath.Length <= 512) { OffersXmlTextWriter.WriteElementString(OFFER_FIELD_URL_FIELD_NAME, absolutePath); } } var pictures = new List <string>(); if (productItem.ProductImages != null && productItem.ProductImages.Any()) { foreach (var productImage in productItem.ProductImages) { if (productImage != null && productImage.OriginalImageAddress.Length <= 512) { pictures.Add(productImage.OriginalImageAddress); if (partnerType == PartnerType.None) { break; } } } } if (documentType == YandexDocumentType.Blizko && pictures.Any()) { OffersXmlTextWriter.WriteElementString(OFFER_FIELD_PICTURE_FIELD_NAME, pictures.First()); } //цена товара без скидки var oldPrice = productItem.Price.Price; //цена товара с учетом скидки var currentPrice = productItem.Price.Price - productItem.Discount.Amount; if (oldPrice != currentPrice) { OffersXmlTextWriter.WriteElementString(OFFER_FIELD_OLDPRICE_FIELD_NAME, oldPrice.ToString("F2", CultureInfo.InvariantCulture)); } var productPrice = currentPrice.ToString("F2", CultureInfo.InvariantCulture); OffersXmlTextWriter.WriteElementString(OFFER_FIELD_PRICE_FIELD_NAME, productPrice); OffersXmlTextWriter.WriteElementString(OFFER_FIELD_CURRENCY_ID_FIELD_NAME, "RUR"); OffersXmlTextWriter.WriteElementString(OFFER_FIELD_CATEGORY_ID_FIELD_NAME, virtualCategoryId.Value.ToString(CultureInfo.InvariantCulture)); if (documentType != YandexDocumentType.Blizko && pictures.Any()) { if (partnerType == PartnerType.None) { OffersXmlTextWriter.WriteElementString(OFFER_FIELD_PICTURE_FIELD_NAME, pictures.First()); } else { foreach (var picture in pictures) { OffersXmlTextWriter.WriteElementString(OFFER_FIELD_PICTURE_FIELD_NAME, picture); } } } if (documentType == YandexDocumentType.VendorModel) { //достаем тип товарногно предложения. Планшет, смартфон и т.п var typePrefix = GetTypePrefix(virtualCategoryId.Value); if (!string.IsNullOrWhiteSpace(typePrefix)) { OffersXmlTextWriter.WriteElementString(OFFER_FIELD_TYPE_PREFIX_FIELD_NAME, typePrefix); } } if (documentType == YandexDocumentType.Simple || documentType == YandexDocumentType.Blizko) { //добавляем название OffersXmlTextWriter.WriteElementString(OFFER_FIELD_NAME_FIELD_NAME, productItem.ProductName); } var vendorName = GetProductVendorString(productItem); //добавлем вендора OffersXmlTextWriter.WriteElementString(OFFER_FIELD_VENDOR_FIELD_NAME, vendorName); //добавляем модель if (documentType == YandexDocumentType.VendorModel) { string model = GetProductModel(productItem); OffersXmlTextWriter.WriteElementString(OFFER_FIELD_MODEL_FIELD_NAME, model); } //описание if (documentType != YandexDocumentType.VendorModel) { var description = GetDescription(productItem); if (!string.IsNullOrWhiteSpace(description)) { OffersXmlTextWriter.WriteElementString(OFFER_FIELD_DESCRIPTION_NAME, description); } } else { var properties = GetDescriptionProperties(productItem); foreach (var property in properties) { OffersXmlTextWriter.WriteStartElement(OFFER_FIELD_PARAM_FIELD_NAME); OffersXmlTextWriter.WriteAttributeString(OFFER_FIELD_NAME_FIELD_NAME, property.Name); OffersXmlTextWriter.WriteValue(property.PropertyValueTitle); OffersXmlTextWriter.WriteEndElement(); } } if (documentType != YandexDocumentType.Blizko) { OffersXmlTextWriter.WriteStartElement(OFFER_FIELD_PARAM_FIELD_NAME); OffersXmlTextWriter.WriteAttributeString("name", "Состояние"); OffersXmlTextWriter.WriteValue("новый"); OffersXmlTextWriter.WriteEndElement(); } OffersXmlTextWriter.WriteEndElement(); } else { result = false; } return(result); }