Product Feed: Add group ID (#839)

* Add attribute mapping

* Improve release note

* Log the error

* Add pattern attribute

* Add group ID
This commit is contained in:
Krzysztof Wolski 2023-08-03 11:14:56 +02:00 committed by GitHub
parent aece07338e
commit fc5e6396d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 15 deletions

View file

@ -0,0 +1,7 @@
---
"saleor-app-products-feed": minor
---
Feed format has been changed to leverage Product Group ID field:
- Product ID: feed items use SKU if available, product variant ID is used otherwise
- Product Group ID: product ID is used for all the items

View file

@ -16,6 +16,7 @@ const productBase: GoogleFeedProductVariantFragment["product"] = {
seoDescription: "Seo description", seoDescription: "Seo description",
slug: "product-slug", slug: "product-slug",
thumbnail: { __typename: "Image", url: "" }, thumbnail: { __typename: "Image", url: "" },
attributes: [],
}; };
const priceBase: GoogleFeedProductVariantFragment["pricing"] = { const priceBase: GoogleFeedProductVariantFragment["pricing"] = {
@ -46,6 +47,7 @@ describe("generateGoogleXmlFeed", () => {
pricing: priceBase, pricing: priceBase,
name: "Product variant", name: "Product variant",
product: productBase, product: productBase,
attributes: [],
}, },
{ {
id: "id2", id: "id2",
@ -55,6 +57,7 @@ describe("generateGoogleXmlFeed", () => {
pricing: priceBase, pricing: priceBase,
name: "Product variant 2", name: "Product variant 2",
product: productBase, product: productBase,
attributes: [],
}, },
], ],
}); });
@ -68,6 +71,7 @@ describe("generateGoogleXmlFeed", () => {
<description>Description</description> <description>Description</description>
<item> <item>
<g:id>sku1</g:id> <g:id>sku1</g:id>
<g:item_group_id>product-id</g:item_group_id>
<title>Product - Product variant</title> <title>Product - Product variant</title>
<g:condition>new</g:condition> <g:condition>new</g:condition>
<g:availability>in_stock</g:availability> <g:availability>in_stock</g:availability>
@ -78,6 +82,7 @@ describe("generateGoogleXmlFeed", () => {
</item> </item>
<item> <item>
<g:id>sku2</g:id> <g:id>sku2</g:id>
<g:item_group_id>product-id</g:item_group_id>
<title>Product - Product variant 2</title> <title>Product - Product variant 2</title>
<g:condition>new</g:condition> <g:condition>new</g:condition>
<g:availability>out_of_stock</g:availability> <g:availability>out_of_stock</g:availability>

View file

@ -2,13 +2,13 @@ import { describe, it, expect } from "vitest";
import { productToProxy } from "./product-to-proxy"; import { productToProxy } from "./product-to-proxy";
describe("productToProxy", () => { describe("productToProxy", () => {
it("Falls back product ID, if product SKU doesnt exist", () => { it("Falls back product ID, if product SKU doesn't exist", () => {
const result = productToProxy({ const result = productToProxy({
slug: "slug", slug: "slug",
availability: "in_stock", availability: "in_stock",
category: "1", category: "1",
condition: "new", condition: "new",
id: "id", id: "product-id",
name: "Name", name: "Name",
variantId: "variant-id", variantId: "variant-id",
}); });
@ -16,13 +16,13 @@ describe("productToProxy", () => {
expect(result.item).toEqual( expect(result.item).toEqual(
expect.arrayContaining([ expect.arrayContaining([
{ {
"g:id": expect.arrayContaining([{ "#text": "id" }]), "g:id": expect.arrayContaining([{ "#text": "variant-id" }]),
}, },
]) ])
); );
}); });
it('Falls back g:condition to "new" if product condition doesnt exist', () => { it('Falls back g:condition to "new" if product condition doesn\'t exist', () => {
const result = productToProxy({ const result = productToProxy({
slug: "slug", slug: "slug",
availability: "in_stock", availability: "in_stock",
@ -31,7 +31,7 @@ describe("productToProxy", () => {
* Missing condition field: * Missing condition field:
* condition: "new", * condition: "new",
*/ */
id: "id", id: "product-id",
name: "Name", name: "Name",
variantId: "variant-id", variantId: "variant-id",
}); });
@ -51,7 +51,7 @@ describe("productToProxy", () => {
availability: "in_stock", availability: "in_stock",
category: "1", category: "1",
condition: "new", condition: "new",
id: "id", id: "product-id",
name: "Name", name: "Name",
variantId: "variant-id", variantId: "variant-id",
description: "Product description", description: "Product description",
@ -73,7 +73,7 @@ describe("productToProxy", () => {
category: "1", category: "1",
condition: "new", condition: "new",
googleProductCategory: "1", googleProductCategory: "1",
id: "id", id: "product-id",
name: "Name", name: "Name",
variantId: "variant-id", variantId: "variant-id",
}); });
@ -94,7 +94,7 @@ describe("productToProxy", () => {
category: "1", category: "1",
condition: "new", condition: "new",
googleProductCategory: "1", googleProductCategory: "1",
id: "id", id: "product-id",
name: "Name", name: "Name",
variantId: "variant-id", variantId: "variant-id",
storefrontUrlTemplate: "https://example.com/p/{productSlug}/{productId}/{variantId}", storefrontUrlTemplate: "https://example.com/p/{productSlug}/{productId}/{variantId}",
@ -105,7 +105,7 @@ describe("productToProxy", () => {
{ {
link: expect.arrayContaining([ link: expect.arrayContaining([
{ {
"#text": "https://example.com/p/slug/id/variant-id", "#text": "https://example.com/p/slug/product-id/variant-id",
}, },
]), ]),
}, },
@ -120,7 +120,7 @@ describe("productToProxy", () => {
category: "1", category: "1",
condition: "new", condition: "new",
googleProductCategory: "1", googleProductCategory: "1",
id: "id", id: "product-id",
name: "Name", name: "Name",
variantId: "variant-id", variantId: "variant-id",
imageUrl: "https://image.example.com", imageUrl: "https://image.example.com",
@ -142,7 +142,7 @@ describe("productToProxy", () => {
category: "1", category: "1",
condition: "new", condition: "new",
googleProductCategory: "1", googleProductCategory: "1",
id: "id", id: "product-id",
name: "Name", name: "Name",
variantId: "variant-id", variantId: "variant-id",
imageUrl: "https://image.example.com", imageUrl: "https://image.example.com",

View file

@ -1,15 +1,19 @@
import { fillUrlTemplate } from "../feed-url/fill-url-template"; import { fillUrlTemplate } from "../feed-url/fill-url-template";
import { GoogleProxyItem, ProductEntry } from "./types"; import { GoogleProxyItem, ProductEntry } from "./types";
/**
* TODO Test
*/
export const productToProxy = (p: ProductEntry) => { export const productToProxy = (p: ProductEntry) => {
const item: GoogleProxyItem[] = [ const item: GoogleProxyItem[] = [
{ {
"g:id": [ "g:id": [
{ {
"#text": p.sku || p.id, "#text": p.sku || p.variantId,
},
],
},
{
"g:item_group_id": [
{
"#text": p.id,
}, },
], ],
}, },