mikemiles86/bazaarvoice-productfeed

A PHP library for generating Bazaarvoice XML ProductFeeds.

1.1.1 2022-07-19 20:45 UTC

This package is auto-updated.

Last update: 2024-10-20 02:11:12 UTC


README

Latest Version on Packagist Software License Total Downloads

A PHP library for generating and sFTPing XML Bazaarvoice ProductFeeds.

Install

Via Composer

$ composer require mikemiles86/bazaarvoice-productfeed

Usage

Creating a Feed.

$productFeed = new \BazaarvoiceProductFeed\ProductFeed();

Creating a feedElement

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

Creating an Incremental feed.

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

Creating products and adding them to a feed.

$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);

Creating categories and adding them to a feed.

$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);

Creating brands and adding them to a feed.

$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);

Print ProductFeed XML string

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

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

print $productFeed->printFeed($feed_element);

Saving Productfeed as an XML file.

$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 ProductFeed to Bazaarvoice Production.

$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 ProductFeed to Bazaarvoice Staging.

$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.
  }
}

Testing

$ composer test

Credits

License

The MIT License (MIT). Please see License File for more information.