mikemiles86 / bazaarvoice-productfeed

一个用于生成 Bazaarvoice XML 产品数据的 PHP 库。

1.1.1 2022-07-19 20:45 UTC

This package is auto-updated.

Last update: 2024-09-20 01:59:25 UTC


README

Latest Version on Packagist Software License Total Downloads

一个用于生成和通过 sFTP 上传 XML Bazaarvoice 产品数据 的 PHP 库。

安装

通过 Composer

$ composer require mikemiles86/bazaarvoice-productfeed

使用方法

创建数据流。

$productFeed = new \BazaarvoiceProductFeed\ProductFeed();

创建数据流元素。

$productFeed = new \BazaarvoiceProductFeed\ProductFeed();
$feed_element = $productFeed->newFeed('my_feed');

创建增量数据流。

$productFeed = new \BazaarvoiceProductFeed\ProductFeed();
$feed_element = $productFeed->newFeed('my_feed', TRUE);
$productFeed = new \BazaarvoiceProductFeed\ProductFeed();
$feed_element = $productFeed->newFeed('my_feed')
  ->setIncremental(TRUE);

创建产品和将它们添加到数据流中。

$productFeed = new \BazaarvoiceProductFeed\ProductFeed();
$feed_element = $productFeed->newFeed('my_feed');

$product_element = $productFeed->newProduct('my_product', 'My Product', 'product_category_123', 'htttp://www.example.com/my-product', 'http://www.example.com/images/my-product.jpg');
$feed_element->addProduct($product_element);

$more_products = [];

$second_product = $productFeed->newProduct('second_product', 'Second Product', 'product_category_456', 'htttp://www.example.com/second-product', 'http://www.example.com/images/second-product.jpg');
  ->setDescription('This is my second product')
  ->addPageUrl('http://www.example.es/second-product', 'es_SP')
  ->setBrandId('my_brand_123')
  ->addUPC('012345');
  
$more_products[] = $second_product;

$more_products[] = $productFeed->newProduct('third_product', 'Third Product', 'product_category_789', 'htttp://www.example.com/third-product', 'http://www.example.com/images/third-product.jpg')
  ->addISBN('123-456-7890')
  ->addPageUrl('http://www.example.co.uk/third-product', 'en_UK')
  ->addCustomAttribute('PRODUCT_FAMILY', 'example_products');

$feed_element->addProducts($more_products);

创建类别并将它们添加到数据流中。

$productFeed = new \BazaarvoiceProductFeed\ProductFeed();
$feed_element = $productFeed->newFeed('my_feed');

// ...

$category_element = $productFeed->newCategory('my_category', 'My Category', 'htttp://www.example.com/my-product');
$feed_element->addCategory($category_element);

$more_categories = [];

$second_category = $productFeed->newCategory('second_category', 'Second Category', 'http://www.example.com/second-category')
  ->setImageUrl('http://www.example.com/images/second-category.jpg')
  ->addImageUrl('http://www.example.co.uk/images/uk-second-category.jpg', 'en_UK')
  ->setParentId('parent_category_id');

$more_categories[] = $second_category;

$feed_element->addCategories($more_categories);

创建品牌并将它们添加到数据流中。

$productFeed = new \BazaarvoiceProductFeed\ProductFeed();
$feed_element = $productFeed->newFeed('my_feed');

// ...

$brand_element = $productFeed->newBrand('my_brand', 'My Brand');
$feed_element->addBrand($brand_element);

$more_brands = [];

$second_brand = $productFeed->newBrand('second_brand', 'Second Brand')
  ->addName('Duo Brand', 'es_SP')
  ->addName('Brand the Second', 'en_UK');

$more_brands[] = $second_brand;

$more_brands[] = $productFeed->newBrand('third_brand', 'Third Brand');

$feed_element->addBrands($more_brands);

打印产品数据流 XML 字符串。

$productFeed = new \BazaarvoiceProductFeed\ProductFeed();
$feed_element = $productFeed->newFeed('my_feed');

// ... add products, brands & categories ...

print $productFeed->printFeed($feed_element);

将产品数据流保存为 XML 文件。

$productFeed = new \BazaarvoiceProductFeed\ProductFeed();
$feed_element = $productFeed->newFeed('my_feed');

// ... add products, brands & categories ...

$productFeed->saveFeed($feed_element, 'path/to/dir', 'my_feed_XYZ');

通过 sFTP 将产品数据流上传到 Bazaarvoice 生产环境。

$productFeed = new \BazaarvoiceProductFeed\ProductFeed();
$feed_element = $productFeed->newFeed('my_feed');

// ... add products, brands & categories ...

if ($feed_file = $productFeed->saveFeed($feed_element, 'path/to/dir', 'my_feed_XYZ') {  
  try {
    $productFeed->sendFeed($feed_file, $sftp_username, $sftp_password);
  } catch (\Exception $e) {
    // Failed to FTP feed file.
  }
}

通过 sFTP 将产品数据流上传到 Bazaarvoice 预发布环境。

$productFeed = new \BazaarvoiceProductFeed\ProductFeed();
$feed_element = $productFeed->newFeed('my_feed');

// ... add products, brands & categories ...

if ($feed_file = $productFeed->saveFeed($feed_element, 'path/to/dir', 'my_feed_XYZ') {  
  try {
    $productFeed->useStage()->sendFeed($feed_file, $sftp_username, $sftp_password);
  } catch (\Exception $e) {
    // Failed to FTP feed file.
  }
}

测试

$ composer test

鸣谢

许可证

MIT 许可证 (MIT)。请参阅许可证文件获取更多信息。