mirror of
https://github.com/myronblair/tomsjavajive
synced 2026-06-30 17:50:32 -05:00
b504981b89
- merchant-feed.php: RSS 2.0 feed with all active products; includes title, description, image_link, price, availability, brand, shipping, google_product_category for each item; URL to submit in Merchant Center - header.php: placeholder GSC meta tag (replace PASTE_GSC_CODE_HERE with verification content value from Search Console) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
79 lines
3.4 KiB
PHP
79 lines
3.4 KiB
PHP
<?php
|
|
/**
|
|
* Tom's Java Jive — Google Merchant Center Product Feed (RSS 2.0 / Atom)
|
|
* URL: https://tomsjavajive.com/merchant-feed.php
|
|
* Submit this URL in Merchant Center → Products → Feeds
|
|
*/
|
|
require_once __DIR__ . '/includes/functions.php';
|
|
|
|
header('Content-Type: application/xml; charset=utf-8');
|
|
header('X-Robots-Tag: noindex');
|
|
|
|
$base = 'https://tomsjavajive.com';
|
|
|
|
$products = db()->fetchAll(
|
|
"SELECT p.*, pt.name AS type_name
|
|
FROM products p
|
|
LEFT JOIN product_types pt ON p.product_type_id = pt.type_id
|
|
WHERE p.is_active = 1
|
|
ORDER BY p.name, p.category"
|
|
);
|
|
|
|
echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
|
|
echo '<rss version="2.0" xmlns:g="http://base.google.com/ns/1.0">' . "\n";
|
|
echo '<channel>' . "\n";
|
|
echo ' <title>Tom\'s Java Jive</title>' . "\n";
|
|
echo ' <link>' . $base . '</link>' . "\n";
|
|
echo ' <description>Premium artisan flavored coffee beans, freshly roasted in Weatherford, TX.</description>' . "\n";
|
|
|
|
foreach ($products as $p) {
|
|
$images = json_decode($p['images'] ?? '[]', true);
|
|
$imageUrl = !empty($images) ? $base . $images[0] : $base . '/assets/images/placeholder-product.svg';
|
|
|
|
$categoryLabel = $p['category'] === 'Bean' ? 'Whole Bean' : 'Ground';
|
|
$title = htmlspecialchars($p['name'] . ' ' . $categoryLabel . ' Coffee');
|
|
$desc = htmlspecialchars(
|
|
$p['name'] . ' flavored artisan coffee — ' . strtolower($categoryLabel) . '. ' .
|
|
'All natural flavoring. Freshly roasted in Weatherford, TX and shipped to your door. ' .
|
|
'12 oz bag.'
|
|
);
|
|
$link = htmlspecialchars($base . '/product.php?id=' . $p['product_id']);
|
|
$imageLink = htmlspecialchars($imageUrl);
|
|
$price = number_format((float)($p['sale_price'] ?? $p['price']), 2, '.', '');
|
|
$salePrice = $p['sale_price'] ? number_format((float)$p['sale_price'], 2, '.', '') : null;
|
|
$avail = (int)$p['stock'] > 0 ? 'in stock' : 'out of stock';
|
|
$id = htmlspecialchars($p['product_id']);
|
|
$updatedAt = substr($p['updated_at'] ?? date('Y-m-d'), 0, 10);
|
|
|
|
// Google product category for flavored coffee
|
|
// https://www.google.com/basepages/producttype/taxonomy-with-ids.en-US.txt
|
|
// 2273 = Food, Beverages & Tobacco > Beverages > Coffee
|
|
$gCategory = 'Food, Beverages & Tobacco > Beverages > Coffee';
|
|
|
|
echo " <item>\n";
|
|
echo " <g:id>{$id}</g:id>\n";
|
|
echo " <g:title>{$title}</g:title>\n";
|
|
echo " <g:description>{$desc}</g:description>\n";
|
|
echo " <g:link>{$link}</g:link>\n";
|
|
echo " <g:image_link>{$imageLink}</g:image_link>\n";
|
|
echo " <g:condition>new</g:condition>\n";
|
|
echo " <g:availability>{$avail}</g:availability>\n";
|
|
echo " <g:price>{$price} USD</g:price>\n";
|
|
if ($salePrice) {
|
|
echo " <g:sale_price>{$salePrice} USD</g:sale_price>\n";
|
|
}
|
|
echo " <g:brand>Tom's Java Jive</g:brand>\n";
|
|
echo " <g:google_product_category>{$gCategory}</g:google_product_category>\n";
|
|
echo " <g:product_type>Coffee > Flavored Coffee > {$categoryLabel}</g:product_type>\n";
|
|
echo " <g:identifier_exists>false</g:identifier_exists>\n";
|
|
echo " <g:shipping>\n";
|
|
echo " <g:country>US</g:country>\n";
|
|
echo " <g:service>Standard</g:service>\n";
|
|
echo " <g:price>5.99 USD</g:price>\n";
|
|
echo " </g:shipping>\n";
|
|
echo " </item>\n";
|
|
}
|
|
|
|
echo '</channel>' . "\n";
|
|
echo '</rss>';
|