All Projects → corpsepk → yii2-yandex-market-yml

corpsepk / yii2-yandex-market-yml

Licence: MIT license
Yii2 module for automatically generation Yandex.Market YML

Programming Languages

PHP
23972 projects - #3 most used programming language
Dockerfile
14818 projects
Makefile
30231 projects
shell
77523 projects

Projects that are alternatives of or similar to yii2-yandex-market-yml

YmlGenerator
YML (Yandex Market Language) file generator
Stars: ✭ 96 (+585.71%)
Mutual labels:  yml, yandex-market
yii2-payment
Yii2 Payment extension hổ trợ tích hợp các cổng thanh toán VnPayment, Onepay, Bảo Kim, Ngân Lượng, VTCPay, MoMo.
Stars: ✭ 20 (+42.86%)
Mutual labels:  yii2
yii2-dysms
阿里云 dysms 官方 SDK 的 Composer 封装,支持 yii2 项目。
Stars: ✭ 13 (-7.14%)
Mutual labels:  yii2
yii2-flysystem-component
The League Flysystem Library for Yii Framework
Stars: ✭ 22 (+57.14%)
Mutual labels:  yii2
yii2-faker
Yii 2 Faker extension
Stars: ✭ 99 (+607.14%)
Mutual labels:  yii2
ar-variation
Variation behavior for ActiveRecord
Stars: ✭ 46 (+228.57%)
Mutual labels:  yii2
slides
Alexander Makarov conference slides
Stars: ✭ 26 (+85.71%)
Mutual labels:  yii2
library
企业内部图书馆管理系统
Stars: ✭ 23 (+64.29%)
Mutual labels:  yii2
query
Run SQL queries as an admin from the Craft CMS control panel.
Stars: ✭ 14 (+0%)
Mutual labels:  yii2
ar-role
ActiveRecord behavior, which provides relation roles (table inheritance)
Stars: ✭ 34 (+142.86%)
Mutual labels:  yii2
deruv
The elegant and professional PHP Content Management System
Stars: ✭ 38 (+171.43%)
Mutual labels:  yii2
yii2-rest-client
REST client (AR-like model) for Yii Framework 2.0 (via yii2-http-client)
Stars: ✭ 19 (+35.71%)
Mutual labels:  yii2
hisite-template
HiSite Project Template
Stars: ✭ 16 (+14.29%)
Mutual labels:  yii2
yii2-lock-form
disable the button when form submit
Stars: ✭ 37 (+164.29%)
Mutual labels:  yii2
yii2-widget-cropbox
This widget allows crop image before upload to server and send informations about crop in JSON format.
Stars: ✭ 90 (+542.86%)
Mutual labels:  yii2
anchors
Add anchor links to headings in your Craft CMS website content.
Stars: ✭ 47 (+235.71%)
Mutual labels:  yii2
project-template
Yii2 Project Template
Stars: ✭ 53 (+278.57%)
Mutual labels:  yii2
yii2-presenter
Yii2 View Presenter
Stars: ✭ 13 (-7.14%)
Mutual labels:  yii2
yii2-timezone
Timezone detector
Stars: ✭ 14 (+0%)
Mutual labels:  yii2
yii2-laradock
Laradock pre-configured for Yii2 Framework (https://github.com/LaraDock/laradock)
Stars: ✭ 16 (+14.29%)
Mutual labels:  yii2

Yandex.Market YML Module for Yii2

Yii2 module for automatically generation Yandex.Market YML.

Latest Version Build Status Quality Score Minimum PHP Version

Installation

The preferred way to install this extension is through composer.

  • Either run
php composer.phar require --prefer-dist "corpsepk/yii2-yandex-market-yml" "~0.7"

or add

"corpsepk/yii2-yandex-market-yml" : "~0.7"

to the require section of your application's composer.json file.

Configure config

Configure the cache component of your application's configuration file, for example:

'components' => [
    'cache' => [
        'class' => 'yii\caching\FileCache',
    ],
]

Add a new module in modules section of your application's configuration file, for example:

'modules' => [
    'YandexMarketYml' => [
        'class' => 'corpsepk\yml\YandexMarketYml',
        'cacheExpire' => 1, // 1 second. Default is 24 hours
        'categoryModel' => 'app\models\Category',
        'shopOptions' => [
            'name' => 'MyCompanyName',
            'company' => 'LTD MyCompanyName',
            'url' => 'http://example.com',
            'currencies' => [
                [
                    'id' => 'RUR',
                    'rate' => 1
                ]
            ],
        ],
        'offerModels' => [
            ['class' => 'app\models\Item'],
        ],
    ],
],

Add a new rule for urlManager of your application's configuration file, for example:

'urlManager' => [
    'rules' => [
        ['pattern' => 'yandex-market', 'route' => 'YandexMarketYml/default/index', 'suffix' => '.yml'],
    ],
],

Configure Category model

https://yandex.ru/support/partnermarket/elements/categories.html

Add behavior in the AR category model, for example:

use corpsepk\yml\behaviors\YmlCategoryBehavior;

public function behaviors()
{
    return [
        'ymlCategory' => [
            'class' => YmlCategoryBehavior::className(),
            'scope' => function ($model) {
                /** @var \yii\db\ActiveQuery $model */
                $model->select(['id', 'name', 'parent_id']);
            },
            'dataClosure' => function ($model) {
                /** @var self $model */
                return [
                    'id' => $model->id,
                    'name' => $model->name,
                    'parentId' => $model->parent_id
                ];
            }
        ],
    ];
}

Configure Offer models

Add behavior in the AR models, for example:

use corpsepk\yml\behaviors\YmlOfferBehavior;
use corpsepk\yml\models\Offer;

public function behaviors()
{
    return [
        'ymlOffer' => [
            'class' => YmlOfferBehavior::className(),
            'scope' => function ($model) {
                /** @var \yii\db\ActiveQuery $model */
                $model->andWhere(['is_deleted' => false]);
            },
            'dataClosure' => function ($model) {
                /** @var self $model */
                return new Offer([
                    'id' => $model->id,
                    'url' => $model->getUrl(true), // absolute url e.g. http://example.com/item/1256
                    'price' => $model->getPrice(),
                    'currencyId' => 'RUR',
                    'categoryId' => $model->category_id,
                    'picture' => $model->cover ? $model->cover->getUrl() : null,
                    /**
                     * Or as array
                     * don't forget that yandex-market accepts 10 pictures max
                     * @see https://yandex.ru/support/partnermarket/picture.xml
                     */
                    'picture' => ArrayHelper::map($model->images, 'id', function ($image) {
                        return $image->getUrl();
                    }),
                    'name' => $model->name,
                    'vendor' => $model->brand ? $model->brand->name : null,
                    'description' => $model->description,
                    'customElements' => [
                        [
                            'outlets' => '<outlet id="1" instock="30" />'
                        ]
                    ],
                ]);
            }
        ],
    ];
}

Testing

docker-compose -f tests/docker-compose.yml run --rm php56 phpunit

or

docker-compose -f tests/docker-compose.yml up --build -d
docker exec -it tests_php56_1 sh
phpunit

Howto

Use console command to build yml

Useful links

Yandex XML validator - https://webmaster.yandex.ru/tools/xml-validator/

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].