softwarepunt/pinterest-xml-catalog

PHP Library for generating Pinterest Catalogs in XML (RSS 2.0) format

dev-main 2023-03-31 04:55 UTC

This package is not auto-updated.

Last update: 2024-11-09 10:31:27 UTC


README

Unofficial PHP Library for generating Pinterest Catalogs in XML (RSS 2.0, ATOM 1.0) format

This can be used to generate a data source for daily product ingestion by Pinterest. You must already have a business account and a claimed website that meets their merchant guidelines.

You can use this to help convert product data to XML, but you'll have to serve the output yourself.

Installation

Add the library to your project via Composer:

composer require softwarepunt/pinterest-xml-catalog

Requirements

  • PHP 7.4+
  • ext-dom

Usage

Creating an XML catalog

Collect your product data, and then feed it into a XmlCatalog instance.

<?php

use SoftwarePunt\PinterestXmlCatalog\XmlCatalog;
use SoftwarePunt\PinterestXmlCatalog\Models\ProductData;

// Create a new, blank catalog
$xmlCatalog = new XmlCatalog();

// Gather product data
$product = new ProductData();
$product->id = "4000086";
$product->title = "Illuminating Makeup Mirror";
$product->description = "A ring light mirror with 23 LED strip lights.";
$product->link = "https://www.example.com/cat/illuminating-makeup-mirror";
$product->imageLink = "https://www.example.com/media/catalog/product/image.jpg";
$product->additionalImageLink = "https://www.example.com/media/catalog/product/image_side.jpg";
$product->price = "14,99 EUR";

// Add products to catalog (can be ProductData, other object, or data array)
$xmlCatalog->addProduct($product);

// Convert to XML and serve as response
echo $xmlCatalog->toXmlString();

Product data

Pinterest uses the Google Merchant Data specifications for RSS 2.0, which you can refer to for documentation on the specific fields used.

👉 This library currently only targets fields that are in the Pinterest sample or docs, not the full Google-supported set of fields.

Using the ProductData class is recommended because it contains relevant phpdocs to make your life easier. You can also pass your own associative array or object for each product to addProduct() if you prefer.

If you are adding products from your own object or array, you should make sure that the property names / array keys can be understood by the library. For example, if you want to set the Google Product Category, valid keys to set it are googleProductCategory, g:google_product_category and google_product_category.

Required fields

When filling products, the following fields are always required:

Optional fields

These fields are optional and can be used to enrich the product with additional information.