gennadyx/tmp-yml-generator

This package is abandoned and no longer maintained. The author suggests using the bukashk0zzz/yml-generator package instead.

YML (Yandex Market Language) file generator

v1.1.0 2017-10-23 09:23 UTC

This package is not auto-updated.

Last update: 2022-02-01 13:11:25 UTC


README

#YML (Yandex Market Language) file generator

Build Status Code Coverage Scrutinizer Code Quality SensioLabsInsight Dependency Status License Latest Stable Version Total Downloads

About

YML (Yandex Market Language) generator. Uses standard XMLWriter for generating YML file. Not required any other library you just need PHP 5.5.0 or >= version.

Generator supports this offer types:

Installation

Run composer require

composer require bukashk0zzz/yml-generator

Or add this to your composer.json file:

"require": {
	"bukashk0zzz/yml-generator": "dev-master",
}

Usage example

<?php

use Bukashk0zzz\YmlGenerator\Model\Offer\OfferSimple;
use Bukashk0zzz\YmlGenerator\Model\Category;
use Bukashk0zzz\YmlGenerator\Model\Currency;
use Bukashk0zzz\YmlGenerator\Model\Delivery;
use Bukashk0zzz\YmlGenerator\Model\ShopInfo;
use Bukashk0zzz\YmlGenerator\Settings;
use Bukashk0zzz\YmlGenerator\Generator;

$file = tempnam(sys_get_temp_dir(), 'YMLGenerator');
$settings = (new Settings())
    ->setOutputFile($file)
;

// Creating ShopInfo object (https://yandex.ru/support/webmaster/goods-prices/technical-requirements.xml#shop)
$shopInfo = (new ShopInfo())
    ->setName('BestShop')
    ->setCompany('Best online seller Inc.')
    ->setUrl('http://www.best.seller.com/')
;

// Creating currencies array (https://yandex.ru/support/webmaster/goods-prices/technical-requirements.xml#currencies)
$currencies = [];
$currencies[] = (new Currency())
    ->setId('USD')
    ->setRate(1)
;

// Creating categories array (https://yandex.ru/support/webmaster/goods-prices/technical-requirements.xml#categories)
$categories = [];
$categories[] = (new Category())
    ->setId(1)
    ->setName($this->faker->name)
;

// Creating offers array (https://yandex.ru/support/webmaster/goods-prices/technical-requirements.xml#offers)
$offers = [];
$offers[] = (new OfferSimple())
    ->setId(12346)
    ->setAvailable(true)
    ->setUrl('http://www.best.seller.com/product_page.php?pid=12348')
    ->setPrice($this->faker->numberBetween(1, 9999))
    ->setCurrencyId('USD')
    ->setCategoryId(1)
    ->setDelivery(false)
    ->setName('Best product ever')
;

// Optional creating deliveries array (https://yandex.ru/support/partnermarket/elements/delivery-options.xml)
$deliveries = [];
$deliveries[] = (new Delivery())
    ->setCost(2)
    ->setDays(1)
    ->setOrderBefore(14)
;

(new Generator($settings))->generate(
    $shopInfo,
    $currencies,
    $categories,
    $offers,
    $deliveries
);

Copyright / License

See LICENSE