Skip to content

Commit

Permalink
Add shipping_label attribute to Product Feed(#1713)
Browse files Browse the repository at this point in the history
Co-authored-by: Krzysztof Żuraw <[email protected]>
  • Loading branch information
JannikZed and krzysztofzuraw authored Jan 28, 2025
1 parent 34da7f1 commit 6c4e330
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/flat-horses-yawn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"products-feed": minor
---

Adding support for shipping_label in the attributes mapping.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const exampleAttributeMappingConfig: RootConfig["attributeMapping"] = {
materialAttributeIds: [],
sizeAttributeIds: [],
gtinAttributeIds: [],
shippingLabelAttributeIds: [],
};

const exampleTitleTemplate: RootConfig["titleTemplate"] =
Expand Down Expand Up @@ -55,6 +56,7 @@ describe("AppConfig", function () {
materialAttributeIds: [],
sizeAttributeIds: [],
gtinAttributeIds: [],
shippingLabelAttributeIds: [],
},
titleTemplate: "{{variant.product.name}} - {{variant.name}}",
imageSize: 1024,
Expand Down Expand Up @@ -88,6 +90,7 @@ describe("AppConfig", function () {
materialAttributeIds: [],
sizeAttributeIds: [],
gtinAttributeIds: [],
shippingLabelAttributeIds: [],
},
titleTemplate: "{{variant.product.name}} - {{variant.name}}",
imageSize: 1024,
Expand Down Expand Up @@ -120,6 +123,7 @@ describe("AppConfig", function () {
materialAttributeIds: [],
sizeAttributeIds: [],
gtinAttributeIds: [],
shippingLabelAttributeIds: [],
},
titleTemplate: "{{ variant.name }}",
imageSize: 1024,
Expand All @@ -144,6 +148,7 @@ describe("AppConfig", function () {
materialAttributeIds: [],
sizeAttributeIds: [],
gtinAttributeIds: [],
shippingLabelAttributeIds: [],
},
titleTemplate: "{{ variant.name }}",
imageSize: 1024,
Expand Down Expand Up @@ -174,6 +179,7 @@ describe("AppConfig", function () {
materialAttributeIds: [],
sizeAttributeIds: ["size-id"],
gtinAttributeIds: [],
shippingLabelAttributeIds: ["shipping-label-id"],
},
titleTemplate: "{{ variant.product.name }} - {{ variant.name }}",
imageSize: 1024,
Expand Down Expand Up @@ -202,6 +208,37 @@ describe("AppConfig", function () {
materialAttributeIds: [],
sizeAttributeIds: ["size-id"],
gtinAttributeIds: [],
shippingLabelAttributeIds: ["shipping-label-id"],
},
titleTemplate: "{{ variant.product.name }} - {{ variant.name }}",
imageSize: 1024,
});
});

it("getRootConfig returns root config data with shipping label attributes", () => {
expect(instance.getRootConfig()).toEqual({
s3: {
region: "region",
bucketName: "bucket",
accessKeyId: "access",
secretAccessKey: "secret",
},
channelConfig: {
test: {
storefrontUrls: {
productStorefrontUrl: "https://example.com",
storefrontUrl: "https://example.com/p/{{ variant.product.slug }}",
},
},
},
attributeMapping: {
brandAttributeIds: [],
colorAttributeIds: [],
patternAttributeIds: [],
materialAttributeIds: [],
sizeAttributeIds: ["size-id"],
gtinAttributeIds: [],
shippingLabelAttributeIds: ["shipping-label-id"],
},
titleTemplate: "{{ variant.product.name }} - {{ variant.name }}",
imageSize: 1024,
Expand Down Expand Up @@ -234,6 +271,7 @@ describe("AppConfig", function () {
materialAttributeIds: [],
sizeAttributeIds: ["size-id"],
gtinAttributeIds: [],
shippingLabelAttributeIds: ["shipping-label-id"],
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const attributeMappingSchema = z.object({
materialAttributeIds: z.array(z.string()).default([]),
patternAttributeIds: z.array(z.string()).default([]),
gtinAttributeIds: z.array(z.string()).default([]),
shippingLabelAttributeIds: z.array(z.string()).default([]),
});

const s3ConfigSchema = z.object({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ export const AttributeMappingConfigurationForm = (props: Props) => {
label="GTIN attributes"
options={options}
/>
<Multiselect
control={control}
name="shippingLabelAttributeIds"
label="Shipping Label attributes"
options={options}
/>
<Box display={"flex"} flexDirection={"row"} gap={4} justifyContent={"flex-end"}>
<Button type="submit" variant="primary">
Save mapping
Expand Down Expand Up @@ -118,6 +124,7 @@ export const ConnectedAttributeMappingForm = () => {
patternAttributeIds: [],
materialAttributeIds: [],
gtinAttributeIds: [],
shippingLabelAttributeIds: [],
};
}, [data]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ describe("attribute-mapping", () => {
materialAttributeIds: ["material-id"],
sizeAttributeIds: ["size-id"],
gtinAttributeIds: ["gtin-id"],
shippingLabelAttributeIds: ["shipping-label-id"],
},
}),
).toStrictEqual({
Expand All @@ -167,6 +168,7 @@ describe("attribute-mapping", () => {
brand: undefined,
pattern: undefined,
gtin: undefined,
shipping_label: undefined,
});
});

Expand Down Expand Up @@ -271,6 +273,7 @@ describe("attribute-mapping", () => {
sizeAttributeIds: ["size-id"],
patternAttributeIds: ["pattern-id"],
gtinAttributeIds: ["gtin-id"],
shippingLabelAttributeIds: ["shipping-label-id"],
},
}),
).toStrictEqual({
Expand All @@ -280,6 +283,7 @@ describe("attribute-mapping", () => {
brand: "Saleor",
pattern: "Plain",
gtin: "01234500001-0",
shipping_label: undefined,
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,18 @@ export const getMappedAttributes = ({
);
const gtinValue = attributeArrayToValueString(gtinAttributes);

const shippingLabelAttributes = attributes.filter((a) =>
mapping.shippingLabelAttributeIds.includes(a.attribute.id),
);
const shippingLabelValue = attributeArrayToValueString(shippingLabelAttributes);

return {
material: materialValue,
brand: brandValue,
color: colorValue,
size: sizeValue,
pattern: patternValue,
shipping_label: shippingLabelValue,
gtin: gtinValue,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export const generateGoogleXmlFeed = ({
pattern: attributes?.pattern,
size: attributes?.size,
gtin: attributes?.gtin,
shipping_label: attributes?.shipping_label,
weight,
...pricing,
});
Expand Down
10 changes: 10 additions & 0 deletions apps/products-feed/src/modules/google-feed/product-to-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,16 @@ export const productToProxy = (p: ProductEntry) => {
});
}

if (p.shipping_label) {
item.push({
"g:shipping_label": [
{
"#text": p.shipping_label,
},
],
});
}

return {
item,
};
Expand Down
1 change: 1 addition & 0 deletions apps/products-feed/src/modules/google-feed/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type ProductEntry = {
pattern?: string;
weight?: string;
gtin?: string;
shipping_label?: string;
};

export type ShopDetailsEntry = {
Expand Down
5 changes: 5 additions & 0 deletions apps/products-feed/src/pages/configuration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ const ConfigurationPage: NextPage = () => {
Size
</TextLink>
</li>
<li>
<TextLink href="https://support.google.com/merchants/answer/6324504" newTab>
Shipping Label
</TextLink>
</li>
</ul>
</Box>
}
Expand Down

0 comments on commit 6c4e330

Please sign in to comment.