Skip to content

Commit

Permalink
Add group ID
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysztofwolski committed Aug 2, 2023
1 parent 01e165d commit 8217c24
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 15 deletions.
7 changes: 7 additions & 0 deletions .changeset/forty-onions-wash.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const productBase: GoogleFeedProductVariantFragment["product"] = {
seoDescription: "Seo description",
slug: "product-slug",
thumbnail: { __typename: "Image", url: "" },
attributes: [],
};

const priceBase: GoogleFeedProductVariantFragment["pricing"] = {
Expand Down Expand Up @@ -46,6 +47,7 @@ describe("generateGoogleXmlFeed", () => {
pricing: priceBase,
name: "Product variant",
product: productBase,
attributes: [],
},
{
id: "id2",
Expand All @@ -55,6 +57,7 @@ describe("generateGoogleXmlFeed", () => {
pricing: priceBase,
name: "Product variant 2",
product: productBase,
attributes: [],
},
],
});
Expand All @@ -68,6 +71,7 @@ describe("generateGoogleXmlFeed", () => {
<description>Description</description>
<item>
<g:id>sku1</g:id>
<g:item_group_id>product-id</g:item_group_id>
<title>Product - Product variant</title>
<g:condition>new</g:condition>
<g:availability>in_stock</g:availability>
Expand All @@ -78,6 +82,7 @@ describe("generateGoogleXmlFeed", () => {
</item>
<item>
<g:id>sku2</g:id>
<g:item_group_id>product-id</g:item_group_id>
<title>Product - Product variant 2</title>
<g:condition>new</g:condition>
<g:availability>out_of_stock</g:availability>
Expand Down
22 changes: 11 additions & 11 deletions apps/products-feed/src/modules/google-feed/product-to-proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@ import { describe, it, expect } from "vitest";
import { productToProxy } from "./product-to-proxy";

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({
slug: "slug",
availability: "in_stock",
category: "1",
condition: "new",
id: "id",
id: "product-id",
name: "Name",
variantId: "variant-id",
});

expect(result.item).toEqual(
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({
slug: "slug",
availability: "in_stock",
Expand All @@ -31,7 +31,7 @@ describe("productToProxy", () => {
* Missing condition field:
* condition: "new",
*/
id: "id",
id: "product-id",
name: "Name",
variantId: "variant-id",
});
Expand All @@ -51,7 +51,7 @@ describe("productToProxy", () => {
availability: "in_stock",
category: "1",
condition: "new",
id: "id",
id: "product-id",
name: "Name",
variantId: "variant-id",
description: "Product description",
Expand All @@ -73,7 +73,7 @@ describe("productToProxy", () => {
category: "1",
condition: "new",
googleProductCategory: "1",
id: "id",
id: "product-id",
name: "Name",
variantId: "variant-id",
});
Expand All @@ -94,7 +94,7 @@ describe("productToProxy", () => {
category: "1",
condition: "new",
googleProductCategory: "1",
id: "id",
id: "product-id",
name: "Name",
variantId: "variant-id",
storefrontUrlTemplate: "https://example.com/p/{productSlug}/{productId}/{variantId}",
Expand All @@ -105,7 +105,7 @@ describe("productToProxy", () => {
{
link: expect.arrayContaining([
{
"#text": "https://example.com/p/slug/id/variant-id",
"#text": "https://example.com/p/slug/product-id/variant-id",
},
]),
},
Expand All @@ -120,7 +120,7 @@ describe("productToProxy", () => {
category: "1",
condition: "new",
googleProductCategory: "1",
id: "id",
id: "product-id",
name: "Name",
variantId: "variant-id",
imageUrl: "https://image.example.com",
Expand All @@ -142,7 +142,7 @@ describe("productToProxy", () => {
category: "1",
condition: "new",
googleProductCategory: "1",
id: "id",
id: "product-id",
name: "Name",
variantId: "variant-id",
imageUrl: "https://image.example.com",
Expand Down
12 changes: 8 additions & 4 deletions apps/products-feed/src/modules/google-feed/product-to-proxy.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { fillUrlTemplate } from "../feed-url/fill-url-template";
import { GoogleProxyItem, ProductEntry } from "./types";

/**
* TODO Test
*/
export const productToProxy = (p: ProductEntry) => {
const item: GoogleProxyItem[] = [
{
"g:id": [
{
"#text": p.sku || p.id,
"#text": p.sku || p.variantId,
},
],
},
{
"g:item_group_id": [
{
"#text": p.id,
},
],
},
Expand Down

0 comments on commit 8217c24

Please sign in to comment.