You can create a product feed to fetch product information with selected and additional set of field values. This section describes how.
Setup
Create an instance of a feed entity to represent the product feed using the API.
Feed.ApiKey is a string that should be sent with each feed request to fetch the feed.
Use the Litium.Products.Syndications.FeedService to create, read, update and delete your feeds.
Feed fields
Feed.FeedFields is the collection of FeedField that will be available through the product feed. Also, an existing product field can be mapped to a different output name.
Apart from fields from varient and baseProducts, calculated fields can also be added to the feed. The ids for these fields are found at Litium.Products.Syndications.FeedSystemFieldConstants
Example:
private static Feed CreateFeed(Guid channelSystemId, Guid countrySystemId, string apiKey)
{
return new Feed(channelSystemId, countrySystemId)
{
Id = "TestFeed",
Name = "TestFeed name",
ApiKey = apiKey, //required on each request to fetch the feed
Active = true, //activate the feed
OutputFormat = "json",
CronExpression = "0 0/1 * 1/1 * ? *", //at one interval and when when the feed will be re-calculated
FeedFields = new List<FeedField>() {
new() { FieldId = "someFieldId", OutputName = "outputFieldId" }, //field from the produtcs field template, with name someFieldId
new() { FieldId = FeedSystemFieldConstants.ProductPriceInclVAT, OutputName = "PriceInclVAT" }, //product price including VAT
new() { FieldId = FeedSystemFieldConstants.GTIN, OutputName = "GTIN" }, //feild mapping from CommonMetadata.GTIN
new() { FieldId = FeedSystemFieldConstants.MPN, OutputName = "MPN" },
new() { FieldId = FeedSystemFieldConstants.CategoryTree, OutputName = "CategoryTree" },
new() { FieldId = FeedSystemFieldConstants.TaxRate, OutputName = "TaxRate" },
new() { FieldId = FeedSystemFieldConstants.StockLevel, OutputName = "StockLevel" },
new() { FieldId = FeedSystemFieldConstants.Availability, OutputName = "Availability" },
new() { FieldId = FeedSystemFieldConstants.Bundle, OutputName = "Bundle" },
new() { FieldId = FeedSystemFieldConstants.ArticleNumber, OutputName = "ArticleNumber" },
new() { FieldId = FeedSystemFieldConstants.VariantOf, OutputName = "VariantOf" },
new() { FieldId = FeedSystemFieldConstants.ProductPriceInclVAT, OutputName = "ProductPriceInclVAT" },
new() { FieldId = FeedSystemFieldConstants.DiscountedPriceInclVAT, OutputName = "DiscountedPriceInclVAT" }
}
};
}
Generate
The feed is generated using a scheduled job. Set the Feed.CronExpression to define when and at what interval the feed should get generated.
Access
To access the feed, use the following URL:
https://<your domain>/feed.axd/<Feed.SystemId>?api-key=<Feed.ApiKey>
Product feed generated is a Json file with a array of feed items. Each feed item has following sample structure.
{
"CategoryTree": [
"Man",
"Bottoms"
],
"TaxRate": 25,
"StockLevel": 1000,
"Availability": true,
"Bundle": [],
"ProductLink": "https://litium-pr11898.svc.litiumlab.se/man/bottoms/m-elastic-shorts-black_l-638046326047328829",
"ArticleNumber": "melasticshorts-l-003-638046326047328829",
"VariantOf": "melasticshorts-638046326047328829",
"ProductPriceExcludingVat": 599,
"ProductPriceIncludingVat": 748.75,
"MediaPointerFileFeedField": "https://litium-pr11898.svc.litiumlab.se/storage/B56A12880BD619B586DEB4FF302BD7B66B9B1593E24EE59D673E88D7BC096816/ee51ec02e76848cfbd570742938f7b38/png/media/6702ec39f56d46c59ed68695280d8bc3/1-901.png",
"MediaPointerImageFeedField": "https://litium-pr11898.svc.litiumlab.se/storage/2621640AC17D1689257DBE7199132317BD35DA2611F18ABAF7AD46864484E861/95f983eafdf64244bc98bd9786091385/png/media/a9e6573739304f5a9b0de021f1c7adfa/6-901.png",
"Images": [
"https://litium-pr11898.svc.litiumlab.se/storage/2F80CB8CEBFCE92880608F0102399CE9881885190B91CD3086679A02F5C8F43A/7fdcc3b6c2e048a68390304a23f8582d/png/media/2e826a34f66449cdbe40a2b7beb81c4b/4-901.png",
"https://litium-pr11898.svc.litiumlab.se/storage/2621640AC17D1689257DBE7199132317BD35DA2611F18ABAF7AD46864484E861/95f983eafdf64244bc98bd9786091385/png/media/a9e6573739304f5a9b0de021f1c7adfa/6-901.png",
"https://litium-pr11898.svc.litiumlab.se/storage/6B6BBFA813C14A4DB814AB8A0D74743D3F000627189080B4B3214DBDD78C8981/45a916b0f5ea4f22a1f79fa8a0d2d6e5/png/media/5cec256e89674350ab363abb35f7845d/5-901.png",
"https://litium-pr11898.svc.litiumlab.se/storage/B56A12880BD619B586DEB4FF302BD7B66B9B1593E24EE59D673E88D7BC096816/ee51ec02e76848cfbd570742938f7b38/png/media/6702ec39f56d46c59ed68695280d8bc3/1-901.png",
"https://litium-pr11898.svc.litiumlab.se/storage/F70AF1BD4C0EC9E47FB505E23C5E74FE80957F8C6ED6B42173FF98497CAB5392/d378d8aef5614ad9b72484fe9f36ba31/png/media/04b95636d8d1417eb95bc4bbe8b97cdb/2-901.png"
],
"Images_small": [
"https://litium-pr11898.svc.litiumlab.se/storage/4EB8DF346F37F57637DFCACDF612D54D827EB66BED788F8F4FDF0011CE7B7705/7fdcc3b6c2e048a68390304a23f8582d/50-50-0-png.Png/media/2e826a34f66449cdbe40a2b7beb81c4b/4-901.png",
"https://litium-pr11898.svc.litiumlab.se/storage/47830E3BB448C8194DE8A9E72217D42BE90F73D7664D89D1DE6ACBD1EC478827/95f983eafdf64244bc98bd9786091385/50-50-0-png.Png/media/a9e6573739304f5a9b0de021f1c7adfa/6-901.png",
"https://litium-pr11898.svc.litiumlab.se/storage/F4A098FFE3681EA1082A71A23E589945A318C407A2B4E6CBD2363671E0C6E058/45a916b0f5ea4f22a1f79fa8a0d2d6e5/50-50-0-png.Png/media/5cec256e89674350ab363abb35f7845d/5-901.png",
"https://litium-pr11898.svc.litiumlab.se/storage/AB7D0EB6535F12E5BBBBD2B5CE00DA5277A860C6B69AC917838D9BD13B88AB2E/ee51ec02e76848cfbd570742938f7b38/50-50-0-png.Png/media/6702ec39f56d46c59ed68695280d8bc3/1-901.png",
"https://litium-pr11898.svc.litiumlab.se/storage/FBC51D4458F765E1BF209ECFE0CC172C1F574AA6614FFACD13A1151AAAA636B0/d378d8aef5614ad9b72484fe9f36ba31/50-50-0-png.Png/media/04b95636d8d1417eb95bc4bbe8b97cdb/2-901.png"
],
"MediaPointerFileFeedFieldML": "https://litium-pr11898.svc.litiumlab.se/storage/C7D5215E1BEADBA75D8729C5FCCF9D195C2A8B77C827CA8B757F1E7BADFC5FC8/52c3ed3a1fc7448db697e155c0d0e822/png/media/20404c0662a3479abcdcbc6b04ab45da/1-170.png",
"MediaPointerImageFeedFieldML": "https://litium-pr11898.svc.litiumlab.se/storage/AA4C1A4F20CEA4A6710891989D70BB16F9EF065C73FCD763CC3F23AD1FB7922F/5bb686cd5ce943b997de215e16575566/png/media/d62eca1974bb4b4ba518bbedc6547b73/6-170.png",
"Url": "m-elastic-shorts-black_l-638046326047328829",
"Brand": "Casall",
"Color": "Black"
}
Result transformation
The result for the syndication feed is customaziable by the project.
To implement your own feed result transformation you need to implement the Litium.Web.Products.Syndications.IFeedResult and define the output format identifier for the implementation inside the [Service(Name =
"..."
)]-attribute
, this output format identifier is the same that should be used when feed is configured.
Below an simple result transformation to output the information in tab-separated file, the example is only adding some of the fields that exists.
using System;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Litium.Products.Syndications;
using Litium.Runtime.DependencyInjection;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
namespace Litium.Accelerator.Mvc
{
[Service(Name = "Tab")]
public class SyndicateTabFeedResult : Litium.Web.Products.Syndications.IFeedResult
{
public Task<IActionResult> ExecuteAsync(Feed feed, Func<JArray> items, CancellationToken cancellationToken)
{
var sb = new StringBuilder()
.Append(nameof(FeedSystemFieldConstants.ArticleNumber))
.Append('\t')
.Append(nameof(FeedSystemFieldConstants.VariantOf))
.Append('\t')
.Append(nameof(FeedSystemFieldConstants.ProductPriceIncludingVat))
.AppendLine();
foreach (var item in items())
{
if (item is JObject jObject)
{
var field1 = jObject[nameof(FeedSystemFieldConstants.ArticleNumber)];
var field2 = jObject[nameof(FeedSystemFieldConstants.VariantOf)];
var field3 = jObject[nameof(FeedSystemFieldConstants.ProductPriceIncludingVat)];
sb
.Append(field1?.Value<string>())
.Append('\t')
.Append(field2?.Value<string>())
.Append('\t')
.Append(field3?.Value<decimal?>())
.AppendLine();
}
}
return Task.FromResult<IActionResult>(new ContentResult
{
Content = sb.ToString(),
ContentType = "text/tab",
});
}
}
}