PHP code example of thepublicgood / pcflib

1. Go to this page and download the library: Download thepublicgood/pcflib library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

thepublicgood / pcflib example snippets




$feed = new TPG\Pcflib\Builder();
//...

$xml = $feed->toXml();

// You can save it directly to a file as well by passing in a pathname:
$feed->toXml('pcf_feed.xml');

// You can 
$feed->offers()->add((new TPG\Pcflib\Offer())->...);

$feed->offers()->add([$offer1, $offer2]);

$feed->offers()->add($offer1)->add($offer2);

$count = $feed->offers()->count();

$count = $feed->offers()->count();

$offer->category(['Books', 'Non-fiction', 'Autobiographies']);

$offer->category(['Books', 'Non-fiction', 'Autobiographies'],
    (new TPC\Pcflib\Categories\Book)
        ->setFormat(TPC\Pcflib\Categories\Book::FORMAT_HARDCOVER)
        ->setIsbn('1234-5678-9012-3456')
        ->setAuthor('Job Rumble');
)

$offer->name('In Black and White: The Jake White Story')
    ->manufacturer('Zebra Press')
    ->description('In Black and White traces the life story of Springbok rugby coach Jake White, right up to and including the 2007 Rugby World Cup. [...] White's story will both absorb and astound.')
    ->sku(12)
    ->price(44.95);
)

$offer->ean($ean)       // EAN barcode number
  ->upc($upc)           // UPC code
  ->modelNumber($model) // Model number
  ->productUrl($url)    // URL to a product on your website
  ->imageUrl($url)      // URL to an image of the product on yout website
  ->notes($notes)       // Notes about the product
  ->marketplace()       // Set product on the marketplace
  ->bundle()            // Set the product as a bundle
  ->groupId($group)     // Group ID for grouping individual products
;

$offer->price(151.96, 139.50, 25);
/*
 * Set a price of R151.96
 * Set a sales price of R139.50
 * Set a delivery cost of R25.00
 */

$offer->contract(600, 24, TPG\Pcflib\Offer::CONTRACT_PERIOD_MONTHS);

$offer->productUrl('http://www.example.com/showproduct.php?product_id=21');
$offer->imageUrl('http://www.example.com/showimage.php?product_id=21');

$offer->secondHand();

// or...

$offer->secondHand(false);

$offer->availability(Offer::AVAILABILITY_IN_STOCK, 200);

$offer->availability(
  Offer::AVAILABILITY_IN_STOCK,
  Offer::ORDERED_FROM_SUPPLIER
);

/*
 * 6 units, of 750ml each
 */
$offer->units(6, 750, Offer::UNIT_MEASURE_ML);

$offers = $feed->offers()->toArray();

$sku = 12;
$offer = $feed->offers()->find($sku);

$offer->price(161.50);

$offer = $feed->offers()->clone($sku);

$feed->offers()->delete($sku);

// or...

$offer = $feed->offers()->find($sku);
$offer->delete();

$feed->offers()->purge();