├── .github └── workflows │ └── ci.yml ├── .gitignore ├── .php_cs ├── LICENSE ├── README.md ├── composer.json ├── phpcs.xml.dist ├── phpunit.xml.dist ├── src ├── Cdata.php ├── Generator.php ├── Model │ ├── Category.php │ ├── Currency.php │ ├── Delivery.php │ ├── Offer │ │ ├── AbstractOffer.php │ │ ├── OfferArtistTitle.php │ │ ├── OfferAudiobook.php │ │ ├── OfferBook.php │ │ ├── OfferBookTrait.php │ │ ├── OfferCondition.php │ │ ├── OfferCustom.php │ │ ├── OfferEventTicket.php │ │ ├── OfferGroupAwareInterface.php │ │ ├── OfferGroupTrait.php │ │ ├── OfferInterface.php │ │ ├── OfferOutlet.php │ │ ├── OfferParam.php │ │ ├── OfferSimple.php │ │ └── OfferTour.php │ └── ShopInfo.php └── Settings.php └── tests ├── AbstractGeneratorTest.php ├── GeneratorTest.php ├── OfferArtistTitleGeneratorTest.php ├── OfferAudiobookGeneratorTest.php ├── OfferBookGeneratorTest.php ├── OfferCdataGeneratorTest.php ├── OfferCustomElementsGeneratorTest.php ├── OfferCustomGeneratorTest.php ├── OfferDeliveryOptionsGeneratorTest.php ├── OfferEventTicketGeneratorTest.php ├── OfferSimpleGeneratorTest.php ├── OfferTourGeneratorTest.php └── dtd ├── ArtistTitle.dtd ├── Audiobook.dtd ├── Book.dtd ├── Custom.dtd ├── EventTicket.dtd ├── OfferDeliveryOptions.dtd ├── Original.dtd ├── Simple.dtd └── Tour.dtd /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: Tests 2 | 3 | on: 4 | pull_request: 5 | push: 6 | branches: 7 | - master 8 | 9 | jobs: 10 | tests: 11 | name: PHPUnit PHP ${{ matrix.php }} 12 | runs-on: ubuntu-20.04 13 | strategy: 14 | matrix: 15 | php: 16 | - '5.6' 17 | - '7.1' 18 | fail-fast: false 19 | steps: 20 | - name: Checkout 21 | uses: actions/checkout@v2 22 | 23 | - name: Setup PHP 24 | uses: shivammathur/setup-php@v2 25 | with: 26 | php-version: ${{ matrix.php }} 27 | extensions: pcov 28 | 29 | - name: Configure CS plugin 30 | run: composer config --no-plugins allow-plugins.dealerdirect/phpcodesniffer-composer-installer "true" 31 | 32 | - name: Get Composer Cache Directory 33 | id: composer-cache 34 | run: echo "::set-output name=dir::$(composer config cache-files-dir)" 35 | 36 | - name: Cache dependencies 37 | uses: actions/cache@v2 38 | with: 39 | path: ${{ steps.composer-cache.outputs.dir }} 40 | key: ${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} 41 | restore-keys: ${{ matrix.php }}-composer- 42 | 43 | - name: Update project dependencies 44 | if: matrix.dependency == '' 45 | run: composer update --no-progress --ansi --prefer-stable 46 | 47 | - name: Validate composer 48 | run: composer validate --strict --no-check-lock 49 | 50 | - name: Run CS 51 | run: ./vendor/bin/phpcs 52 | 53 | - name: Run CS Fixer 54 | run: ./vendor/bin/php-cs-fixer fix --config=./.php_cs -v --dry-run 55 | 56 | - name: Run tests 57 | run: ./vendor/bin/phpunit -c phpunit.xml.dist --coverage-clover=coverage.xml 58 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor/ 2 | .php_cs.cache 3 | phpunit.xml 4 | coverage.xml 5 | composer.lock 6 | -------------------------------------------------------------------------------- /.php_cs: -------------------------------------------------------------------------------- 1 | exclude('vendor/') 5 | ->in(__DIR__) 6 | ; 7 | 8 | return PhpCsFixer\Config::create() 9 | ->setRiskyAllowed(true) 10 | ->setRules([ 11 | '@PSR1' => true, 12 | '@PSR2' => true, 13 | '@Symfony' => true, 14 | '@Symfony:risky' => true, 15 | '@PHP70Migration' => false, 16 | '@PHP70Migration:risky' => false, 17 | '@PHP71Migration' => false, 18 | 'phpdoc_summary' => false, 19 | 'yoda_style' => false, 20 | 'no_superfluous_phpdoc_tags' => false, 21 | 'combine_consecutive_unsets' => true, 22 | 'blank_line_after_opening_tag' => false, 23 | 'phpdoc_to_comment' => false, 24 | 'phpdoc_no_empty_return' => false, 25 | 'strict_param' => true, 26 | 'doctrine_annotation_indentation' => true, 27 | 'mb_str_functions' => true, 28 | 'native_function_invocation' => true, 29 | 'no_short_echo_tag' => true, 30 | 'no_unreachable_default_argument_value' => true, 31 | 'no_useless_else' => true, 32 | 'no_useless_return' => true, 33 | 'ordered_class_elements' => true, 34 | 'phpdoc_add_missing_param_annotation' => true, 35 | 'phpdoc_order' => true, 36 | 'simplified_null_return' => false, 37 | 'strict_comparison' => true, 38 | 'ordered_imports' => ['sortAlgorithm' => 'alpha'], 39 | 'declare_equal_normalize' => ['space' => 'single'], 40 | 'array_syntax' => ['syntax' => 'short'], 41 | 'list_syntax' => ['syntax' => 'short'], 42 | 'doctrine_annotation_braces' => ['syntax' => 'with_braces'], 43 | 'general_phpdoc_annotation_remove' => ['annotations' => ['author', 'created', 'version', 'package', 'copyright', 'license', 'throws']], 44 | ]) 45 | ->setFinder($finder) 46 | ; 47 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Denis Golubovskiy 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # YML (Yandex Market Language) file generator 2 | 3 | [![Code Coverage](https://img.shields.io/codecov/c/github/Bukashk0zzz/YmlGenerator.svg?style=flat-square)](https://codecov.io/github/Bukashk0zzz/YmlGenerator) 4 | [![License](https://img.shields.io/packagist/l/Bukashk0zzz/yml-generator.svg?style=flat-square)](https://packagist.org/packages/Bukashk0zzz/yml-generator) 5 | [![Latest Stable Version](https://img.shields.io/packagist/v/Bukashk0zzz/yml-generator.svg?style=flat-square)](https://packagist.org/packages/Bukashk0zzz/yml-generator) 6 | [![Total Downloads](https://img.shields.io/packagist/dt/Bukashk0zzz/yml-generator.svg?style=flat-square)](https://packagist.org/packages/Bukashk0zzz/yml-generator) 7 | 8 | About 9 | ----- 10 | [YML (Yandex Market Language)](https://yandex.ru/support/webmaster/goods-prices/technical-requirements.xml) generator. 11 | Uses standard XMLWriter for generating YML file. 12 | Not required any other library you just need PHP 5.5.0 or >= version. 13 | 14 | Generator supports this offer types: 15 | - OfferCustom [(vendor.model)](https://yandex.ru/support/webmaster/goods-prices/technical-requirements.xml#vendor-model) 16 | - OfferBook [(book)](https://yandex.ru/support/webmaster/goods-prices/technical-requirements.xml#book) 17 | - OfferAudiobook [(audiobook)](https://yandex.ru/support/webmaster/goods-prices/technical-requirements.xml#audiobook) 18 | - OfferArtistTitle [(artist.title)](https://yandex.ru/support/webmaster/goods-prices/technical-requirements.xml#artist-title) 19 | - OfferTour [(tour)](https://yandex.ru/support/webmaster/goods-prices/technical-requirements.xml#tour) 20 | - OfferEventTicket [(event-ticket)](https://yandex.ru/support/webmaster/goods-prices/technical-requirements.xml#event-ticket) 21 | - OfferSimple [(empty)](https://yandex.ru/support/webmaster/goods-prices/technical-requirements.xml#base) 22 | 23 | Installation 24 | ------------ 25 | Run composer require 26 | 27 | ```bash 28 | composer require bukashk0zzz/yml-generator 29 | ``` 30 | 31 | 32 | Or add this to your `composer.json` file: 33 | 34 | ```json 35 | "require": { 36 | "bukashk0zzz/yml-generator": "dev-master", 37 | } 38 | ``` 39 | 40 | Usage examples 41 | ------------- 42 | 43 | ```php 44 | setOutputFile($file) 57 | ->setEncoding('UTF-8') 58 | ; 59 | 60 | // Creating ShopInfo object (https://yandex.ru/support/webmaster/goods-prices/technical-requirements.xml#shop) 61 | $shopInfo = (new ShopInfo()) 62 | ->setName('BestShop') 63 | ->setCompany('Best online seller Inc.') 64 | ->setUrl('http://www.best.seller.com/') 65 | ; 66 | 67 | // Creating currencies array (https://yandex.ru/support/webmaster/goods-prices/technical-requirements.xml#currencies) 68 | $currencies = []; 69 | $currencies[] = (new Currency()) 70 | ->setId('USD') 71 | ->setRate(1) 72 | ; 73 | 74 | // Creating categories array (https://yandex.ru/support/webmaster/goods-prices/technical-requirements.xml#categories) 75 | $categories = []; 76 | $categories[] = (new Category()) 77 | ->setId(1) 78 | ->setName($this->faker->name) 79 | ; 80 | 81 | // Creating offers array (https://yandex.ru/support/webmaster/goods-prices/technical-requirements.xml#offers) 82 | $offers = []; 83 | $offers[] = (new OfferSimple()) 84 | ->setId(12346) 85 | ->setAvailable(true) 86 | ->setUrl('http://www.best.seller.com/product_page.php?pid=12348') 87 | ->setPrice($this->faker->numberBetween(1, 9999)) 88 | ->setCurrencyId('USD') 89 | ->setCategoryId(1) 90 | ->setDelivery(false) 91 | ->setName('Best product ever') 92 | ; 93 | 94 | // Optional creating deliveries array (https://yandex.ru/support/partnermarket/elements/delivery-options.xml) 95 | $deliveries = []; 96 | $deliveries[] = (new Delivery()) 97 | ->setCost(2) 98 | ->setDays(1) 99 | ->setOrderBefore(14) 100 | ; 101 | 102 | (new Generator($settings))->generate( 103 | $shopInfo, 104 | $currencies, 105 | $categories, 106 | $offers, 107 | $deliveries 108 | ); 109 | ``` 110 | ### Adding custom elements 111 | if you need additional offers elements in your yml file using method addCustomElement('type','value'). For example: 112 | ```php 113 | $offers[] = (new OfferSimple()) 114 | ->setId(12346) 115 | ->setAvailable(true) 116 | ->setUrl('http://www.best.seller.com/product_page.php?pid=12348') 117 | ->setPrice($this->faker->numberBetween(1, 9999)) 118 | ->setCurrencyId('USD') 119 | ->setCategoryId(1) 120 | ->setDelivery(false) 121 | ->setName('Best product ever') 122 | ->addCustomElement('type', 'value') 123 | ; 124 | ``` 125 | 126 | Copyright / License 127 | ------------------- 128 | 129 | See [LICENSE](https://github.com/bukashk0zzz/YmlGenerator/blob/master/LICENSE) 130 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bukashk0zzz/yml-generator", 3 | "description": "YML (Yandex Market Language) file generator", 4 | "keywords": ["yml", "yandex", "market", "yml-generator"], 5 | "homepage": "https://github.com/Bukashk0zzz/YmlGenerator", 6 | "type": "library", 7 | "license": "MIT", 8 | "authors": [ 9 | { 10 | "name": "Denis Golubovskiy", 11 | "email": "bukashk0zzz@gmail.com", 12 | "role": "Creator" 13 | } 14 | ], 15 | "support": { 16 | "email": "bukashk0zzz@gmail.com", 17 | "issues": "https://github.com/Bukashk0zzz/YmlGenerator/issues" 18 | }, 19 | "require": { 20 | "php": ">=5.6.1", 21 | "ext-simplexml": "*", 22 | "ext-xmlwriter": "*" 23 | }, 24 | "require-dev": { 25 | "ext-dom": "*", 26 | "phpunit/phpunit": "^5.0", 27 | "fzaninotto/faker": "^1.6", 28 | "friendsofphp/php-cs-fixer": "^2.3", 29 | "escapestudios/symfony2-coding-standard": "^3.0", 30 | "phpcompatibility/php-compatibility": "^9.0", 31 | "dealerdirect/phpcodesniffer-composer-installer": "^0.7.1" 32 | }, 33 | "autoload": { 34 | "psr-4": { 35 | "Bukashk0zzz\\YmlGenerator\\": "src/" 36 | } 37 | }, 38 | "autoload-dev": { 39 | "psr-4": { 40 | "Bukashk0zzz\\YmlGenerator\\Tests\\": "tests/" 41 | } 42 | }, 43 | "config": { 44 | "allow-plugins": { 45 | "dealerdirect/phpcodesniffer-composer-installer": true 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /phpcs.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 3 | YmlGenerator coding standard. 4 | 5 | vendor/ 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | ./ 19 | 20 | -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 14 | 15 | 16 | 17 | ./tests 18 | 19 | 20 | 21 | 22 | 23 | ./ 24 | 25 | ./tests 26 | ./vendor 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/Cdata.php: -------------------------------------------------------------------------------- 1 | value = $value; 28 | } 29 | 30 | /** 31 | * Allows to get the wrapped value by casting an instance to string 32 | * 33 | * @return string 34 | */ 35 | public function __toString() 36 | { 37 | return $this->value; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Generator.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Bukashk0zzz\YmlGenerator; 13 | 14 | use Bukashk0zzz\YmlGenerator\Model\Category; 15 | use Bukashk0zzz\YmlGenerator\Model\Currency; 16 | use Bukashk0zzz\YmlGenerator\Model\Delivery; 17 | use Bukashk0zzz\YmlGenerator\Model\Offer\OfferCondition; 18 | use Bukashk0zzz\YmlGenerator\Model\Offer\OfferGroupAwareInterface; 19 | use Bukashk0zzz\YmlGenerator\Model\Offer\OfferInterface; 20 | use Bukashk0zzz\YmlGenerator\Model\Offer\OfferOutlet; 21 | use Bukashk0zzz\YmlGenerator\Model\Offer\OfferParam; 22 | use Bukashk0zzz\YmlGenerator\Model\ShopInfo; 23 | 24 | /** 25 | * Class Generator 26 | */ 27 | class Generator 28 | { 29 | /** 30 | * @var string 31 | */ 32 | protected $tmpFile; 33 | 34 | /** 35 | * @var \XMLWriter 36 | */ 37 | protected $writer; 38 | 39 | /** 40 | * @var Settings 41 | */ 42 | protected $settings; 43 | 44 | /** 45 | * Generator constructor. 46 | * 47 | * @param Settings $settings 48 | */ 49 | public function __construct($settings = null) 50 | { 51 | $this->settings = $settings instanceof Settings ? $settings : new Settings(); 52 | $this->writer = new \XMLWriter(); 53 | 54 | if ($this->settings->getOutputFile() !== null && $this->settings->getReturnResultYMLString()) { 55 | throw new \LogicException('Only one destination need to be used ReturnResultYMLString or OutputFile'); 56 | } 57 | 58 | if ($this->settings->getReturnResultYMLString()) { 59 | $this->writer->openMemory(); 60 | } else { 61 | $this->tmpFile = $this->settings->getOutputFile() !== null ? \tempnam(\sys_get_temp_dir(), 'YMLGenerator') : 'php://output'; 62 | $this->writer->openURI($this->tmpFile); 63 | } 64 | 65 | if ($this->settings->getIndentString()) { 66 | $this->writer->setIndentString($this->settings->getIndentString()); 67 | $this->writer->setIndent(true); 68 | } 69 | } 70 | 71 | /** 72 | * @param ShopInfo $shopInfo 73 | * @param array $currencies 74 | * @param array $categories 75 | * @param array $offers 76 | * @param array $deliveries 77 | * 78 | * @return bool 79 | */ 80 | public function generate(ShopInfo $shopInfo, array $currencies, array $categories, array $offers, array $deliveries = []) 81 | { 82 | try { 83 | $this->addHeader(); 84 | 85 | $this->addShopInfo($shopInfo); 86 | $this->addCurrencies($currencies); 87 | $this->addCategories($categories); 88 | 89 | if (\count($deliveries) !== 0) { 90 | $this->addDeliveries($deliveries); 91 | } 92 | 93 | $this->addOffers($offers); 94 | $this->addFooter(); 95 | 96 | if ($this->settings->getReturnResultYMLString()) { 97 | return $this->writer->flush(); 98 | } 99 | 100 | if (null !== $this->settings->getOutputFile()) { 101 | \copy($this->tmpFile, $this->settings->getOutputFile()); 102 | @\unlink($this->tmpFile); 103 | } 104 | 105 | return true; 106 | } catch (\Exception $exception) { 107 | throw new \RuntimeException(\sprintf('Problem with generating YML file: %s', $exception->getMessage()), 0, $exception); 108 | } 109 | } 110 | 111 | /** 112 | * Add document header 113 | */ 114 | protected function addHeader() 115 | { 116 | $this->writer->startDocument('1.0', $this->settings->getEncoding()); 117 | $this->writer->startDTD('yml_catalog', null, 'shops.dtd'); 118 | $this->writer->endDTD(); 119 | $this->writer->startElement('yml_catalog'); 120 | $this->writer->writeAttribute('date', \date(\DATE_RFC3339)); 121 | $this->writer->startElement('shop'); 122 | } 123 | 124 | /** 125 | * Add document footer 126 | */ 127 | protected function addFooter() 128 | { 129 | $this->writer->fullEndElement(); 130 | $this->writer->fullEndElement(); 131 | $this->writer->endDocument(); 132 | } 133 | 134 | /** 135 | * Adds shop element data. (See https://yandex.ru/support/webmaster/goods-prices/technical-requirements.xml#shop) 136 | * 137 | * @param ShopInfo $shopInfo 138 | */ 139 | protected function addShopInfo(ShopInfo $shopInfo) 140 | { 141 | foreach ($shopInfo->toArray() as $name => $value) { 142 | if ($value !== null) { 143 | $this->writer->writeElement($name, $value); 144 | } 145 | } 146 | } 147 | 148 | /** 149 | * @param Currency $currency 150 | */ 151 | protected function addCurrency(Currency $currency) 152 | { 153 | $this->writer->startElement('currency'); 154 | $this->writer->writeAttribute('id', $currency->getId()); 155 | $this->writer->writeAttribute('rate', $currency->getRate()); 156 | $this->writer->endElement(); 157 | } 158 | 159 | /** 160 | * @param Category $category 161 | */ 162 | protected function addCategory(Category $category) 163 | { 164 | $this->writer->startElement('category'); 165 | $this->writer->writeAttribute('id', $category->getId()); 166 | 167 | if ($category->getParentId() !== null) { 168 | $this->writer->writeAttribute('parentId', $category->getParentId()); 169 | } 170 | 171 | if (!empty($category->getAttributes())) { 172 | foreach ($category->getAttributes() as $attribute) { 173 | $this->writer->writeAttribute($attribute['name'], $attribute['value']); 174 | } 175 | } 176 | 177 | $this->writer->text($category->getName()); 178 | $this->writer->fullEndElement(); 179 | } 180 | 181 | /** 182 | * @param Delivery $delivery 183 | */ 184 | protected function addDelivery(Delivery $delivery) 185 | { 186 | $this->writer->startElement('option'); 187 | $this->writer->writeAttribute('cost', $delivery->getCost()); 188 | $this->writer->writeAttribute('days', $delivery->getDays()); 189 | if ($delivery->getOrderBefore() !== null) { 190 | $this->writer->writeAttribute('order-before', $delivery->getOrderBefore()); 191 | } 192 | $this->writer->endElement(); 193 | } 194 | 195 | /** 196 | * @param OfferInterface $offer 197 | */ 198 | protected function addOffer(OfferInterface $offer) 199 | { 200 | $this->writer->startElement('offer'); 201 | $this->writer->writeAttribute('id', $offer->getId()); 202 | $this->writer->writeAttribute('available', $offer->isAvailable() ? 'true' : 'false'); 203 | 204 | if ($offer->getType() !== null) { 205 | $this->writer->writeAttribute('type', $offer->getType()); 206 | } 207 | 208 | if ($offer instanceof OfferGroupAwareInterface && $offer->getGroupId() !== null) { 209 | $this->writer->writeAttribute('group_id', $offer->getGroupId()); 210 | } 211 | 212 | foreach ($offer->toArray() as $name => $value) { 213 | if (\is_array($value)) { 214 | foreach ($value as $itemValue) { 215 | $this->addOfferElement($name, $itemValue); 216 | } 217 | } else { 218 | $this->addOfferElement($name, $value); 219 | } 220 | } 221 | $this->addOfferOutlets($offer); 222 | $this->addOfferParams($offer); 223 | $this->addOfferDeliveryOptions($offer); 224 | $this->addOfferCondition($offer); 225 | 226 | $this->writer->fullEndElement(); 227 | } 228 | 229 | /** 230 | * Adds element. (See https://yandex.ru/support/webmaster/goods-prices/technical-requirements.xml#currencies) 231 | * 232 | * @param array $currencies 233 | */ 234 | private function addCurrencies(array $currencies) 235 | { 236 | $this->writer->startElement('currencies'); 237 | 238 | /** @var Currency $currency */ 239 | foreach ($currencies as $currency) { 240 | if ($currency instanceof Currency) { 241 | $this->addCurrency($currency); 242 | } 243 | } 244 | 245 | $this->writer->fullEndElement(); 246 | } 247 | 248 | /** 249 | * Adds element. (See https://yandex.ru/support/webmaster/goods-prices/technical-requirements.xml#categories) 250 | * 251 | * @param array $categories 252 | */ 253 | private function addCategories(array $categories) 254 | { 255 | $this->writer->startElement('categories'); 256 | 257 | /** @var Category $category */ 258 | foreach ($categories as $category) { 259 | if ($category instanceof Category) { 260 | $this->addCategory($category); 261 | } 262 | } 263 | 264 | $this->writer->fullEndElement(); 265 | } 266 | 267 | /** 268 | * Adds element. (See https://yandex.ru/support/partnermarket/elements/delivery-options.xml) 269 | * 270 | * @param array $deliveries 271 | */ 272 | private function addDeliveries(array $deliveries) 273 | { 274 | $this->writer->startElement('delivery-options'); 275 | 276 | /** @var Delivery $delivery */ 277 | foreach ($deliveries as $delivery) { 278 | if ($delivery instanceof Delivery) { 279 | $this->addDelivery($delivery); 280 | } 281 | } 282 | 283 | $this->writer->fullEndElement(); 284 | } 285 | 286 | /** 287 | * Adds element. (See https://yandex.ru/support/webmaster/goods-prices/technical-requirements.xml#offers) 288 | * 289 | * @param array $offers 290 | */ 291 | private function addOffers(array $offers) 292 | { 293 | $this->writer->startElement('offers'); 294 | 295 | /** @var OfferInterface $offer */ 296 | foreach ($offers as $offer) { 297 | if ($offer instanceof OfferInterface) { 298 | $this->addOffer($offer); 299 | } 300 | } 301 | 302 | $this->writer->fullEndElement(); 303 | } 304 | 305 | /** 306 | * @param OfferInterface $offer 307 | */ 308 | private function addOfferDeliveryOptions(OfferInterface $offer) 309 | { 310 | $options = $offer->getDeliveryOptions(); 311 | if (!empty($options)) { 312 | $this->addDeliveries($options); 313 | } 314 | } 315 | 316 | /** 317 | * @param OfferInterface $offer 318 | */ 319 | private function addOfferParams(OfferInterface $offer) 320 | { 321 | /** @var OfferParam $param */ 322 | foreach ($offer->getParams() as $param) { 323 | if ($param instanceof OfferParam) { 324 | $this->writer->startElement('param'); 325 | 326 | $this->writer->writeAttribute('name', $param->getName()); 327 | if ($param->getUnit()) { 328 | $this->writer->writeAttribute('unit', $param->getUnit()); 329 | } 330 | $this->writer->text($param->getValue()); 331 | 332 | $this->writer->endElement(); 333 | } 334 | } 335 | } 336 | 337 | /** 338 | * @param OfferInterface $offer 339 | */ 340 | private function addOfferOutlets(OfferInterface $offer) 341 | { 342 | if ($offer->getOutlets() && \count($offer->getOutlets())) { 343 | $this->writer->startElement('outlets'); 344 | /** @var OfferOutlet $outlet */ 345 | foreach ($offer->getOutlets() as $outlet) { 346 | if ($outlet instanceof OfferOutlet) { 347 | $this->writer->startElement('outlet'); 348 | 349 | $this->writer->writeAttribute('id', $outlet->getId()); 350 | $this->writer->writeAttribute('instock', $outlet->getInStock()); 351 | 352 | $this->writer->endElement(); 353 | } 354 | } 355 | $this->writer->fullEndElement(); 356 | } 357 | } 358 | 359 | /** 360 | * @param OfferInterface $offer 361 | */ 362 | private function addOfferCondition(OfferInterface $offer) 363 | { 364 | $params = $offer->getCondition(); 365 | if ($params instanceof OfferCondition) { 366 | $this->writer->startElement('condition'); 367 | $this->writer->writeAttribute('type', $params->getType()); 368 | $this->writer->writeElement('reason', $params->getReasonText()); 369 | $this->writer->endElement(); 370 | } 371 | } 372 | 373 | /** 374 | * @param string $name 375 | * @param mixed $value 376 | * 377 | * @return bool 378 | */ 379 | private function addOfferElement($name, $value) 380 | { 381 | if ($value === null) { 382 | return false; 383 | } 384 | 385 | if ($value instanceof Cdata) { 386 | $this->writer->startElement($name); 387 | $this->writer->writeCdata((string) $value); 388 | $this->writer->endElement(); 389 | 390 | return true; 391 | } 392 | 393 | if (\is_bool($value)) { 394 | $value = $value ? 'true' : 'false'; 395 | } 396 | $this->writer->writeElement($name, $value); 397 | 398 | return true; 399 | } 400 | } 401 | -------------------------------------------------------------------------------- /src/Model/Category.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Bukashk0zzz\YmlGenerator\Model; 13 | 14 | /** 15 | * Class Category 16 | */ 17 | class Category 18 | { 19 | /** 20 | * @var int 21 | */ 22 | private $id; 23 | 24 | /** 25 | * @var int 26 | */ 27 | private $parentId; 28 | 29 | /** 30 | * @var string 31 | */ 32 | private $name; 33 | 34 | /** 35 | * @var array 36 | */ 37 | private $attributes = []; 38 | 39 | /** 40 | * @return int 41 | */ 42 | public function getId() 43 | { 44 | return $this->id; 45 | } 46 | 47 | /** 48 | * @param int $id 49 | * 50 | * @return Category 51 | */ 52 | public function setId($id) 53 | { 54 | $this->id = $id; 55 | 56 | return $this; 57 | } 58 | 59 | /** 60 | * @return int 61 | */ 62 | public function getParentId() 63 | { 64 | return $this->parentId; 65 | } 66 | 67 | /** 68 | * @param int $parentId 69 | * 70 | * @return Category 71 | */ 72 | public function setParentId($parentId) 73 | { 74 | $this->parentId = $parentId; 75 | 76 | return $this; 77 | } 78 | 79 | /** 80 | * @return string 81 | */ 82 | public function getName() 83 | { 84 | return $this->name; 85 | } 86 | 87 | /** 88 | * @param string $name 89 | * 90 | * @return Category 91 | */ 92 | public function setName($name) 93 | { 94 | $this->name = $name; 95 | 96 | return $this; 97 | } 98 | 99 | /** 100 | * @return array 101 | */ 102 | public function getAttributes() 103 | { 104 | return $this->attributes; 105 | } 106 | 107 | /** 108 | * Sets list of custom attributes (Array of arrays [['name' => ?, 'value' => ?]]) 109 | * 110 | * @param array $attributes 111 | * 112 | * @return Category 113 | */ 114 | public function setAttributes(array $attributes) 115 | { 116 | $this->attributes = $attributes; 117 | 118 | return $this; 119 | } 120 | 121 | /** 122 | * @param string $attributeName 123 | * @param mixed $value 124 | * 125 | * @return Category 126 | */ 127 | public function pushAttribute($attributeName, $value) 128 | { 129 | $this->attributes[] = ['name' => $attributeName, 'value' => $value]; 130 | 131 | return $this; 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /src/Model/Currency.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Bukashk0zzz\YmlGenerator\Model; 13 | 14 | /** 15 | * Class Currency 16 | */ 17 | class Currency 18 | { 19 | /** 20 | * @var string 21 | */ 22 | private $id; 23 | 24 | /** 25 | * @var string 26 | */ 27 | private $rate; 28 | 29 | /** 30 | * @return string 31 | */ 32 | public function getId() 33 | { 34 | return $this->id; 35 | } 36 | 37 | /** 38 | * @param string $id 39 | * 40 | * @return Currency 41 | */ 42 | public function setId($id) 43 | { 44 | $this->id = $id; 45 | 46 | return $this; 47 | } 48 | 49 | /** 50 | * @return string 51 | */ 52 | public function getRate() 53 | { 54 | return $this->rate; 55 | } 56 | 57 | /** 58 | * @param string $rate 59 | * 60 | * @return Currency 61 | */ 62 | public function setRate($rate) 63 | { 64 | $this->rate = $rate; 65 | 66 | return $this; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/Model/Delivery.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Bukashk0zzz\YmlGenerator\Model; 13 | 14 | /** 15 | * Class Delivery 16 | */ 17 | class Delivery 18 | { 19 | /** 20 | * @var int 21 | */ 22 | private $cost; 23 | 24 | /** 25 | * @var int 26 | */ 27 | private $days; 28 | 29 | /** 30 | * @var int 31 | */ 32 | private $orderBefore; 33 | 34 | /** 35 | * @return int 36 | */ 37 | public function getCost() 38 | { 39 | return $this->cost; 40 | } 41 | 42 | /** 43 | * @param int $cost 44 | * 45 | * @return Delivery 46 | */ 47 | public function setCost($cost) 48 | { 49 | $this->cost = $cost; 50 | 51 | return $this; 52 | } 53 | 54 | /** 55 | * @return int 56 | */ 57 | public function getDays() 58 | { 59 | return $this->days; 60 | } 61 | 62 | /** 63 | * @param int $days 64 | * 65 | * @return Delivery 66 | */ 67 | public function setDays($days) 68 | { 69 | $this->days = $days; 70 | 71 | return $this; 72 | } 73 | 74 | /** 75 | * @return int|null 76 | */ 77 | public function getOrderBefore() 78 | { 79 | return $this->orderBefore; 80 | } 81 | 82 | /** 83 | * @param int|null $orderBefore 84 | * 85 | * @return Delivery 86 | */ 87 | public function setOrderBefore($orderBefore) 88 | { 89 | $this->orderBefore = $orderBefore; 90 | 91 | return $this; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/Model/Offer/AbstractOffer.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Bukashk0zzz\YmlGenerator\Model\Offer; 13 | 14 | use Bukashk0zzz\YmlGenerator\Model\Delivery; 15 | 16 | /** 17 | * Abstract Class Offer 18 | */ 19 | abstract class AbstractOffer implements OfferInterface 20 | { 21 | /** 22 | * @var string 23 | */ 24 | private $id; 25 | 26 | /** 27 | * @var bool 28 | */ 29 | private $available; 30 | 31 | /** 32 | * @var string 33 | */ 34 | private $url; 35 | 36 | /** 37 | * @var float 38 | */ 39 | private $price; 40 | 41 | /** 42 | * @var float 43 | */ 44 | private $oldPrice; 45 | 46 | /** 47 | * @var float 48 | */ 49 | private $purchasePrice; 50 | 51 | /** 52 | * @var string 53 | */ 54 | private $currencyId; 55 | 56 | /** 57 | * @var int 58 | */ 59 | private $categoryId; 60 | 61 | /** 62 | * @var array 63 | */ 64 | private $categoriesId = []; 65 | 66 | /** 67 | * @var string 68 | */ 69 | private $name; 70 | 71 | /** 72 | * @var string 73 | */ 74 | private $marketCategory; 75 | 76 | /** 77 | * @var bool 78 | */ 79 | private $adult; 80 | 81 | /** 82 | * @var string 83 | */ 84 | private $salesNotes; 85 | 86 | /** 87 | * @var bool 88 | */ 89 | private $manufacturerWarranty; 90 | 91 | /** 92 | * @var bool 93 | */ 94 | private $pickup; 95 | 96 | /** 97 | * @var bool 98 | */ 99 | private $downloadable; 100 | 101 | /** 102 | * @var bool 103 | */ 104 | private $delivery; 105 | 106 | /** 107 | * @var float 108 | */ 109 | private $localDeliveryCost; 110 | 111 | /** 112 | * @var array 113 | */ 114 | private $deliveryOptions = []; 115 | 116 | /** 117 | * @var string 118 | */ 119 | private $description; 120 | 121 | /** 122 | * @var string 123 | */ 124 | private $countryOfOrigin; 125 | 126 | /** 127 | * @var string 128 | */ 129 | private $weight; 130 | 131 | /** 132 | * @var string 133 | */ 134 | private $dimensions; 135 | 136 | /** 137 | * @var int 138 | */ 139 | private $cpa; 140 | 141 | /** 142 | * @var string[] 143 | */ 144 | private $barcodes; 145 | 146 | /** 147 | * @var array 148 | */ 149 | private $pictures = []; 150 | 151 | /** 152 | * @var array 153 | */ 154 | private $params = []; 155 | 156 | /** 157 | * @var array 158 | */ 159 | private $outlets = []; 160 | 161 | /** 162 | * @var bool 163 | */ 164 | private $store; 165 | 166 | /** 167 | * @var bool 168 | */ 169 | private $autoDiscount; 170 | 171 | /** 172 | * Array of custom elements (element types are keys) of arrays of element values 173 | * There may be multiple elements of the same type 174 | * 175 | * @var array[] 176 | */ 177 | private $customElements; 178 | 179 | /** 180 | * @var OfferCondition 181 | */ 182 | private $condition; 183 | 184 | /** 185 | * @return array 186 | */ 187 | public function toArray() 188 | { 189 | return \array_merge($this->getHeaderOptions(), $this->getOptions(), $this->getFooterOptions()); 190 | } 191 | 192 | /** 193 | * @return string 194 | */ 195 | public function getId() 196 | { 197 | return $this->id; 198 | } 199 | 200 | /** 201 | * @param string $id 202 | * 203 | * @return $this 204 | */ 205 | public function setId($id) 206 | { 207 | $this->id = $id; 208 | 209 | return $this; 210 | } 211 | 212 | /** 213 | * @return bool 214 | */ 215 | public function isAvailable() 216 | { 217 | return $this->available; 218 | } 219 | 220 | /** 221 | * @param bool $available 222 | * 223 | * @return $this 224 | */ 225 | public function setAvailable($available) 226 | { 227 | $this->available = $available; 228 | 229 | return $this; 230 | } 231 | 232 | /** 233 | * @return string 234 | */ 235 | public function getUrl() 236 | { 237 | return $this->url; 238 | } 239 | 240 | /** 241 | * @param string $url 242 | * 243 | * @return $this 244 | */ 245 | public function setUrl($url) 246 | { 247 | $this->url = $url; 248 | 249 | return $this; 250 | } 251 | 252 | /** 253 | * @return float 254 | */ 255 | public function getPrice() 256 | { 257 | return $this->price; 258 | } 259 | 260 | /** 261 | * @param float $price 262 | * 263 | * @return $this 264 | */ 265 | public function setPrice($price) 266 | { 267 | $this->price = $price; 268 | 269 | return $this; 270 | } 271 | 272 | /** 273 | * @return float 274 | */ 275 | public function getOldPrice() 276 | { 277 | return $this->oldPrice; 278 | } 279 | 280 | /** 281 | * @param float $oldPrice 282 | * 283 | * @return $this 284 | */ 285 | public function setOldPrice($oldPrice) 286 | { 287 | $this->oldPrice = $oldPrice; 288 | 289 | return $this; 290 | } 291 | 292 | /** 293 | * @return float 294 | */ 295 | public function getPurchasePrice() 296 | { 297 | return $this->purchasePrice; 298 | } 299 | 300 | /** 301 | * @param float $purchasePrice 302 | * 303 | * @return $this 304 | */ 305 | public function setPurchasePrice($purchasePrice) 306 | { 307 | $this->purchasePrice = $purchasePrice; 308 | 309 | return $this; 310 | } 311 | 312 | /** 313 | * @return string 314 | */ 315 | public function getCurrencyId() 316 | { 317 | return $this->currencyId; 318 | } 319 | 320 | /** 321 | * @param string $currencyId 322 | * 323 | * @return $this 324 | */ 325 | public function setCurrencyId($currencyId) 326 | { 327 | $this->currencyId = $currencyId; 328 | 329 | return $this; 330 | } 331 | 332 | /** 333 | * @return int 334 | */ 335 | public function getCategoryId() 336 | { 337 | return $this->categoryId; 338 | } 339 | 340 | /** 341 | * @param int $categoryId 342 | * 343 | * @return $this 344 | */ 345 | public function setCategoryId($categoryId) 346 | { 347 | $this->categoryId = $categoryId; 348 | 349 | return $this; 350 | } 351 | 352 | /** 353 | * @return array 354 | */ 355 | public function getCategoriesId() 356 | { 357 | return $this->categoriesId; 358 | } 359 | 360 | /** 361 | * @param array $categoriesId 362 | * 363 | * @return $this 364 | */ 365 | public function setCategoriesId(array $categoriesId) 366 | { 367 | $this->categoriesId = $categoriesId; 368 | 369 | return $this; 370 | } 371 | 372 | /** 373 | * @return string 374 | */ 375 | public function getName() 376 | { 377 | return $this->name; 378 | } 379 | 380 | /** 381 | * @param string $name 382 | * 383 | * @return $this 384 | */ 385 | public function setName($name) 386 | { 387 | $this->name = $name; 388 | 389 | return $this; 390 | } 391 | 392 | /** 393 | * @return string 394 | */ 395 | public function getMarketCategory() 396 | { 397 | return $this->marketCategory; 398 | } 399 | 400 | /** 401 | * @param string $marketCategory 402 | * 403 | * @return $this 404 | */ 405 | public function setMarketCategory($marketCategory) 406 | { 407 | $this->marketCategory = $marketCategory; 408 | 409 | return $this; 410 | } 411 | 412 | /** 413 | * @return bool 414 | */ 415 | public function isAdult() 416 | { 417 | return $this->adult; 418 | } 419 | 420 | /** 421 | * @param bool $adult 422 | * 423 | * @return $this 424 | */ 425 | public function setAdult($adult) 426 | { 427 | $this->adult = $adult; 428 | 429 | return $this; 430 | } 431 | 432 | /** 433 | * @return string 434 | */ 435 | public function getSalesNotes() 436 | { 437 | return $this->salesNotes; 438 | } 439 | 440 | /** 441 | * @param string $salesNotes 442 | * 443 | * @return $this 444 | */ 445 | public function setSalesNotes($salesNotes) 446 | { 447 | $this->salesNotes = $salesNotes; 448 | 449 | return $this; 450 | } 451 | 452 | /** 453 | * @return bool 454 | */ 455 | public function isManufacturerWarranty() 456 | { 457 | return $this->manufacturerWarranty; 458 | } 459 | 460 | /** 461 | * @param bool $manufacturerWarranty 462 | * 463 | * @return $this 464 | */ 465 | public function setManufacturerWarranty($manufacturerWarranty) 466 | { 467 | $this->manufacturerWarranty = $manufacturerWarranty; 468 | 469 | return $this; 470 | } 471 | 472 | /** 473 | * @return bool 474 | */ 475 | public function isPickup() 476 | { 477 | return $this->pickup; 478 | } 479 | 480 | /** 481 | * @param bool $pickup 482 | * 483 | * @return $this 484 | */ 485 | public function setPickup($pickup) 486 | { 487 | $this->pickup = $pickup; 488 | 489 | return $this; 490 | } 491 | 492 | /** 493 | * @return bool 494 | */ 495 | public function isDownloadable() 496 | { 497 | return $this->downloadable; 498 | } 499 | 500 | /** 501 | * @param bool $downloadable 502 | * 503 | * @return $this 504 | */ 505 | public function setDownloadable($downloadable) 506 | { 507 | $this->downloadable = $downloadable; 508 | 509 | return $this; 510 | } 511 | 512 | /** 513 | * @return bool 514 | */ 515 | public function isDelivery() 516 | { 517 | return $this->delivery; 518 | } 519 | 520 | /** 521 | * @param bool $delivery 522 | * 523 | * @return $this 524 | */ 525 | public function setDelivery($delivery) 526 | { 527 | $this->delivery = $delivery; 528 | 529 | return $this; 530 | } 531 | 532 | /** 533 | * @return array 534 | */ 535 | public function getDeliveryOptions() 536 | { 537 | return $this->deliveryOptions; 538 | } 539 | 540 | /** 541 | * @param Delivery $option 542 | * 543 | * @return $this 544 | */ 545 | public function addDeliveryOption(Delivery $option) 546 | { 547 | $this->deliveryOptions[] = $option; 548 | 549 | return $this; 550 | } 551 | 552 | /** 553 | * @param bool $store 554 | * 555 | * @return $this 556 | */ 557 | public function setStore($store) 558 | { 559 | $this->store = $store; 560 | 561 | return $this; 562 | } 563 | 564 | /** 565 | * @return bool 566 | */ 567 | public function isStore() 568 | { 569 | return $this->store; 570 | } 571 | 572 | /** 573 | * @return float 574 | */ 575 | public function getLocalDeliveryCost() 576 | { 577 | return $this->localDeliveryCost; 578 | } 579 | 580 | /** 581 | * @param float $localDeliveryCost 582 | * 583 | * @return $this 584 | */ 585 | public function setLocalDeliveryCost($localDeliveryCost) 586 | { 587 | $this->localDeliveryCost = $localDeliveryCost; 588 | 589 | return $this; 590 | } 591 | 592 | /** 593 | * @return string 594 | */ 595 | public function getDescription() 596 | { 597 | return $this->description; 598 | } 599 | 600 | /** 601 | * @param string $description 602 | * 603 | * @return $this 604 | */ 605 | public function setDescription($description) 606 | { 607 | $this->description = $description; 608 | 609 | return $this; 610 | } 611 | 612 | /** 613 | * @return string 614 | */ 615 | public function getCountryOfOrigin() 616 | { 617 | return $this->countryOfOrigin; 618 | } 619 | 620 | /** 621 | * @param string $countryOfOrigin 622 | * 623 | * @return $this 624 | */ 625 | public function setCountryOfOrigin($countryOfOrigin) 626 | { 627 | $this->countryOfOrigin = $countryOfOrigin; 628 | 629 | return $this; 630 | } 631 | 632 | /** 633 | * @return string 634 | */ 635 | public function getWeight() 636 | { 637 | return $this->weight; 638 | } 639 | 640 | /** 641 | * @param string $weight 642 | * 643 | * @return $this 644 | */ 645 | public function setWeight($weight) 646 | { 647 | $this->weight = $weight; 648 | 649 | return $this; 650 | } 651 | 652 | /** 653 | * @return string 654 | */ 655 | public function getDimensions() 656 | { 657 | return $this->dimensions; 658 | } 659 | 660 | /** 661 | * @param float $length 662 | * @param float $width 663 | * @param float $height 664 | * 665 | * @return $this 666 | */ 667 | public function setDimensions($length, $width, $height) 668 | { 669 | $dimensions = [ 670 | \round((float) $length, 3), 671 | \round((float) $width, 3), 672 | \round((float) $height, 3), 673 | ]; 674 | 675 | $this->dimensions = \implode('/', $dimensions); 676 | 677 | return $this; 678 | } 679 | 680 | /** 681 | * @return int 682 | */ 683 | public function getCpa() 684 | { 685 | return $this->cpa; 686 | } 687 | 688 | /** 689 | * @param int $cpa 690 | * 691 | * @return $this 692 | */ 693 | public function setCpa($cpa) 694 | { 695 | $this->cpa = $cpa; 696 | 697 | return $this; 698 | } 699 | 700 | /** 701 | * @return array 702 | */ 703 | public function getParams() 704 | { 705 | return $this->params; 706 | } 707 | 708 | /** 709 | * @param OfferParam $param 710 | * 711 | * @return $this 712 | */ 713 | public function addParam(OfferParam $param) 714 | { 715 | $this->params[] = $param; 716 | 717 | return $this; 718 | } 719 | 720 | /** 721 | * @return array 722 | */ 723 | public function getOutlets() 724 | { 725 | return $this->outlets; 726 | } 727 | 728 | /** 729 | * @param OfferOutlet $outlet 730 | * 731 | * @return $this 732 | */ 733 | public function addOutlet(OfferOutlet $outlet) 734 | { 735 | $this->outlets[] = $outlet; 736 | 737 | return $this; 738 | } 739 | 740 | /** 741 | * Add picture 742 | * 743 | * @param string $url 744 | * 745 | * @return $this 746 | */ 747 | public function addPicture($url) 748 | { 749 | if (\count($this->pictures) < 10) { 750 | $this->pictures[] = $url; 751 | } 752 | 753 | return $this; 754 | } 755 | 756 | /** 757 | * Set pictures 758 | * 759 | * @param array $pictures 760 | * 761 | * @return $this 762 | */ 763 | public function setPictures(array $pictures) 764 | { 765 | $this->pictures = $pictures; 766 | 767 | return $this; 768 | } 769 | 770 | /** 771 | * Get picture list 772 | * 773 | * @return array 774 | */ 775 | public function getPictures() 776 | { 777 | return $this->pictures; 778 | } 779 | 780 | /** 781 | * Get list of barcodes of the offer 782 | * 783 | * @return string[] 784 | */ 785 | public function getBarcodes() 786 | { 787 | return $this->barcodes; 788 | } 789 | 790 | /** 791 | * Set list of barcodes for that offer 792 | * 793 | * @param string[] $barcodes 794 | * 795 | * @return $this 796 | */ 797 | public function setBarcodes(array $barcodes = []) 798 | { 799 | $this->barcodes = $barcodes; 800 | 801 | return $this; 802 | } 803 | 804 | /** 805 | * Add one barcode to the collection of barcodes of this offer 806 | * 807 | * @param string $barcode 808 | * 809 | * @return $this 810 | */ 811 | public function addBarcode($barcode) 812 | { 813 | $this->barcodes[] = $barcode; 814 | 815 | return $this; 816 | } 817 | 818 | /** 819 | * Sets list of custom elements 820 | * 821 | * @param array $customElements Array (keys are element types) of arrays (element values) 822 | * 823 | * @return $this 824 | */ 825 | public function setCustomElements(array $customElements = []) 826 | { 827 | $this->customElements = $customElements; 828 | 829 | return $this; 830 | } 831 | 832 | /** 833 | * Add a custom element with given type and value 834 | * Multiple elements of the same type are supported 835 | * 836 | * @param string $elementType 837 | * @param mixed $value 838 | * 839 | * @return $this 840 | */ 841 | public function addCustomElement($elementType, $value) 842 | { 843 | if ($value !== null) { 844 | // Add value to the list of values of the given element type creating array when needed 845 | $this->customElements[$elementType][] = $value; 846 | } 847 | 848 | return $this; 849 | } 850 | 851 | /** 852 | * Returns a list of custom elements 853 | * Always returns an array even if no custom elements were added 854 | * 855 | * @return array 856 | */ 857 | public function getCustomElements() 858 | { 859 | return $this->customElements ?: []; 860 | } 861 | 862 | /** 863 | * Returns a list of values for the specified custom element type 864 | * Always returns an array 865 | * 866 | * @param string $elementType 867 | * 868 | * @return array 869 | */ 870 | public function getCustomElementByType($elementType) 871 | { 872 | // TODO: Use ?? operator when support for PHP 5.6 is no longer needed 873 | if (isset($this->customElements[$elementType])) { 874 | return $this->customElements[$elementType]; 875 | } 876 | 877 | return []; 878 | } 879 | 880 | /** 881 | * @return OfferCondition 882 | */ 883 | public function getCondition() 884 | { 885 | return $this->condition; 886 | } 887 | 888 | /** 889 | * @param OfferCondition $condition 890 | * 891 | * @return $this 892 | */ 893 | public function addCondition(OfferCondition $condition) 894 | { 895 | $this->condition = $condition; 896 | 897 | return $this; 898 | } 899 | 900 | /** 901 | * @return bool 902 | */ 903 | public function getAutoDiscount() 904 | { 905 | return $this->autoDiscount; 906 | } 907 | 908 | /** 909 | * @param bool $autoDiscount 910 | * 911 | * @return $this 912 | */ 913 | public function setAutoDiscount($autoDiscount) 914 | { 915 | $this->autoDiscount = $autoDiscount; 916 | 917 | return $this; 918 | } 919 | 920 | /** 921 | * @return array 922 | */ 923 | abstract protected function getOptions(); 924 | 925 | /** 926 | * @return array 927 | */ 928 | private function getHeaderOptions() 929 | { 930 | return [ 931 | 'url' => $this->getUrl(), 932 | 'price' => $this->getPrice(), 933 | 'oldprice' => $this->getOldPrice(), 934 | 'purchase_price' => $this->getPurchasePrice(), 935 | 'currencyId' => $this->getCurrencyId(), 936 | 'categoryId' => \array_merge( 937 | [$this->getCategoryId()], 938 | $this->getCategoriesId() 939 | ), 940 | 'market_category' => $this->getMarketCategory(), 941 | 'picture' => $this->getPictures(), 942 | 'pickup' => $this->isPickup(), 943 | 'store' => $this->isStore(), 944 | 'delivery' => $this->isDelivery(), 945 | 'local_delivery_cost' => $this->getLocalDeliveryCost(), 946 | 'weight' => $this->getWeight(), 947 | 'dimensions' => $this->getDimensions(), 948 | 'name' => $this->getName(), 949 | 'enable_auto_discounts' => $this->getAutoDiscount(), 950 | ] + $this->getCustomElements(); 951 | } 952 | 953 | /** 954 | * @return array 955 | */ 956 | private function getFooterOptions() 957 | { 958 | return [ 959 | 'description' => $this->getDescription(), 960 | 'sales_notes' => $this->getSalesNotes(), 961 | 'manufacturer_warranty' => $this->isManufacturerWarranty(), 962 | 'country_of_origin' => $this->getCountryOfOrigin(), 963 | 'downloadable' => $this->isDownloadable(), 964 | 'adult' => $this->isAdult(), 965 | 'cpa' => $this->getCpa(), 966 | 'barcode' => $this->getBarcodes(), 967 | ]; 968 | } 969 | } 970 | -------------------------------------------------------------------------------- /src/Model/Offer/OfferArtistTitle.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Bukashk0zzz\YmlGenerator\Model\Offer; 13 | 14 | /** 15 | * Class OfferArtistTitle 16 | */ 17 | class OfferArtistTitle extends AbstractOffer 18 | { 19 | /** 20 | * @var string 21 | */ 22 | private $artist; 23 | 24 | /** 25 | * @var string 26 | */ 27 | private $title; 28 | 29 | /** 30 | * @var int 31 | */ 32 | private $year; 33 | 34 | /** 35 | * @var string 36 | */ 37 | private $media; 38 | 39 | /** 40 | * @return string 41 | */ 42 | public function getType() 43 | { 44 | return 'artist.title'; 45 | } 46 | 47 | /** 48 | * @return string 49 | */ 50 | public function getArtist() 51 | { 52 | return $this->artist; 53 | } 54 | 55 | /** 56 | * @param string $artist 57 | * 58 | * @return OfferArtistTitle 59 | */ 60 | public function setArtist($artist) 61 | { 62 | $this->artist = $artist; 63 | 64 | return $this; 65 | } 66 | 67 | /** 68 | * @return string 69 | */ 70 | public function getTitle() 71 | { 72 | return $this->title; 73 | } 74 | 75 | /** 76 | * @param string $title 77 | * 78 | * @return OfferArtistTitle 79 | */ 80 | public function setTitle($title) 81 | { 82 | $this->title = $title; 83 | 84 | return $this; 85 | } 86 | 87 | /** 88 | * @return int 89 | */ 90 | public function getYear() 91 | { 92 | return $this->year; 93 | } 94 | 95 | /** 96 | * @param int $year 97 | * 98 | * @return OfferArtistTitle 99 | */ 100 | public function setYear($year) 101 | { 102 | $this->year = $year; 103 | 104 | return $this; 105 | } 106 | 107 | /** 108 | * @return string 109 | */ 110 | public function getMedia() 111 | { 112 | return $this->media; 113 | } 114 | 115 | /** 116 | * @param string $media 117 | * 118 | * @return OfferArtistTitle 119 | */ 120 | public function setMedia($media) 121 | { 122 | $this->media = $media; 123 | 124 | return $this; 125 | } 126 | 127 | /** 128 | * @return array 129 | */ 130 | protected function getOptions() 131 | { 132 | return [ 133 | 'artist' => $this->getArtist(), 134 | 'title' => $this->getTitle(), 135 | 'year' => $this->getYear(), 136 | 'media' => $this->getMedia(), 137 | ]; 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /src/Model/Offer/OfferAudiobook.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Bukashk0zzz\YmlGenerator\Model\Offer; 13 | 14 | /** 15 | * Class OfferAudiobook 16 | */ 17 | class OfferAudiobook extends AbstractOffer 18 | { 19 | use OfferBookTrait; 20 | 21 | /** 22 | * @var string 23 | */ 24 | private $performedBy; 25 | 26 | /** 27 | * @var string 28 | */ 29 | private $performanceType; 30 | 31 | /** 32 | * @var string 33 | */ 34 | private $format; 35 | 36 | /** 37 | * @var string 38 | */ 39 | private $storage; 40 | 41 | /** 42 | * @var string 43 | */ 44 | private $recordingLength; 45 | 46 | /** 47 | * @return string 48 | */ 49 | public function getType() 50 | { 51 | return 'audiobook'; 52 | } 53 | 54 | /** 55 | * @return string 56 | */ 57 | public function getPerformedBy() 58 | { 59 | return $this->performedBy; 60 | } 61 | 62 | /** 63 | * @param string $performedBy 64 | * 65 | * @return $this 66 | */ 67 | public function setPerformedBy($performedBy) 68 | { 69 | $this->performedBy = $performedBy; 70 | 71 | return $this; 72 | } 73 | 74 | /** 75 | * @return string 76 | */ 77 | public function getPerformanceType() 78 | { 79 | return $this->performanceType; 80 | } 81 | 82 | /** 83 | * @param string $performanceType 84 | * 85 | * @return $this 86 | */ 87 | public function setPerformanceType($performanceType) 88 | { 89 | $this->performanceType = $performanceType; 90 | 91 | return $this; 92 | } 93 | 94 | /** 95 | * @return string 96 | */ 97 | public function getFormat() 98 | { 99 | return $this->format; 100 | } 101 | 102 | /** 103 | * @param string $format 104 | * 105 | * @return $this 106 | */ 107 | public function setFormat($format) 108 | { 109 | $this->format = $format; 110 | 111 | return $this; 112 | } 113 | 114 | /** 115 | * @return string 116 | */ 117 | public function getStorage() 118 | { 119 | return $this->storage; 120 | } 121 | 122 | /** 123 | * @param string $storage 124 | * 125 | * @return $this 126 | */ 127 | public function setStorage($storage) 128 | { 129 | $this->storage = $storage; 130 | 131 | return $this; 132 | } 133 | 134 | /** 135 | * @return string 136 | */ 137 | public function getRecordingLength() 138 | { 139 | return $this->recordingLength; 140 | } 141 | 142 | /** 143 | * @param string $recordingLength 144 | * 145 | * @return $this 146 | */ 147 | public function setRecordingLength($recordingLength) 148 | { 149 | $this->recordingLength = $recordingLength; 150 | 151 | return $this; 152 | } 153 | 154 | /** 155 | * @return array 156 | */ 157 | protected function getOptions() 158 | { 159 | return [ 160 | 'author' => $this->getAuthor(), 161 | 'name' => $this->getName(), 162 | 'publisher' => $this->getPublisher(), 163 | 'series' => $this->getSeries(), 164 | 'year' => $this->getYear(), 165 | 'ISBN' => $this->getISBN(), 166 | 'volume' => $this->getVolume(), 167 | 'part' => $this->getPart(), 168 | 'language' => $this->getLanguage(), 169 | 'table_of_contents' => $this->getTableOfContents(), 170 | 'performed_by' => $this->getPerformedBy(), 171 | 'performance_type' => $this->getPerformanceType(), 172 | 'storage' => $this->getStorage(), 173 | 'format' => $this->getFormat(), 174 | 'recording_length' => $this->getRecordingLength(), 175 | ]; 176 | } 177 | } 178 | -------------------------------------------------------------------------------- /src/Model/Offer/OfferBook.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Bukashk0zzz\YmlGenerator\Model\Offer; 13 | 14 | /** 15 | * Class OfferBook 16 | */ 17 | class OfferBook extends AbstractOffer 18 | { 19 | use OfferBookTrait; 20 | 21 | /** 22 | * @var string 23 | */ 24 | private $binding; 25 | 26 | /** 27 | * @var int 28 | */ 29 | private $pageExtent; 30 | 31 | /** 32 | * @return string 33 | */ 34 | public function getType() 35 | { 36 | return 'book'; 37 | } 38 | 39 | /** 40 | * @return string 41 | */ 42 | public function getBinding() 43 | { 44 | return $this->binding; 45 | } 46 | 47 | /** 48 | * @param string $binding 49 | * 50 | * @return $this 51 | */ 52 | public function setBinding($binding) 53 | { 54 | $this->binding = $binding; 55 | 56 | return $this; 57 | } 58 | 59 | /** 60 | * @return int 61 | */ 62 | public function getPageExtent() 63 | { 64 | return $this->pageExtent; 65 | } 66 | 67 | /** 68 | * @param int $pageExtent 69 | * 70 | * @return $this 71 | */ 72 | public function setPageExtent($pageExtent) 73 | { 74 | $this->pageExtent = $pageExtent; 75 | 76 | return $this; 77 | } 78 | 79 | /** 80 | * @return array 81 | */ 82 | protected function getOptions() 83 | { 84 | return [ 85 | 'author' => $this->getAuthor(), 86 | 'name' => $this->getName(), 87 | 'publisher' => $this->getPublisher(), 88 | 'series' => $this->getSeries(), 89 | 'year' => $this->getYear(), 90 | 'ISBN' => $this->getISBN(), 91 | 'volume' => $this->getVolume(), 92 | 'part' => $this->getPart(), 93 | 'language' => $this->getLanguage(), 94 | 'binding' => $this->getBinding(), 95 | 'page_extent' => $this->getPageExtent(), 96 | 'table_of_contents' => $this->getTableOfContents(), 97 | ]; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/Model/Offer/OfferBookTrait.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Bukashk0zzz\YmlGenerator\Model\Offer; 13 | 14 | /** 15 | * Trait OfferBook 16 | */ 17 | trait OfferBookTrait 18 | { 19 | /** 20 | * @var string 21 | */ 22 | private $author; 23 | 24 | /** 25 | * @var string 26 | */ 27 | private $name; 28 | 29 | /** 30 | * @var string 31 | */ 32 | private $publisher; 33 | 34 | /** 35 | * @var string 36 | */ 37 | private $series; 38 | 39 | /** 40 | * @var int 41 | */ 42 | private $year; 43 | 44 | /** 45 | * @var string 46 | */ 47 | private $ISBN; 48 | 49 | /** 50 | * @var int 51 | */ 52 | private $volume; 53 | 54 | /** 55 | * @var int 56 | */ 57 | private $part; 58 | 59 | /** 60 | * @var string 61 | */ 62 | private $language; 63 | 64 | /** 65 | * @var string 66 | */ 67 | private $tableOfContents; 68 | 69 | /** 70 | * @return string 71 | */ 72 | public function getAuthor() 73 | { 74 | return $this->author; 75 | } 76 | 77 | /** 78 | * @param string $author 79 | * 80 | * @return $this 81 | */ 82 | public function setAuthor($author) 83 | { 84 | $this->author = $author; 85 | 86 | return $this; 87 | } 88 | 89 | /** 90 | * @return string 91 | */ 92 | public function getName() 93 | { 94 | return $this->name; 95 | } 96 | 97 | /** 98 | * @param string $name 99 | * 100 | * @return $this 101 | */ 102 | public function setName($name) 103 | { 104 | $this->name = $name; 105 | 106 | return $this; 107 | } 108 | 109 | /** 110 | * @return string 111 | */ 112 | public function getPublisher() 113 | { 114 | return $this->publisher; 115 | } 116 | 117 | /** 118 | * @param string $publisher 119 | * 120 | * @return $this 121 | */ 122 | public function setPublisher($publisher) 123 | { 124 | $this->publisher = $publisher; 125 | 126 | return $this; 127 | } 128 | 129 | /** 130 | * @return string 131 | */ 132 | public function getSeries() 133 | { 134 | return $this->series; 135 | } 136 | 137 | /** 138 | * @param string $series 139 | * 140 | * @return $this 141 | */ 142 | public function setSeries($series) 143 | { 144 | $this->series = $series; 145 | 146 | return $this; 147 | } 148 | 149 | /** 150 | * @return int 151 | */ 152 | public function getYear() 153 | { 154 | return $this->year; 155 | } 156 | 157 | /** 158 | * @param int $year 159 | * 160 | * @return $this 161 | */ 162 | public function setYear($year) 163 | { 164 | $this->year = $year; 165 | 166 | return $this; 167 | } 168 | 169 | /** 170 | * @return string 171 | */ 172 | public function getISBN() 173 | { 174 | return $this->ISBN; 175 | } 176 | 177 | /** 178 | * @param string $ISBN 179 | * 180 | * @return $this 181 | */ 182 | public function setISBN($ISBN) 183 | { 184 | $this->ISBN = $ISBN; 185 | 186 | return $this; 187 | } 188 | 189 | /** 190 | * @return int 191 | */ 192 | public function getVolume() 193 | { 194 | return $this->volume; 195 | } 196 | 197 | /** 198 | * @param int $volume 199 | * 200 | * @return $this 201 | */ 202 | public function setVolume($volume) 203 | { 204 | $this->volume = $volume; 205 | 206 | return $this; 207 | } 208 | 209 | /** 210 | * @return int 211 | */ 212 | public function getPart() 213 | { 214 | return $this->part; 215 | } 216 | 217 | /** 218 | * @param int $part 219 | * 220 | * @return $this 221 | */ 222 | public function setPart($part) 223 | { 224 | $this->part = $part; 225 | 226 | return $this; 227 | } 228 | 229 | /** 230 | * @return string 231 | */ 232 | public function getLanguage() 233 | { 234 | return $this->language; 235 | } 236 | 237 | /** 238 | * @param string $language 239 | * 240 | * @return $this 241 | */ 242 | public function setLanguage($language) 243 | { 244 | $this->language = $language; 245 | 246 | return $this; 247 | } 248 | 249 | /** 250 | * @return string 251 | */ 252 | public function getTableOfContents() 253 | { 254 | return $this->tableOfContents; 255 | } 256 | 257 | /** 258 | * @param string $tableOfContents 259 | * 260 | * @return $this 261 | */ 262 | public function setTableOfContents($tableOfContents) 263 | { 264 | $this->tableOfContents = $tableOfContents; 265 | 266 | return $this; 267 | } 268 | } 269 | -------------------------------------------------------------------------------- /src/Model/Offer/OfferCondition.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Bukashk0zzz\YmlGenerator\Model\Offer; 13 | 14 | /** 15 | * Class OfferCondition 16 | */ 17 | class OfferCondition 18 | { 19 | /** 20 | * @var string 21 | */ 22 | private $type; 23 | 24 | /** 25 | * @var string 26 | */ 27 | private $reasonText; 28 | 29 | /** 30 | * @return string 31 | */ 32 | public function getReasonText() 33 | { 34 | return $this->reasonText; 35 | } 36 | 37 | /** 38 | * @return string 39 | */ 40 | public function getType() 41 | { 42 | return $this->type; 43 | } 44 | 45 | /** 46 | * Description text for the reason for markdowns 47 | * 48 | * @param string $reasonText 49 | * 50 | * @return $this 51 | */ 52 | public function setReasonText($reasonText) 53 | { 54 | $this->reasonText = $reasonText; 55 | 56 | return $this; 57 | } 58 | 59 | /** 60 | * Set product condition 61 | * 62 | * @param string $type 63 | * 64 | * @return $this 65 | */ 66 | public function setType($type) 67 | { 68 | $this->type = $type; 69 | 70 | return $this; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/Model/Offer/OfferCustom.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Bukashk0zzz\YmlGenerator\Model\Offer; 13 | 14 | /** 15 | * Class OfferCustom 16 | */ 17 | class OfferCustom extends AbstractOffer implements OfferGroupAwareInterface 18 | { 19 | use OfferGroupTrait; 20 | 21 | /** 22 | * @var string 23 | */ 24 | private $typePrefix; 25 | 26 | /** 27 | * @var string 28 | */ 29 | private $vendor; 30 | 31 | /** 32 | * @var string 33 | */ 34 | private $vendorCode; 35 | 36 | /** 37 | * @var string 38 | */ 39 | private $model; 40 | 41 | /** 42 | * @return string 43 | */ 44 | public function getType() 45 | { 46 | return 'vendor.model'; 47 | } 48 | 49 | /** 50 | * @return string 51 | */ 52 | public function getTypePrefix() 53 | { 54 | return $this->typePrefix; 55 | } 56 | 57 | /** 58 | * @param string $typePrefix 59 | * 60 | * @return $this 61 | */ 62 | public function setTypePrefix($typePrefix) 63 | { 64 | $this->typePrefix = $typePrefix; 65 | 66 | return $this; 67 | } 68 | 69 | /** 70 | * @return string 71 | */ 72 | public function getModel() 73 | { 74 | return $this->model; 75 | } 76 | 77 | /** 78 | * @param string $model 79 | * 80 | * @return $this 81 | */ 82 | public function setModel($model) 83 | { 84 | $this->model = $model; 85 | 86 | return $this; 87 | } 88 | 89 | /** 90 | * @return string 91 | */ 92 | public function getVendor() 93 | { 94 | return $this->vendor; 95 | } 96 | 97 | /** 98 | * @param string $vendor 99 | * 100 | * @return $this 101 | */ 102 | public function setVendor($vendor) 103 | { 104 | $this->vendor = $vendor; 105 | 106 | return $this; 107 | } 108 | 109 | /** 110 | * @return string 111 | */ 112 | public function getVendorCode() 113 | { 114 | return $this->vendorCode; 115 | } 116 | 117 | /** 118 | * @param string $vendorCode 119 | * 120 | * @return $this 121 | */ 122 | public function setVendorCode($vendorCode) 123 | { 124 | $this->vendorCode = $vendorCode; 125 | 126 | return $this; 127 | } 128 | 129 | /** 130 | * @return array 131 | */ 132 | protected function getOptions() 133 | { 134 | return [ 135 | 'typePrefix' => $this->getTypePrefix(), 136 | 'vendor' => $this->getVendor(), 137 | 'vendorCode' => $this->getVendorCode(), 138 | 'model' => $this->getModel(), 139 | ]; 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /src/Model/Offer/OfferEventTicket.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Bukashk0zzz\YmlGenerator\Model\Offer; 13 | 14 | /** 15 | * Class OfferEventTicket 16 | */ 17 | class OfferEventTicket extends AbstractOffer 18 | { 19 | /** 20 | * @var string 21 | */ 22 | private $name; 23 | 24 | /** 25 | * @var string 26 | */ 27 | private $place; 28 | 29 | /** 30 | * @var string 31 | */ 32 | private $date; 33 | 34 | /** 35 | * @var int 36 | */ 37 | private $premiere; 38 | 39 | /** 40 | * @var int 41 | */ 42 | private $kids; 43 | 44 | /** 45 | * @return string 46 | */ 47 | public function getType() 48 | { 49 | return 'event-ticket'; 50 | } 51 | 52 | /** 53 | * @return string 54 | */ 55 | public function getName() 56 | { 57 | return $this->name; 58 | } 59 | 60 | /** 61 | * @param string $name 62 | * 63 | * @return $this 64 | */ 65 | public function setName($name) 66 | { 67 | $this->name = $name; 68 | 69 | return $this; 70 | } 71 | 72 | /** 73 | * @return string 74 | */ 75 | public function getPlace() 76 | { 77 | return $this->place; 78 | } 79 | 80 | /** 81 | * @param string $place 82 | * 83 | * @return $this 84 | */ 85 | public function setPlace($place) 86 | { 87 | $this->place = $place; 88 | 89 | return $this; 90 | } 91 | 92 | /** 93 | * @return string 94 | */ 95 | public function getDate() 96 | { 97 | return $this->date; 98 | } 99 | 100 | /** 101 | * @param string $date 102 | * 103 | * @return $this 104 | */ 105 | public function setDate($date) 106 | { 107 | $this->date = $date; 108 | 109 | return $this; 110 | } 111 | 112 | /** 113 | * @return int 114 | */ 115 | public function getPremiere() 116 | { 117 | return $this->premiere; 118 | } 119 | 120 | /** 121 | * @param int $premiere 122 | * 123 | * @return $this 124 | */ 125 | public function setPremiere($premiere) 126 | { 127 | $this->premiere = $premiere; 128 | 129 | return $this; 130 | } 131 | 132 | /** 133 | * @return int 134 | */ 135 | public function getKids() 136 | { 137 | return $this->kids; 138 | } 139 | 140 | /** 141 | * @param int $kids 142 | * 143 | * @return $this 144 | */ 145 | public function setKids($kids) 146 | { 147 | $this->kids = $kids; 148 | 149 | return $this; 150 | } 151 | 152 | /** 153 | * @return array 154 | */ 155 | protected function getOptions() 156 | { 157 | return [ 158 | 'name' => $this->getName(), 159 | 'place' => $this->getPlace(), 160 | 'date' => $this->getDate(), 161 | 'is_premiere' => $this->getPremiere(), 162 | 'is_kids' => $this->getKids(), 163 | ]; 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /src/Model/Offer/OfferGroupAwareInterface.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Bukashk0zzz\YmlGenerator\Model\Offer; 13 | 14 | /** 15 | * Interface OfferGroupAwareInterface 16 | */ 17 | interface OfferGroupAwareInterface 18 | { 19 | /** 20 | * Get groupId 21 | * 22 | * @return int 23 | */ 24 | public function getGroupId(); 25 | 26 | /** 27 | * Set groupId 28 | * 29 | * @param int $groupId 30 | * 31 | * @return $this 32 | */ 33 | public function setGroupId($groupId); 34 | } 35 | -------------------------------------------------------------------------------- /src/Model/Offer/OfferGroupTrait.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Bukashk0zzz\YmlGenerator\Model\Offer; 13 | 14 | /** 15 | * Trait OfferGroupTrait 16 | */ 17 | trait OfferGroupTrait 18 | { 19 | /** 20 | * @var int 21 | */ 22 | protected $groupId; 23 | 24 | /** 25 | * Get groupId 26 | * 27 | * @return int|null 28 | */ 29 | public function getGroupId() 30 | { 31 | return $this->groupId; 32 | } 33 | 34 | /** 35 | * Set groupId 36 | * 37 | * @param int $groupId 38 | * 39 | * @return $this 40 | */ 41 | public function setGroupId($groupId) 42 | { 43 | $this->groupId = $groupId; 44 | 45 | return $this; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Model/Offer/OfferInterface.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Bukashk0zzz\YmlGenerator\Model\Offer; 13 | 14 | /** 15 | * Interface Offer 16 | */ 17 | interface OfferInterface 18 | { 19 | /** 20 | * @return string 21 | */ 22 | public function getId(); 23 | 24 | /** 25 | * @return string 26 | */ 27 | public function getType(); 28 | 29 | /** 30 | * @return bool 31 | */ 32 | public function isAvailable(); 33 | 34 | /** 35 | * @return array 36 | */ 37 | public function getDeliveryOptions(); 38 | 39 | /** 40 | * @return array 41 | */ 42 | public function getParams(); 43 | 44 | /** 45 | * @return array 46 | */ 47 | public function getOutlets(); 48 | 49 | /** 50 | * @return object 51 | */ 52 | public function getCondition(); 53 | 54 | /** 55 | * @return array 56 | */ 57 | public function toArray(); 58 | } 59 | -------------------------------------------------------------------------------- /src/Model/Offer/OfferOutlet.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Bukashk0zzz\YmlGenerator\Model\Offer; 13 | 14 | /** 15 | * Class OfferOutlet 16 | */ 17 | class OfferOutlet 18 | { 19 | /** 20 | * @var string 21 | */ 22 | private $id; 23 | 24 | /** 25 | * @var string 26 | */ 27 | private $inStock; 28 | 29 | /** 30 | * @return string 31 | */ 32 | public function getId() 33 | { 34 | return $this->id; 35 | } 36 | 37 | /** 38 | * @param string $id 39 | * 40 | * @return OfferOutlet 41 | */ 42 | public function setId($id) 43 | { 44 | $this->id = $id; 45 | 46 | return $this; 47 | } 48 | 49 | /** 50 | * @return string 51 | */ 52 | public function getInStock() 53 | { 54 | return $this->inStock; 55 | } 56 | 57 | /** 58 | * @param string $inStock 59 | * 60 | * @return OfferOutlet 61 | */ 62 | public function setInStock($inStock) 63 | { 64 | $this->inStock = $inStock; 65 | 66 | return $this; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/Model/Offer/OfferParam.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Bukashk0zzz\YmlGenerator\Model\Offer; 13 | 14 | /** 15 | * Class OfferParam 16 | */ 17 | class OfferParam 18 | { 19 | /** 20 | * @var string 21 | */ 22 | private $name; 23 | 24 | /** 25 | * @var string 26 | */ 27 | private $unit; 28 | 29 | /** 30 | * @var string 31 | */ 32 | private $value; 33 | 34 | /** 35 | * @return string 36 | */ 37 | public function getName() 38 | { 39 | return $this->name; 40 | } 41 | 42 | /** 43 | * @param string $name 44 | * 45 | * @return OfferParam 46 | */ 47 | public function setName($name) 48 | { 49 | $this->name = $name; 50 | 51 | return $this; 52 | } 53 | 54 | /** 55 | * @return string 56 | */ 57 | public function getUnit() 58 | { 59 | return $this->unit; 60 | } 61 | 62 | /** 63 | * @param string $unit 64 | * 65 | * @return OfferParam 66 | */ 67 | public function setUnit($unit) 68 | { 69 | $this->unit = $unit; 70 | 71 | return $this; 72 | } 73 | 74 | /** 75 | * @return string 76 | */ 77 | public function getValue() 78 | { 79 | return $this->value; 80 | } 81 | 82 | /** 83 | * @param string $value 84 | * 85 | * @return OfferParam 86 | */ 87 | public function setValue($value) 88 | { 89 | $this->value = $value; 90 | 91 | return $this; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/Model/Offer/OfferSimple.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Bukashk0zzz\YmlGenerator\Model\Offer; 13 | 14 | /** 15 | * Class OfferSimple 16 | */ 17 | class OfferSimple extends AbstractOffer implements OfferGroupAwareInterface 18 | { 19 | use OfferGroupTrait; 20 | 21 | /** 22 | * @var string 23 | */ 24 | private $name; 25 | 26 | /** 27 | * @var string 28 | */ 29 | private $vendor; 30 | 31 | /** 32 | * @var string 33 | */ 34 | private $vendorCode; 35 | 36 | /** 37 | * @return string 38 | */ 39 | public function getType() 40 | { 41 | return null; 42 | } 43 | 44 | /** 45 | * @return string 46 | */ 47 | public function getName() 48 | { 49 | return $this->name; 50 | } 51 | 52 | /** 53 | * @param string $name 54 | * 55 | * @return $this 56 | */ 57 | public function setName($name) 58 | { 59 | $this->name = $name; 60 | 61 | return $this; 62 | } 63 | 64 | /** 65 | * @return string 66 | */ 67 | public function getVendor() 68 | { 69 | return $this->vendor; 70 | } 71 | 72 | /** 73 | * @param string $vendor 74 | * 75 | * @return $this 76 | */ 77 | public function setVendor($vendor) 78 | { 79 | $this->vendor = $vendor; 80 | 81 | return $this; 82 | } 83 | 84 | /** 85 | * @return string 86 | */ 87 | public function getVendorCode() 88 | { 89 | return $this->vendorCode; 90 | } 91 | 92 | /** 93 | * @param string $vendorCode 94 | * 95 | * @return $this 96 | */ 97 | public function setVendorCode($vendorCode) 98 | { 99 | $this->vendorCode = $vendorCode; 100 | 101 | return $this; 102 | } 103 | 104 | /** 105 | * @return array 106 | */ 107 | protected function getOptions() 108 | { 109 | return [ 110 | 'name' => $this->getName(), 111 | 'vendor' => $this->getVendor(), 112 | 'vendorCode' => $this->getVendorCode(), 113 | ]; 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /src/Model/Offer/OfferTour.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Bukashk0zzz\YmlGenerator\Model\Offer; 13 | 14 | /** 15 | * Class OfferTour 16 | */ 17 | class OfferTour extends AbstractOffer 18 | { 19 | /** 20 | * @var string 21 | */ 22 | private $worldRegion; 23 | 24 | /** 25 | * @var string 26 | */ 27 | private $country; 28 | 29 | /** 30 | * @var string 31 | */ 32 | private $region; 33 | 34 | /** 35 | * @var int 36 | */ 37 | private $days; 38 | 39 | /** 40 | * @var array 41 | */ 42 | private $dataTour; 43 | 44 | /** 45 | * @var string 46 | */ 47 | private $name; 48 | 49 | /** 50 | * @var string 51 | */ 52 | private $hotelStars; 53 | 54 | /** 55 | * @var string 56 | */ 57 | private $room; 58 | 59 | /** 60 | * @var string 61 | */ 62 | private $meal; 63 | 64 | /** 65 | * @var string 66 | */ 67 | private $included; 68 | 69 | /** 70 | * @var string 71 | */ 72 | private $transport; 73 | 74 | /** 75 | * @return string 76 | */ 77 | public function getType() 78 | { 79 | return 'tour'; 80 | } 81 | 82 | /** 83 | * @return string 84 | */ 85 | public function getWorldRegion() 86 | { 87 | return $this->worldRegion; 88 | } 89 | 90 | /** 91 | * @param string $worldRegion 92 | * 93 | * @return $this 94 | */ 95 | public function setWorldRegion($worldRegion) 96 | { 97 | $this->worldRegion = $worldRegion; 98 | 99 | return $this; 100 | } 101 | 102 | /** 103 | * @return string 104 | */ 105 | public function getCountry() 106 | { 107 | return $this->country; 108 | } 109 | 110 | /** 111 | * @param string $country 112 | * 113 | * @return $this 114 | */ 115 | public function setCountry($country) 116 | { 117 | $this->country = $country; 118 | 119 | return $this; 120 | } 121 | 122 | /** 123 | * @return string 124 | */ 125 | public function getRegion() 126 | { 127 | return $this->region; 128 | } 129 | 130 | /** 131 | * @param string $region 132 | * 133 | * @return $this 134 | */ 135 | public function setRegion($region) 136 | { 137 | $this->region = $region; 138 | 139 | return $this; 140 | } 141 | 142 | /** 143 | * @return int 144 | */ 145 | public function getDays() 146 | { 147 | return $this->days; 148 | } 149 | 150 | /** 151 | * @param int $days 152 | * 153 | * @return $this 154 | */ 155 | public function setDays($days) 156 | { 157 | $this->days = $days; 158 | 159 | return $this; 160 | } 161 | 162 | /** 163 | * @return array 164 | */ 165 | public function getDataTour() 166 | { 167 | return $this->dataTour; 168 | } 169 | 170 | /** 171 | * @param string $dataTour 172 | * 173 | * @return $this 174 | */ 175 | public function addDataTour($dataTour) 176 | { 177 | $this->dataTour[] = $dataTour; 178 | 179 | return $this; 180 | } 181 | 182 | /** 183 | * @return string 184 | */ 185 | public function getName() 186 | { 187 | return $this->name; 188 | } 189 | 190 | /** 191 | * @param string $name 192 | * 193 | * @return $this 194 | */ 195 | public function setName($name) 196 | { 197 | $this->name = $name; 198 | 199 | return $this; 200 | } 201 | 202 | /** 203 | * @return string 204 | */ 205 | public function getHotelStars() 206 | { 207 | return $this->hotelStars; 208 | } 209 | 210 | /** 211 | * @param string $hotelStars 212 | * 213 | * @return $this 214 | */ 215 | public function setHotelStars($hotelStars) 216 | { 217 | $this->hotelStars = $hotelStars; 218 | 219 | return $this; 220 | } 221 | 222 | /** 223 | * @return string 224 | */ 225 | public function getRoom() 226 | { 227 | return $this->room; 228 | } 229 | 230 | /** 231 | * @param string $room 232 | * 233 | * @return $this 234 | */ 235 | public function setRoom($room) 236 | { 237 | $this->room = $room; 238 | 239 | return $this; 240 | } 241 | 242 | /** 243 | * @return string 244 | */ 245 | public function getMeal() 246 | { 247 | return $this->meal; 248 | } 249 | 250 | /** 251 | * @param string $meal 252 | * 253 | * @return $this 254 | */ 255 | public function setMeal($meal) 256 | { 257 | $this->meal = $meal; 258 | 259 | return $this; 260 | } 261 | 262 | /** 263 | * @return string 264 | */ 265 | public function getIncluded() 266 | { 267 | return $this->included; 268 | } 269 | 270 | /** 271 | * @param string $included 272 | * 273 | * @return $this 274 | */ 275 | public function setIncluded($included) 276 | { 277 | $this->included = $included; 278 | 279 | return $this; 280 | } 281 | 282 | /** 283 | * @return string 284 | */ 285 | public function getTransport() 286 | { 287 | return $this->transport; 288 | } 289 | 290 | /** 291 | * @param string $transport 292 | * 293 | * @return $this 294 | */ 295 | public function setTransport($transport) 296 | { 297 | $this->transport = $transport; 298 | 299 | return $this; 300 | } 301 | 302 | /** 303 | * @return array 304 | */ 305 | protected function getOptions() 306 | { 307 | return [ 308 | 'worldRegion' => $this->getWorldRegion(), 309 | 'country' => $this->getCountry(), 310 | 'region' => $this->getRegion(), 311 | 'days' => $this->getDays(), 312 | 'dataTour' => $this->getDataTour(), 313 | 'name' => $this->getName(), 314 | 'hotel_stars' => $this->getHotelStars(), 315 | 'room' => $this->getRoom(), 316 | 'meal' => $this->getMeal(), 317 | 'included' => $this->getIncluded(), 318 | 'transport' => $this->getTransport(), 319 | ]; 320 | } 321 | } 322 | -------------------------------------------------------------------------------- /src/Model/ShopInfo.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Bukashk0zzz\YmlGenerator\Model; 13 | 14 | /** 15 | * Class ShopInfo 16 | */ 17 | class ShopInfo 18 | { 19 | /** 20 | * @var string 21 | */ 22 | private $name; 23 | 24 | /** 25 | * @var string 26 | */ 27 | private $company; 28 | 29 | /** 30 | * @var string 31 | */ 32 | private $url; 33 | 34 | /** 35 | * @var string 36 | */ 37 | private $platform; 38 | 39 | /** 40 | * @var string 41 | */ 42 | private $version; 43 | 44 | /** 45 | * @var string 46 | */ 47 | private $agency; 48 | 49 | /** 50 | * @var string 51 | */ 52 | private $email; 53 | 54 | /** 55 | * @var bool 56 | */ 57 | private $autoDiscount; 58 | 59 | /** 60 | * @return array 61 | */ 62 | public function toArray() 63 | { 64 | return [ 65 | 'name' => $this->getName(), 66 | 'company' => $this->getCompany(), 67 | 'url' => $this->getUrl(), 68 | 'platform' => $this->getPlatform(), 69 | 'version' => $this->getVersion(), 70 | 'agency' => $this->getAgency(), 71 | 'email' => $this->getEmail(), 72 | 'enable_auto_discounts' => $this->getAutoDiscount(), 73 | ]; 74 | } 75 | 76 | /** 77 | * @return string 78 | */ 79 | public function getName() 80 | { 81 | return $this->name; 82 | } 83 | 84 | /** 85 | * @param string $name 86 | * 87 | * @return ShopInfo 88 | */ 89 | public function setName($name) 90 | { 91 | $this->name = $name; 92 | 93 | return $this; 94 | } 95 | 96 | /** 97 | * @return string 98 | */ 99 | public function getCompany() 100 | { 101 | return $this->company; 102 | } 103 | 104 | /** 105 | * @param string $company 106 | * 107 | * @return ShopInfo 108 | */ 109 | public function setCompany($company) 110 | { 111 | $this->company = $company; 112 | 113 | return $this; 114 | } 115 | 116 | /** 117 | * @return string 118 | */ 119 | public function getUrl() 120 | { 121 | return $this->url; 122 | } 123 | 124 | /** 125 | * @param string $url 126 | * 127 | * @return ShopInfo 128 | */ 129 | public function setUrl($url) 130 | { 131 | $this->url = $url; 132 | 133 | return $this; 134 | } 135 | 136 | /** 137 | * @return string 138 | */ 139 | public function getPlatform() 140 | { 141 | return $this->platform; 142 | } 143 | 144 | /** 145 | * @param string $platform 146 | * 147 | * @return ShopInfo 148 | */ 149 | public function setPlatform($platform) 150 | { 151 | $this->platform = $platform; 152 | 153 | return $this; 154 | } 155 | 156 | /** 157 | * @return string 158 | */ 159 | public function getVersion() 160 | { 161 | return $this->version; 162 | } 163 | 164 | /** 165 | * @param string $version 166 | * 167 | * @return ShopInfo 168 | */ 169 | public function setVersion($version) 170 | { 171 | $this->version = $version; 172 | 173 | return $this; 174 | } 175 | 176 | /** 177 | * @return string 178 | */ 179 | public function getAgency() 180 | { 181 | return $this->agency; 182 | } 183 | 184 | /** 185 | * @param string $agency 186 | * 187 | * @return ShopInfo 188 | */ 189 | public function setAgency($agency) 190 | { 191 | $this->agency = $agency; 192 | 193 | return $this; 194 | } 195 | 196 | /** 197 | * @return string 198 | */ 199 | public function getEmail() 200 | { 201 | return $this->email; 202 | } 203 | 204 | /** 205 | * @param string $email 206 | * 207 | * @return ShopInfo 208 | */ 209 | public function setEmail($email) 210 | { 211 | $this->email = $email; 212 | 213 | return $this; 214 | } 215 | 216 | /** 217 | * @return bool 218 | */ 219 | public function getAutoDiscount() 220 | { 221 | return $this->autoDiscount; 222 | } 223 | 224 | /** 225 | * @param bool $autoDiscount 226 | * 227 | * @return ShopInfo 228 | */ 229 | public function setAutoDiscount($autoDiscount) 230 | { 231 | $this->autoDiscount = $autoDiscount; 232 | 233 | return $this; 234 | } 235 | } 236 | -------------------------------------------------------------------------------- /src/Settings.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Bukashk0zzz\YmlGenerator; 13 | 14 | /** 15 | * Class Settings 16 | */ 17 | class Settings 18 | { 19 | /** 20 | * Xml file encoding 21 | * 22 | * @var string 23 | */ 24 | protected $encoding = 'windows-1251'; 25 | 26 | /** 27 | * Output file name. If null 'php://output' is used. 28 | * 29 | * @var string|null 30 | */ 31 | protected $outputFile; 32 | 33 | /** 34 | * If true Generator will return generated YML string. 35 | * Not recommended to use this for big catalogs because of heavy memory usage. 36 | * 37 | * @var bool 38 | */ 39 | protected $returnResultYMLString = false; 40 | 41 | /** 42 | * Indent string in xml file. False or null means no indent; 43 | * 44 | * @var string 45 | */ 46 | protected $indentString = "\t"; 47 | 48 | /** 49 | * @return string 50 | */ 51 | public function getEncoding() 52 | { 53 | return $this->encoding; 54 | } 55 | 56 | /** 57 | * @param string $encoding 58 | * 59 | * @return Settings 60 | */ 61 | public function setEncoding($encoding) 62 | { 63 | $this->encoding = $encoding; 64 | 65 | return $this; 66 | } 67 | 68 | /** 69 | * @return string|null 70 | */ 71 | public function getOutputFile() 72 | { 73 | return $this->outputFile; 74 | } 75 | 76 | /** 77 | * @param string|null $outputFile 78 | * 79 | * @return Settings 80 | */ 81 | public function setOutputFile($outputFile) 82 | { 83 | $this->outputFile = $outputFile; 84 | 85 | return $this; 86 | } 87 | 88 | /** 89 | * @return string 90 | */ 91 | public function getIndentString() 92 | { 93 | return $this->indentString; 94 | } 95 | 96 | /** 97 | * @param string $indentString 98 | * 99 | * @return Settings 100 | */ 101 | public function setIndentString($indentString) 102 | { 103 | $this->indentString = $indentString; 104 | 105 | return $this; 106 | } 107 | 108 | /** 109 | * @param bool $returnResultYMLString 110 | * 111 | * @return Settings 112 | */ 113 | public function setReturnResultYMLString($returnResultYMLString) 114 | { 115 | $this->returnResultYMLString = $returnResultYMLString; 116 | 117 | return $this; 118 | } 119 | 120 | /** 121 | * @return bool 122 | */ 123 | public function getReturnResultYMLString() 124 | { 125 | return $this->returnResultYMLString; 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /tests/AbstractGeneratorTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Bukashk0zzz\YmlGenerator\Tests; 13 | 14 | use Bukashk0zzz\YmlGenerator\Generator; 15 | use Bukashk0zzz\YmlGenerator\Model\Category; 16 | use Bukashk0zzz\YmlGenerator\Model\Currency; 17 | use Bukashk0zzz\YmlGenerator\Model\Delivery; 18 | use Bukashk0zzz\YmlGenerator\Model\ShopInfo; 19 | use Bukashk0zzz\YmlGenerator\Settings; 20 | use Faker\Factory as Faker; 21 | 22 | /** 23 | * Abstract Generator test 24 | */ 25 | abstract class AbstractGeneratorTest extends \PHPUnit_Framework_TestCase 26 | { 27 | /** 28 | * @var \Faker\Generator 29 | */ 30 | protected $faker; 31 | 32 | /** 33 | * @var Settings 34 | */ 35 | protected $settings; 36 | 37 | /** 38 | * @var ShopInfo 39 | */ 40 | protected $shopInfo; 41 | 42 | /** 43 | * @var array 44 | */ 45 | protected $currencies; 46 | 47 | /** 48 | * @var array 49 | */ 50 | protected $categories; 51 | 52 | /** 53 | * @var array 54 | */ 55 | protected $deliveries; 56 | 57 | /** 58 | * @var string 59 | */ 60 | protected $offerType; 61 | 62 | /** 63 | * Test setup 64 | */ 65 | protected function setUp() 66 | { 67 | $this->faker = Faker::create(); 68 | 69 | $this->settings = $this->createSettings(); 70 | $this->shopInfo = $this->createShopInfo(); 71 | $this->currencies = $this->createCurrencies(); 72 | $this->categories = $this->createCategories(); 73 | $this->deliveries = $this->createDeliveries(); 74 | } 75 | 76 | /** 77 | * @return \Bukashk0zzz\YmlGenerator\Model\Offer\AbstractOffer 78 | */ 79 | abstract protected function createOffer(); 80 | 81 | /** 82 | * Produces an XML file and writes to $this->settings->getOutputFile() 83 | */ 84 | protected function generateFile() 85 | { 86 | static::assertTrue((new Generator($this->settings))->generate( 87 | $this->shopInfo, 88 | $this->currencies, 89 | $this->categories, 90 | $this->createOffers(), 91 | $this->deliveries 92 | )); 93 | } 94 | 95 | /** 96 | * Test generation 97 | */ 98 | protected function runGeneratorTest() 99 | { 100 | $this->generateFile(); 101 | $this->validateFileWithDtd(); 102 | } 103 | 104 | /** 105 | * @return array 106 | */ 107 | protected function createOffers() 108 | { 109 | $offers = []; 110 | foreach (\range(1, 2) as $id) { 111 | $offers[] = $this 112 | ->createOffer() 113 | ->setId($id) 114 | ->setAvailable($this->faker->boolean) 115 | ->setUrl($this->faker->url) 116 | ->setPrice($this->faker->numberBetween(1, 9999)) 117 | ->setOldPrice($this->faker->numberBetween(1, 9999)) 118 | ->setPurchasePrice($this->faker->numberBetween(1, 9999)) 119 | ->setWeight($this->faker->numberBetween(1, 9999)) 120 | ->setDimensions( 121 | $this->faker->randomFloat(3, 0), 122 | $this->faker->randomFloat(3, 0), 123 | $this->faker->randomFloat(3, 0) 124 | ) 125 | ->setCurrencyId('UAH') 126 | ->setCategoryId($id) 127 | ->setDelivery($this->faker->boolean) 128 | ->setLocalDeliveryCost($this->faker->numberBetween(1, 9999)) 129 | ->setDescription($this->faker->sentence) 130 | ->setSalesNotes($this->faker->text(45)) 131 | ->setManufacturerWarranty($this->faker->boolean) 132 | ->setCountryOfOrigin('Украина') 133 | ->setDownloadable($this->faker->boolean) 134 | ->setAdult($this->faker->boolean) 135 | ->setMarketCategory($this->faker->word) 136 | ->setCpa($this->faker->numberBetween(0, 1)) 137 | ->setBarcodes([$this->faker->ean13, $this->faker->ean13]) 138 | ->setAutoDiscount($this->faker->boolean) 139 | ; 140 | } 141 | 142 | return $offers; 143 | } 144 | 145 | /** 146 | * Validate yml file using dtd 147 | */ 148 | private function validateFileWithDtd() 149 | { 150 | $systemId = 'data://text/plain;base64,'.\base64_encode(\file_get_contents(__DIR__.'/dtd/'.$this->offerType.'.dtd')); 151 | $root = 'yml_catalog'; 152 | 153 | $ymlFile = new \DOMDocument(); 154 | $ymlFile->loadXML(\file_get_contents($this->settings->getOutputFile())); 155 | 156 | $creator = new \DOMImplementation(); 157 | $ymlFileWithDtd = $creator->createDocument(null, null, $creator->createDocumentType($root, null, $systemId)); 158 | $ymlFileWithDtd->encoding = 'windows-1251'; 159 | 160 | $oldNode = $ymlFile->getElementsByTagName($root)->item(0); 161 | $newNode = $ymlFileWithDtd->importNode($oldNode, true); 162 | $ymlFileWithDtd->appendChild($newNode); 163 | 164 | try { 165 | static::assertTrue($ymlFileWithDtd->validate()); 166 | } catch (\Exception $exception) { 167 | echo $exception->getMessage(); 168 | static::fail('YML file not valid'); 169 | } 170 | } 171 | 172 | /** 173 | * @return Settings 174 | */ 175 | private function createSettings() 176 | { 177 | return (new Settings()) 178 | ->setOutputFile(\tempnam(\sys_get_temp_dir(), 'YMLGeneratorTest')) 179 | ->setEncoding('utf-8') 180 | ->setIndentString("\t") 181 | ; 182 | } 183 | 184 | /** 185 | * @return ShopInfo 186 | */ 187 | private function createShopInfo() 188 | { 189 | return (new ShopInfo()) 190 | ->setName($this->faker->name) 191 | ->setCompany($this->faker->company) 192 | ->setUrl($this->faker->url) 193 | ->setPlatform($this->faker->name) 194 | ->setVersion($this->faker->numberBetween(1, 999)) 195 | ->setAgency($this->faker->name) 196 | ->setEmail($this->faker->email) 197 | ->setAutoDiscount($this->faker->boolean) 198 | ; 199 | } 200 | 201 | /** 202 | * @return array 203 | */ 204 | private function createCurrencies() 205 | { 206 | $currencies = []; 207 | $currencies[] = (new Currency()) 208 | ->setId('UAH') 209 | ->setRate(1) 210 | ; 211 | 212 | return $currencies; 213 | } 214 | 215 | /** 216 | * @return array 217 | */ 218 | private function createCategories() 219 | { 220 | $categories = []; 221 | $categories[] = (new Category()) 222 | ->setId(1) 223 | ->setName($this->faker->name) 224 | ; 225 | 226 | $categories[] = (new Category()) 227 | ->setId(2) 228 | ->setParentId(1) 229 | ->setName($this->faker->name) 230 | ; 231 | 232 | return $categories; 233 | } 234 | 235 | /** 236 | * @return array 237 | */ 238 | private function createDeliveries() 239 | { 240 | $deliveries = []; 241 | $deliveries[] = (new Delivery()) 242 | ->setCost(1) 243 | ->setDays(2); 244 | 245 | $deliveries[] = (new Delivery()) 246 | ->setCost(2) 247 | ->setDays(1) 248 | ->setOrderBefore(14); 249 | 250 | return $deliveries; 251 | } 252 | } 253 | -------------------------------------------------------------------------------- /tests/GeneratorTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Bukashk0zzz\YmlGenerator\Tests; 13 | 14 | use Bukashk0zzz\YmlGenerator\Generator; 15 | use Bukashk0zzz\YmlGenerator\Model\ShopInfo; 16 | use Bukashk0zzz\YmlGenerator\Settings; 17 | 18 | /** 19 | * Generator test 20 | */ 21 | class GeneratorTest extends \PHPUnit_Framework_TestCase 22 | { 23 | /** 24 | * @expectedException \RuntimeException 25 | */ 26 | public function testExceptionForIncompatibleAnnotations() 27 | { 28 | (new Generator((new Settings())->setOutputFile(''))) 29 | ->generate(new ShopInfo(), [], [], []) 30 | ; 31 | } 32 | 33 | /** 34 | * @expectedException \LogicException 35 | */ 36 | public function testExceptionIfManyDestinationUsed() 37 | { 38 | $settings = (new Settings()) 39 | ->setOutputFile('') 40 | ->setReturnResultYMLString(true) 41 | ; 42 | 43 | (new Generator($settings)) 44 | ->generate(new ShopInfo(), [], [], []) 45 | ; 46 | } 47 | 48 | /** 49 | * Test equal returned value and printed 50 | */ 51 | public function testGenerationEchoValueEqualsReturnValue() 52 | { 53 | $settings = (new Settings()) 54 | ->setReturnResultYMLString(true) 55 | ; 56 | $value = (new Generator($settings)) 57 | ->generate(new ShopInfo(), [], [], [], []); 58 | 59 | \ob_start(); 60 | (new Generator(new Settings())) 61 | ->generate(new ShopInfo(), [], [], [], []); 62 | $value2 = \ob_get_clean(); 63 | 64 | $this->assertEquals($value, $value2); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /tests/OfferArtistTitleGeneratorTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Bukashk0zzz\YmlGenerator\Tests; 13 | 14 | use Bukashk0zzz\YmlGenerator\Model\Offer\OfferArtistTitle; 15 | 16 | /** 17 | * Generator test 18 | */ 19 | class OfferArtistTitleGeneratorTest extends AbstractGeneratorTest 20 | { 21 | /** 22 | * Test generate 23 | */ 24 | public function testGenerate() 25 | { 26 | $this->offerType = 'ArtistTitle'; 27 | $this->runGeneratorTest(); 28 | } 29 | 30 | /** 31 | * {@inheritdoc} 32 | */ 33 | protected function createOffer() 34 | { 35 | return (new OfferArtistTitle()) 36 | ->setArtist($this->faker->name) 37 | ->setTitle($this->faker->name) 38 | ->setYear($this->faker->numberBetween(1, 9999)) 39 | ->setMedia($this->faker->name) 40 | ; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /tests/OfferAudiobookGeneratorTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Bukashk0zzz\YmlGenerator\Tests; 13 | 14 | use Bukashk0zzz\YmlGenerator\Model\Offer\OfferAudiobook; 15 | 16 | /** 17 | * Generator test 18 | */ 19 | class OfferAudiobookGeneratorTest extends AbstractGeneratorTest 20 | { 21 | /** 22 | * Test generate 23 | */ 24 | public function testGenerate() 25 | { 26 | $this->offerType = 'Audiobook'; 27 | $this->runGeneratorTest(); 28 | } 29 | 30 | /** 31 | * {@inheritdoc} 32 | */ 33 | protected function createOffer() 34 | { 35 | return (new OfferAudiobook()) 36 | ->setAuthor($this->faker->name) 37 | ->setName($this->faker->name) 38 | ->setPublisher($this->faker->name) 39 | ->setSeries($this->faker->name) 40 | ->setYear($this->faker->numberBetween(1, 9999)) 41 | ->setISBN($this->faker->isbn13) 42 | ->setVolume($this->faker->numberBetween(1, 9999)) 43 | ->setPart($this->faker->numberBetween(1, 9999)) 44 | ->setLanguage($this->faker->name) 45 | ->setTableOfContents($this->faker->name) 46 | ->setPerformedBy($this->faker->name) 47 | ->setPerformanceType($this->faker->name) 48 | ->setStorage($this->faker->name) 49 | ->setFormat($this->faker->name) 50 | ->setRecordingLength($this->faker->name) 51 | ; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /tests/OfferBookGeneratorTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Bukashk0zzz\YmlGenerator\Tests; 13 | 14 | use Bukashk0zzz\YmlGenerator\Model\Offer\OfferBook; 15 | 16 | /** 17 | * Generator test 18 | */ 19 | class OfferBookGeneratorTest extends AbstractGeneratorTest 20 | { 21 | /** 22 | * Test generate 23 | */ 24 | public function testGenerate() 25 | { 26 | $this->offerType = 'Book'; 27 | $this->runGeneratorTest(); 28 | } 29 | 30 | /** 31 | * {@inheritdoc} 32 | */ 33 | protected function createOffer() 34 | { 35 | return (new OfferBook()) 36 | ->setAuthor($this->faker->name) 37 | ->setName($this->faker->name) 38 | ->setPublisher($this->faker->name) 39 | ->setSeries($this->faker->name) 40 | ->setYear($this->faker->numberBetween(1, 9999)) 41 | ->setISBN($this->faker->isbn13) 42 | ->setVolume($this->faker->numberBetween(1, 9999)) 43 | ->setPart($this->faker->numberBetween(1, 9999)) 44 | ->setLanguage($this->faker->name) 45 | ->setBinding($this->faker->name) 46 | ->setPageExtent($this->faker->numberBetween(1, 9999)) 47 | ->setTableOfContents($this->faker->name) 48 | ; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /tests/OfferCdataGeneratorTest.php: -------------------------------------------------------------------------------- 1 | Simple HTML

