diff options
author | Serghei Cebotari <serghei@cebotari.ru> | 2024-01-29 14:34:51 +0300 |
---|---|---|
committer | Serghei Cebotari <serghei@cebotari.ru> | 2024-01-29 14:34:51 +0300 |
commit | 4aac347867917948cad1ccdea651a9b3702f90a3 (patch) | |
tree | b4595654b1ae4bc7eb2c59288895ef5d167db895 | |
parent | 4d1a5229e5f86924db96a0274a9e54370bf111ae (diff) |
Add yandex feed
-rw-r--r-- | Pages/Feed.xml.cshtml | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/Pages/Feed.xml.cshtml b/Pages/Feed.xml.cshtml new file mode 100644 index 0000000..c17981f --- /dev/null +++ b/Pages/Feed.xml.cshtml @@ -0,0 +1,42 @@ +@page "/feed.yml" +@using Microsoft.AspNetCore.Http +@using Microsoft.EntityFrameworkCore +@inject MyDarling.Models.DataContext context +@{ + var p = + new { Url = "https://mydarlingunderwear.ru/", LastUpdated = DateTime.Today }; + Response.ContentType = "text/xml"; + var products = context.Products + .Include(b => b.Figures) + .Where(b => b.Price != 0 && b.Figures.Count > 0); + await Response.WriteAsync("<?xml version='1.0' encoding='UTF-8' ?>"); + var updateDate = p.LastUpdated.ToString("yyyy-MM-dd"); +} + +<yml_catalog date="@updateDate"> + <shop> + <name>My Darling Underwear</name> + <company>Екатерина Мануйлова</company> + <url>@p.Url</url> + <currencies> + <currency id="RUB" rate="1"></currency> + </currencies> + <categories> + <category id="1">Нижнее бельё</category> + </categories> + <offers> + @foreach (var product in products) + { + var figureUrl = $"{@p.Url}Content/{@product.Id}/{@product.Figures[0].Id}.jpg"; + <offer id="@product.Id" available="true"> + <url>@p.Url#@product.Id-1</url> + <price>@product.Price</price> + <currencyId>RUR</currencyId> + <categoryId>1</categoryId> + <name>@product.Name</name> + <picture>@figureUrl</picture> + </offer> + } + </offers> + </shop> +</yml_catalog>
\ No newline at end of file |