PHP code example of iamsaint / yml

1. Go to this page and download the library: Download iamsaint/yml 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/ */

    

iamsaint / yml example snippets



use iamsaint\yml\Writer;
use iamsaint\yml\components\{
    Shop,
    Currency,
    Category
}

// create shop
$shop = new Shop();
$shop->setName('Shop Name')
    ->setUrl('http://...')
    ->setCompany('My Company');

// create currency
$currency = new Currency();
$currency
    ->setId(Currency::RUR)
    ->setRate(Currency::DEFAULT_RATE);

// add currency
$shop->addCurrency($currency);

// create category
$category = new Category();
$category
    ->setId(1)
    ->setName("My category");

// create subcategory
$subCategory = new Category();
$subCategory
    ->setId(2)
    ->setParentId(1)
    ->setName("My subcategory");

// add categories to shop
$shop->addCategory($category);
$shop->addCategory($subCategory);

// create offer
$offer = new Offer();

$offer->setId(123)
    ->setUrl('http://...')
    ->setPrice(1000)
    ->setCurrencyId(Currency::RUR);

// add offer to shop    
$shop->addOffer($offer);

// create writer
$writer = new Writer();

// write to file
$writer->write('path/to/file.yml', $shop);