elfeffe/google-shopping-product-feed

PHP 的 Google Shopping 产品 Feed

1.1.2 2016-06-19 11:37 UTC

This package is auto-updated.

Last update: 2024-09-01 17:30:34 UTC


README

#Google Shopping Product Feed 一个用于生成 Google Shopping Feed 的 PHP 库。可以从前端数据库、json 或 xml 文件中检索填充 Feed 的数据,或者手动添加。

欢迎提交问题、功能请求和 pull 请求!

目前已在英国、德国和法国的 Feed 上进行了测试。已经使用并会添加用于使数据通过 Google 商家中心验证的功能。这主要适用于尺寸和颜色变体等边缘情况。

更多信息请参阅:https://support.google.com/merchants/answer/188494?hl=en-GB

##安装

###Composer (.json)

{
    "require": {
        "ninthyard/google-shopping-product-feed": "master"
    }
}

###Composer (命令行)

composer require ninthyard/google-shopping-product-feed

###标准安装 如果不使用 composer 并包含 vendor/autoload.php,则在使用之前需要包含以下内容

require('src/NinthYard/GoogleShoppingFeed/Feed.php');
require('src/NinthYard/GoogleShoppingFeed/Item.php');
require('src/NinthYard/GoogleShoppingFeed/Node.php');
require('src/NinthYard/GoogleShoppingFeed/Containers/GoogleShopping.php');

##使用

###示例 请查看 examples_using_composer.php 以简要了解如何创建 Google Shopping Feed。

更多示例将随后提供。

###概述

require('vendor/autoload.php');
use NinthYard\GoogleShoppingFeed\Containers\GoogleShopping;

GoogleShopping::title('Test Feed');
GoogleShopping::link('http://www.example.com/');
GoogleShopping::description('Test Google Shopping Feed');

$item = GoogleShopping::createItem();
$item->id('SKU0001');//A SKU code for example, or any unique identifies (eg. could be the id from a database table)
$item->title('An Example Product Title');
$item->price('29.99'); //Price one wishes to sell a product for (unless sale_price option is added, then it's the original price)
$item->mpn('ACME00001');
$item->brand('ACME');
$item->sale_price('19.99'); //The actual price one wishes to sell a product for (optional)
$item->link('http://www.example.com/example-product.html');
$item->image_link('http://www.example.com/example-image.jpg');


/** create a variant */
$variant = $item->variant();
$variant->size('L');
$variant->color('Green');

/**
 * If creating variants one should delete the initial product object as
 * the variants will have the original $item properties and will be
 * grouped under one product group with the information from the $item
 * 
 * $item->delete();
 *
**/


// boolean value true outputs to browser as XML
GoogleShopping::asRss(true);

// boolean value true outputs raw (to put in a file for example)
file_put_contents('myfeed.xml', GoogleShopping::asRss(false));