offerType = 'Simple'; 29 | $this->runGeneratorTest(); 30 | $this->checkCdata(); 31 | } 32 | 33 | /** 34 | * Need to override parent::createOffers() in order to avoid setting description 35 | * after calling self::createOffer() 36 | * 37 | * {@inheritdoc} 38 | * 39 | * @see \Bukashk0zzz\YmlGenerator\Tests\AbstractGeneratorTest::createOffers() 40 | */ 41 | protected function createOffers() 42 | { 43 | $offers = []; 44 | foreach (\range(1, self::OFFER_COUNT) as $id) { 45 | $offers[] = 46 | $this->createOffer() 47 | ->setId($id) 48 | ->setCategoryId($id) 49 | ; 50 | } 51 | 52 | return $offers; 53 | } 54 | 55 | /** 56 | * Set the test description with CDATA here 57 | * 58 | * {@inheritdoc} 59 | * 60 | * @see \Bukashk0zzz\YmlGenerator\Tests\AbstractGeneratorTest::createOffer() 61 | */ 62 | protected function createOffer() 63 | { 64 | return (new OfferSimple()) 65 | ->setAvailable($this->faker->boolean) 66 | ->setUrl($this->faker->url) 67 | ->setPrice($this->faker->numberBetween(1, 9999)) 68 | ->setOldPrice($this->faker->numberBetween(1, 9999)) 69 | ->setWeight($this->faker->numberBetween(1, 9999)) 70 | ->setCurrencyId('UAH') 71 | ->setDelivery($this->faker->boolean) 72 | ->setLocalDeliveryCost($this->faker->numberBetween(1, 9999)) 73 | ->setSalesNotes($this->faker->text(45)) 74 | ->setManufacturerWarranty($this->faker->boolean) 75 | ->setCountryOfOrigin('Украина') 76 | ->setDownloadable($this->faker->boolean) 77 | ->setAdult($this->faker->boolean) 78 | ->setMarketCategory($this->faker->word) 79 | ->setCpa($this->faker->numberBetween(0, 1)) 80 | ->setBarcodes([$this->faker->ean13, $this->faker->ean13]) 81 | 82 | ->setName($this->faker->name) 83 | ->setVendor($this->faker->company) 84 | ->setDescription($this->makeDescription()) 85 | ->setVendorCode(null) 86 | ->setPickup(true) 87 | ->setGroupId($this->faker->numberBetween()) 88 | ->addPicture('http://example.com/example.jpeg') 89 | ->addBarcode($this->faker->ean13) 90 | ; 91 | } 92 | 93 | /** 94 | * Retreive and check CDATA from the generated file 95 | */ 96 | private function checkCdata() 97 | { 98 | $ymlFile = new \DOMDocument(); 99 | $ymlFile->loadXML(\file_get_contents($this->settings->getOutputFile())); 100 | 101 | $xpath = new \DOMXPath($ymlFile); 102 | $descriptionNodes = $xpath->query('//yml_catalog/shop/offers/offer/description'); 103 | self::assertNotFalse($descriptionNodes); 104 | 105 | // One description per offer is expected 106 | self::assertEquals(self::OFFER_COUNT, $descriptionNodes->length); 107 | 108 | foreach ($descriptionNodes as $descriptionNode) { 109 | $description = $descriptionNode->nodeValue; 110 | 111 | self::assertSame(self::CDATA_TEST_STRING, $description); 112 | } 113 | } 114 | 115 | /** 116 | * Create instance of Cdata class with a predefined test string 117 | * 118 | * @return \Bukashk0zzz\YmlGenerator\Cdata 119 | */ 120 | private function makeDescription() 121 | { 122 | return new Cdata(self::CDATA_TEST_STRING); 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /tests/OfferCustomElementsGeneratorTest.php: -------------------------------------------------------------------------------- 1 | Simple HTML

validateFileWithDtd() here because custom elements are not included into the default DTD 29 | $this->generateFile(); 30 | $this->checkCustomElements(); 31 | } 32 | 33 | /** 34 | * Need to override parent::createOffers() in order to avoid setting description 35 | * after calling self::createOffer() 36 | * 37 | * {@inheritdoc} 38 | * 39 | * @see \Bukashk0zzz\YmlGenerator\Tests\AbstractGeneratorTest::createOffers() 40 | */ 41 | protected function createOffers() 42 | { 43 | $offers = []; 44 | foreach (\range(1, self::OFFER_COUNT) as $id) { 45 | $offers[] = 46 | $this->createOffer() 47 | ->setId($id) 48 | ->setCategoryId($id) 49 | ; 50 | } 51 | 52 | return $offers; 53 | } 54 | 55 | /** 56 | * Set the test description with CDATA here 57 | * 58 | * {@inheritdoc} 59 | * 60 | * @see \Bukashk0zzz\YmlGenerator\Tests\AbstractGeneratorTest::createOffer() 61 | */ 62 | protected function createOffer() 63 | { 64 | $offer = (new OfferSimple()) 65 | ->setAvailable($this->faker->boolean) 66 | ->setUrl($this->faker->url) 67 | ->setPrice($this->faker->numberBetween(1, 9999)) 68 | ->setOldPrice($this->faker->numberBetween(1, 9999)) 69 | ->setWeight($this->faker->numberBetween(1, 9999)) 70 | ->setCurrencyId('UAH') 71 | ->setDelivery($this->faker->boolean) 72 | ->setLocalDeliveryCost($this->faker->numberBetween(1, 9999)) 73 | ->setSalesNotes($this->faker->text(45)) 74 | ->setManufacturerWarranty($this->faker->boolean) 75 | ->setCountryOfOrigin('Украина') 76 | ->setDownloadable($this->faker->boolean) 77 | ->setAdult($this->faker->boolean) 78 | ->setMarketCategory($this->faker->word) 79 | ->setCpa($this->faker->numberBetween(0, 1)) 80 | ->setBarcodes([$this->faker->ean13, $this->faker->ean13]) 81 | 82 | ->setName($this->faker->name) 83 | ->setVendor($this->faker->company) 84 | ->setDescription($this->faker->sentence) 85 | ->setVendorCode(null) 86 | ->setPickup(true) 87 | ->setGroupId($this->faker->numberBetween()) 88 | ->addPicture('http://example.com/example.jpeg') 89 | ->addBarcode($this->faker->ean13) 90 | 91 | ->setCustomElements(['custom_element' => [100500, 'string value']]) 92 | ->addCustomElement('custom_element', true) 93 | ->addCustomElement('custom_element', false) 94 | ->addCustomElement('custom_element', null) // Should not be written 95 | ->addCustomElement('custom_element', $cdata = new Cdata(self::CDATA_TEST_STRING)) 96 | ->addCustomElement('stock_quantity', 100) // https://rozetka.com.ua/sellerinfo/pricelist/ 97 | ; 98 | 99 | $this->assertSame([100500, 'string value', true, false, $cdata], $offer->getCustomElementByType('custom_element')); 100 | $this->assertSame([100], $offer->getCustomElementByType('stock_quantity')); 101 | $this->assertSame([], $offer->getCustomElementByType('non_existent_element')); 102 | 103 | return $offer; 104 | } 105 | 106 | /** 107 | * Load generated XML file and check custom elements 108 | */ 109 | private function checkCustomElements() 110 | { 111 | // Much easier to test with SimpleXML tahn with DOM 112 | $yml = \simplexml_load_file($this->settings->getOutputFile()); 113 | 114 | $offers = $yml->shop->offers->offer; 115 | $this->assertNotEmpty($offers); 116 | $this->assertEquals(self::OFFER_COUNT, \count($offers)); 117 | 118 | foreach ($offers as $offer) { 119 | $prop = 'stock_quantity'; 120 | $this->assertSame(100, (int) $offer->$prop); // Can't use $offer->stock_quantity because of CS rules 121 | 122 | $prop = 'custom_element'; 123 | $multipleElements = $offer->$prop; // Can't use $offer->custom_element because of CS rules 124 | $this->assertNotEmpty($multipleElements); 125 | 126 | // Verity each added value 127 | $this->assertSame(100500, (int) $multipleElements[0]); 128 | $this->assertSame('string value', (string) $multipleElements[1]); 129 | $this->assertSame('true', (string) $multipleElements[2]); 130 | $this->assertSame('false', (string) $multipleElements[3]); 131 | 132 | // ->addCustomElement('custom_element', null) must not produce an element 133 | 134 | $this->assertSame(self::CDATA_TEST_STRING, (string) $multipleElements[4]); 135 | } 136 | } 137 | 138 | /** 139 | * Create instance of Cdata class with a predefined test string 140 | * 141 | * @return \Bukashk0zzz\YmlGenerator\Cdata 142 | */ 143 | private function makeDescription() 144 | { 145 | return new Cdata(self::CDATA_TEST_STRING); 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /tests/OfferCustomGeneratorTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Bukashk0zzz\YmlGenerator\Tests; 13 | 14 | use Bukashk0zzz\YmlGenerator\Model\Offer\OfferCondition; 15 | use Bukashk0zzz\YmlGenerator\Model\Offer\OfferCustom; 16 | use Bukashk0zzz\YmlGenerator\Model\Offer\OfferParam; 17 | 18 | /** 19 | * Generator test 20 | */ 21 | class OfferCustomGeneratorTest extends AbstractGeneratorTest 22 | { 23 | /** 24 | * Test generate 25 | */ 26 | public function testGenerate() 27 | { 28 | $this->offerType = 'Custom'; 29 | $this->runGeneratorTest(); 30 | } 31 | 32 | /** 33 | * {@inheritdoc} 34 | */ 35 | protected function createOffer() 36 | { 37 | return (new OfferCustom()) 38 | ->setTypePrefix($this->faker->colorName) 39 | ->setVendor($this->faker->company) 40 | ->setVendorCode($this->faker->companySuffix) 41 | ->setModel($this->faker->userName) 42 | ->setGroupId($this->faker->numberBetween()) 43 | ->setStore($this->faker->boolean) 44 | ->addParam( 45 | (new OfferParam()) 46 | ->setName($this->faker->name) 47 | ->setUnit($this->faker->text(5)) 48 | ->setValue($this->faker->text(10)) 49 | ) 50 | ->setPictures(['http://example.com/example.jpeg', 'http://example.com/example2.jpeg']) 51 | ->addCondition( 52 | (new OfferCondition()) 53 | ->setType($this->faker->text(5)) 54 | ->setReasonText($this->faker->text(10)) 55 | ) 56 | ; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /tests/OfferDeliveryOptionsGeneratorTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Bukashk0zzz\YmlGenerator\Tests; 13 | 14 | use Bukashk0zzz\YmlGenerator\Model\Delivery; 15 | use Bukashk0zzz\YmlGenerator\Model\Offer\OfferSimple; 16 | 17 | /** 18 | * Generator test 19 | */ 20 | class OfferDeliveryOptionsGeneratorTest extends AbstractGeneratorTest 21 | { 22 | /** 23 | * Test generate 24 | */ 25 | public function testGenerate() 26 | { 27 | $this->offerType = 'OfferDeliveryOptions'; 28 | $this->runGeneratorTest(); 29 | } 30 | 31 | /** 32 | * {@inheritdoc} 33 | */ 34 | protected function createOffer() 35 | { 36 | $delivery = (new Delivery())->setCost(10)->setDays(1)->setOrderBefore(14); 37 | 38 | return (new OfferSimple()) 39 | ->setName($this->faker->name) 40 | ->setVendor($this->faker->company) 41 | ->setVendorCode(null) 42 | ->setPickup(true) 43 | ->addDeliveryOption($delivery) 44 | ->addDeliveryOption($delivery) 45 | ->setGroupId($this->faker->numberBetween()) 46 | ->addPicture('http://example.com/example.jpeg') 47 | ->addBarcode($this->faker->ean13) 48 | ->setCategoriesId([1, 2, 3]) 49 | ->setCategoryId(999) 50 | ; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /tests/OfferEventTicketGeneratorTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Bukashk0zzz\YmlGenerator\Tests; 13 | 14 | use Bukashk0zzz\YmlGenerator\Model\Offer\OfferEventTicket; 15 | 16 | /** 17 | * Generator test 18 | */ 19 | class OfferEventTicketGeneratorTest extends AbstractGeneratorTest 20 | { 21 | /** 22 | * Test generate 23 | */ 24 | public function testGenerate() 25 | { 26 | $this->offerType = 'EventTicket'; 27 | $this->runGeneratorTest(); 28 | } 29 | 30 | /** 31 | * {@inheritdoc} 32 | */ 33 | protected function createOffer() 34 | { 35 | return (new OfferEventTicket()) 36 | ->setName($this->faker->name) 37 | ->setPlace($this->faker->name) 38 | ->setDate($this->faker->date('d/m/y')) 39 | ->setPremiere($this->faker->numberBetween(0, 1)) 40 | ->setKids($this->faker->numberBetween(0, 1)) 41 | ; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /tests/OfferSimpleGeneratorTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Bukashk0zzz\YmlGenerator\Tests; 13 | 14 | use Bukashk0zzz\YmlGenerator\Model\Offer\OfferSimple; 15 | 16 | /** 17 | * Generator test 18 | */ 19 | class OfferSimpleGeneratorTest extends AbstractGeneratorTest 20 | { 21 | /** 22 | * Test generate 23 | */ 24 | public function testGenerate() 25 | { 26 | $this->offerType = 'Simple'; 27 | $this->runGeneratorTest(); 28 | } 29 | 30 | /** 31 | * {@inheritdoc} 32 | */ 33 | protected function createOffer() 34 | { 35 | return (new OfferSimple()) 36 | ->setName($this->faker->name) 37 | ->setVendor($this->faker->company) 38 | ->setVendorCode(null) 39 | ->setPickup(true) 40 | ->setGroupId($this->faker->numberBetween()) 41 | ->addPicture('http://example.com/example.jpeg') 42 | ->addBarcode($this->faker->ean13) 43 | ->setCategoriesId([1, 2, 3]) 44 | ->setCategoryId(999) 45 | ; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /tests/OfferTourGeneratorTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Bukashk0zzz\YmlGenerator\Tests; 13 | 14 | use Bukashk0zzz\YmlGenerator\Model\Offer\OfferTour; 15 | 16 | /** 17 | * Generator test 18 | */ 19 | class OfferTourGeneratorTest extends AbstractGeneratorTest 20 | { 21 | /** 22 | * Test generate 23 | */ 24 | public function testGenerate() 25 | { 26 | $this->offerType = 'Tour'; 27 | $this->runGeneratorTest(); 28 | } 29 | 30 | /** 31 | * {@inheritdoc} 32 | */ 33 | protected function createOffer() 34 | { 35 | return (new OfferTour()) 36 | ->setWorldRegion($this->faker->name) 37 | ->setCountry($this->faker->name) 38 | ->setRegion($this->faker->name) 39 | ->setDays($this->faker->numberBetween(1, 9999)) 40 | ->addDataTour($this->faker->date("Y-m-d\TH:i")) 41 | ->setName($this->faker->name) 42 | ->setHotelStars($this->faker->name) 43 | ->setRoom($this->faker->name) 44 | ->setMeal($this->faker->name) 45 | ->setIncluded($this->faker->name) 46 | ->setTransport($this->faker->name) 47 | ; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /tests/dtd/ArtistTitle.dtd: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 15 | 16 | 17 | 18 | 19 | 24 | 25 | 26 | 27 | 31 | 32 | 33 | 78 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 175 | 176 | 177 | 178 | 179 | 180 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | -------------------------------------------------------------------------------- /tests/dtd/Audiobook.dtd: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 15 | 16 | 17 | 18 | 19 | 24 | 25 | 26 | 27 | 31 | 32 | 33 | 85 | 86 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 183 | 184 | 185 | 186 | 187 | 188 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | -------------------------------------------------------------------------------- /tests/dtd/Book.dtd: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 15 | 16 | 17 | 18 | 19 | 24 | 25 | 26 | 27 | 31 | 32 | 33 | 34 | 83 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 180 | 181 | 182 | 183 | 184 | 185 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | -------------------------------------------------------------------------------- /tests/dtd/Custom.dtd: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 15 | 16 | 17 | 18 | 19 | 24 | 25 | 26 | 27 | 31 | 32 | 33 | 75 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 172 | 173 | 174 | 175 | 176 | 177 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | -------------------------------------------------------------------------------- /tests/dtd/EventTicket.dtd: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 15 | 16 | 17 | 18 | 19 | 24 | 25 | 26 | 27 | 31 | 32 | 33 | 77 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 174 | 175 | 176 | 177 | 178 | 179 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | -------------------------------------------------------------------------------- /tests/dtd/OfferDeliveryOptions.dtd: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 15 | 16 | 17 | 18 | 19 | 24 | 25 | 26 | 27 | 31 | 32 | 33 | 73 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 170 | 171 | 172 | 173 | 174 | 175 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | -------------------------------------------------------------------------------- /tests/dtd/Original.dtd: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 15 | 16 | 17 | 18 | 19 | 24 | 25 | 26 | 43 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 137 | 138 | 139 | 140 | 141 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | -------------------------------------------------------------------------------- /tests/dtd/Simple.dtd: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 15 | 16 | 17 | 18 | 19 | 24 | 25 | 26 | 27 | 31 | 32 | 33 | 72 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 169 | 170 | 171 | 172 | 173 | 174 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | -------------------------------------------------------------------------------- /tests/dtd/Tour.dtd: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 15 | 16 | 17 | 18 | 19 | 24 | 25 | 26 | 27 | 31 | 32 | 33 | 83 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 180 | 181 | 182 | 183 | 184 | 185 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | --------------------------------------------------------------------------------