diff --git a/.github/workflows/build-production-zip.yml b/.github/workflows/build-production-zip.yml new file mode 100644 index 0000000..07b9342 --- /dev/null +++ b/.github/workflows/build-production-zip.yml @@ -0,0 +1,42 @@ +name: Build Production Zip + +on: + workflow_dispatch: + +jobs: + build: + name: Build Production Zip + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '7.4' + tools: composer:v2 + coverage: none + + - name: Get Composer cache directory + id: composer-cache + run: echo "dir=$(composer config cache-files-dir)" >> "$GITHUB_OUTPUT" + + - name: Cache Composer dependencies + uses: actions/cache@v4 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + + - name: Build production zip + run: ./bin/build-prod-zip.sh + + - name: Upload production zip artifact + uses: actions/upload-artifact@v4 + with: + name: woocommerce-product-feed-for-openai + path: build/woocommerce-product-feed-for-openai + if-no-files-found: error + retention-days: 7 diff --git a/.gitignore b/.gitignore index 5e41603..c0a5799 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,5 @@ vendor/ # Core test files tests/unit/woo +# Build folder +build/ diff --git a/README.md b/README.md index de6cb62..69c7649 100644 --- a/README.md +++ b/README.md @@ -4,158 +4,19 @@ A WooCommerce plugin that automatically generates and delivers product feeds to ## What This Plugin Does -**Connects your WooCommerce store to OpenAI's ChatGPT commerce platform** by automatically generating product feeds in the [required format](https://developers.openai.com/commerce/specs/feed) and delivering them via multiple channels. - -### Core Features - -- **Complete OpenAI Specification Coverage** - All required and optional fields supported -- **Real-time Updates** - Products sync within 30 seconds of changes -- **Scheduled Delivery** - Automatic full feed updates every 15 minutes -- **Per-Product Control** - Override global settings for individual products -- **Feed Validation** - Built-in validation against OpenAI specifications -- **Multiple Formats** - JSON, CSV, XML, TSV export options -- **Secure API Access** - Admin-only REST endpoints for integration +- **ProductFeed generation abstraction** to support the large store. +- **Complete OpenAI Specification Coverage** includes: + - All required and optional fields supported + - Automatic full feed updates every 15 minutes + - Override global settings for individual products + - Built-in validation against OpenAI specifications +- **Pos Catalog generation** ## Quick Start -### Installation - -1. **Download** the latest release from GitHub Releases +1. **Build and get zip file** from the latest `trunk` branch by either: + - Running `npm run build` in your local env + - Running [Build Production Zip](https://github.com/woocommerce/OpenAI-Product-Feed/actions/workflows/build-production-zip.yml) workflow manually for your selected branch 2. **Upload** the zip file via WordPress admin (Plugins > Add New > Upload Plugin) or extract to `/wp-content/plugins/` 3. **Activate** the plugin through WordPress admin -4. Go to **WooCommerce > Settings > Integrations > ChatGPT** - -### Basic Setup - -1. **Sign Up as OpenAI Merchant** - - Register at [ChatGPT Merchants](https://chatgpt.com/merchants) - - Verify your feed meets OpenAI specifications - -2. **Configure Integration Settings** - - Set your Feed Delivery URL (endpoint provided by OpenAI) - - Set Return Window (days) - - Store identity and policy settings are managed in WooCommerce core - -4. **Test Your Feed** - - Click "Preview Feed" to see generated data - - Check for validation errors - - Download sample feed files - -## How It Works - -### Product Data Mapping - -The plugin automatically maps your WooCommerce products to OpenAI's required format: - -| WooCommerce Data | OpenAI Field | Notes | -|------------------|--------------|-------| -| Product ID | `id` | Unique identifier | -| Product Name | `title` | HTML stripped | -| Description | `description` | Long or short description | -| Stock Status | `availability` | `in_stock`, `out_of_stock`, `preorder` | -| Weight | `weight` | With unit (kg, lbs, etc.) | -| Images | `image_link`, `additional_image_link` | URLs | -| Categories | `product_category` | Hierarchical path | -| Attributes | `color`, `size`, `material`, etc. | Product attributes | - -### Feed Delivery Options - -**1. Push to OpenAI (Automatic)** -- Scheduled: Every 15 minutes -- Delta: 30 seconds after product changes -- Manual: On-demand admin trigger - -**2. Pull via API (On-demand)** -``` -GET /wp-json/wc/v3/openai-feed -GET /wp-json/wc/v3/openai-feed?product_id=123 -``` - -## Product Control - -### Global Settings -Set store-wide defaults for: -- **Search Visibility** - Whether products appear in ChatGPT search -- **Checkout Enabled** - Whether products allow direct purchase -- **Merchant Info** - Store details, policies, shipping - -### Per-Product Overrides -Override global settings for specific products: -- **Disable Search** - Exclude from ChatGPT search results -- **Disable Checkout** - Remove direct purchase option -- **Custom Fields** - Add product-specific data (GTIN, MPN, warnings, etc.) - -## Required vs Optional Fields - -### Required Fields (Always Included) -- `enable_search`, `enable_checkout` - AI platform flags -- `id`, `title`, `description`, `link` - Basic product info -- `gtin`, `brand` - Product identifiers (with fallbacks) -- `availability`, `inventory_quantity` - Stock info -- `weight` - Product weight - -### Optional Fields (When Available) -- **Product Details** - MPN, category, material, condition, age group -- **Dimensions** - Length, width, height, combined dimensions -- **Media** - Additional images, videos, 3D models -- **Pricing** - Sale prices, promotional dates -- **Variants** - Colors, sizes, gender targeting -- **Shipping** - Methods, pickup options, SLA -- **Compliance** - Warnings, age restrictions, Q&A - -## Access - - -### Endpoints -```http -# Get complete feed -GET /wp-json/wc/v3/openai-feed - -# Preview specific product -GET /wp-json/wc/v3/openai-feed?product_id=123 - -# Response format -Content-Type: application/json -[ - { - "enable_search": "true", - "id": "123", - "title": "Product Name", - "availability": "in_stock", - "weight": "1.5 kg" - // ... all mapped fields - } -] -``` - -## Validation & Troubleshooting - -### Feed Validation -- **Automatic** - Validates before every delivery -- **Manual** - Test via "Preview Feed" button -- **Logged** - All validation errors logged to WooCommerce logs - -### Common Issues - -**Missing Required Fields** -- GTIN → Add `_gtin` custom field or uses fallback `'MISSING'` -- Brand → Add `pa_brand` attribute or uses fallback `'Generic'` - -**Validation Errors** -- Check WooCommerce > Status > Logs (source: wpfoai) -- Verify product data completeness -- Test with single product preview - -**Delivery Issues** -- Confirm endpoint URL and token -- Check WooCommerce logs for HTTP errors -- Verify network connectivity - - -### Getting Help -- Check WooCommerce > Status > Logs (source: wpfoai) -- Use "Preview Feed" for testing individual products -- Verify all required WooCommerce data is present - -### Logs Location -WooCommerce > Status > Logs > Filter by source: `wpfoai` +4. Go to **WooCommerce > Settings > Integrations > OpenAI** for OpenAI Product feed. diff --git a/bin/build-prod-zip.sh b/bin/build-prod-zip.sh new file mode 100755 index 0000000..93eac0b --- /dev/null +++ b/bin/build-prod-zip.sh @@ -0,0 +1,67 @@ +#!/bin/bash + +# Build production zip file for woocommerce-product-feed-for-openai +# Exit on any error +set -e + +# Plugin slug constant +PLUGIN_SLUG="woocommerce-product-feed-for-openai" + +echo "======================================" +echo "Building Production Zip" +echo "======================================" + +echo "" +echo "Step 1: Creating build directory..." +mkdir -p ./build + +if [ -d "./build/${PLUGIN_SLUG}" ]; then + echo "Removing existing ${PLUGIN_SLUG} directory..." + rm -rf ./build/${PLUGIN_SLUG} +fi + +echo "" +echo "Step 2: Creating ${PLUGIN_SLUG} fresh directory..." +mkdir -p ./build/${PLUGIN_SLUG} + +echo "" +echo "Step 3: Installing production dependencies..." +COMPOSER_VENDOR_DIR=./build/${PLUGIN_SLUG}/vendor composer install --no-dev --optimize-autoloader + +echo "" +echo "Step 4: Copying files and folders..." +FILES_TO_COPY=( + "./src" + "./openai-product-feed-for-woo.php" +) + +for file in "${FILES_TO_COPY[@]}"; do + cp -r "$file" ./build/${PLUGIN_SLUG} +done + +echo "" +echo "Step 5: Creating zip file..." +cd ./build +if [ -f "${PLUGIN_SLUG}.zip" ]; then + echo "Removing existing zip file..." + rm ${PLUGIN_SLUG}.zip +fi +zip -r ${PLUGIN_SLUG}.zip ${PLUGIN_SLUG} +cd .. + +# Success message +echo "" +echo "======================================" +echo "✓ SUCCESS!" +echo "======================================" +echo "Production zip file created successfully!" +echo "Location: ./build/${PLUGIN_SLUG}.zip" +echo "Size: $(du -h ./build/${PLUGIN_SLUG}.zip | awk '{print $1}')" + +# Cleanup build directory when not in CI environment +if [ -z "$CI" ]; then + echo "Removing ./build/${PLUGIN_SLUG} directory" + rm -rf ./build/${PLUGIN_SLUG} +fi + +echo "Done!" diff --git a/package.json b/package.json index 2d11b45..4655f42 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ }, "license": "GPL-2.0-or-later", "scripts": { + "build": "./bin/build-prod-zip.sh", "env:start": "wp-env start --update", "env:stop": "wp-env stop", "test:php": "./bin/checkout-woo-tests.sh && wp-env run --env-cwd='wp-content/plugins/woocommerce-product-feed-for-openai' tests-cli vendor/bin/phpunit -c phpunit.xml tests/unit/ProductFeed",