0.1.2 • Published 6 months ago

@xcommerceweb/google-merchant-feed v0.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

Google Merchant Feed 🛍️

A simple library to generate Google Merchant XML Feed

npm version CI License: MIT

Installation

npm install @xcommerceweb/google-merchant-feed

Usage

import { FeedBuilder } from "@xcommerceweb/google-merchant-feed";

const feedBuilder = new FeedBuilder();

feedBuilder.withTitle("Test Store");
feedBuilder.withLink("https://example.com");
feedBuilder.withDescription("An example item from the feed");

feedBuilder.withProduct({
  id: "DB_1",
  title: "Dog Bowl In Blue",
  description: "Solid plastic Dog Bowl in marine blue color",
  link: "http://www.example.com/bowls/db-1.html",
  imageLink: "http://images.example.com/DB_1.png",
  availability: "in_stock",
  price: {
    currency: "GBP",
    value: 9.99,
  },
  shipping: {
    country: "UK",
    service: "Standard",
    price: {
      currency: "GBP",
      value: 4.95,
    },
  },
  googleProductCategory: "Animals > Pet Supplies",
  customLabels: ["Made in Waterford, IE"],
  // Other fields
});

// More products
feedBuilder.withProduct({
  // ...
});

const xml = feedBuilder.buildXml();

console.log(xml);

Example

XML generated by the code above:

<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:g="http://base.google.com/ns/1.0" version="2.0">
  <channel>
    <title>Test Store</title>
    <link>https://example.com</link>
    <description>An example item from the feed</description>
    <item>
      <g:id>DB_1</g:id>
      <g:title>Dog Bowl In Blue</g:title>
      <g:description>Solid plastic Dog Bowl in marine blue color</g:description>
      <g:link>http://www.example.com/bowls/db-1.html</g:link>
      <g:image_link>http://images.example.com/DB_1.png</g:image_link>
      <g:availability>in_stock</g:availability>
      <g:price>9.99 GBP</g:price>
      <g:google_product_category>Animals &gt; Pet Supplies</g:google_product_category>
      <g:custom_label_0>Made in Waterford, IE</g:custom_label_0>
      <g:shipping>
        <g:country>UK</g:country>
        <g:service>Standard</g:service>
        <g:price>4.95 GBP</g:price>
      </g:shipping>
    </item>
  </channel>
</rss>
0.1.2

6 months ago

0.1.1

6 months ago