aluch / yml-generator
YML (Yandex Market Language) file generator
v1.0.1
2024-06-06 15:48 UTC
Requires
- php: >=8.0
- ext-simplexml: *
- ext-xmlwriter: *
Requires (Dev)
- ext-dom: *
- dealerdirect/phpcodesniffer-composer-installer: ^0.7.1
- escapestudios/symfony2-coding-standard: ^3.0
- friendsofphp/php-cs-fixer: ^2.3
- fzaninotto/faker: ^1.6
- phpcompatibility/php-compatibility: ^9.0
- phpunit/phpunit: ^5.0
This package is auto-updated.
Last update: 2024-11-06 16:52:33 UTC
README
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:
- OfferCustom (vendor.model)
- OfferBook (book)
- OfferAudiobook (audiobook)
- OfferArtistTitle (artist.title)
- OfferTour (tour)
- OfferEventTicket (event-ticket)
- OfferSimple (empty)
Installation
Run composer require
composer require aluch/yml-generator
Or add this to your composer.json
file:
"require": { "aluch/yml-generator": "dev-master", }
Usage examples
<?php use Aluch\YmlGenerator\Model\Offer\OfferSimple; use Aluch\YmlGenerator\Model\Category; use Aluch\YmlGenerator\Model\Currency; use Aluch\YmlGenerator\Model\Delivery; use Aluch\YmlGenerator\Model\ShopInfo; use Aluch\YmlGenerator\Settings; use Aluch\YmlGenerator\Generator; $file = tempnam(sys_get_temp_dir(), 'YMLGenerator'); $settings = (new Settings()) ->setOutputFile($file) ->setEncoding('UTF-8') ; // 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 );
Adding custom elements
if you need additional offers elements in your yml file using method addCustomElement('type','value'). For example:
$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') ->addCustomElement('type', 'value') ;
Copyright / License
See LICENSE