loevgaard / sylius-brand-plugin
一个用于处理品牌的Sylius插件
Requires
- sylius/sylius: ^1.3
Requires (Dev)
- behat/behat: ^3.4
- behat/mink: ^1.7@dev
- behat/mink-browserkit-driver: ^1.3
- behat/mink-extension: ^2.2
- behat/mink-selenium2-driver: ^1.3
- ergebnis/composer-normalize: ^2.0
- friends-of-behat/mink-debug-extension: ^1.2.3 || ^2.0
- friends-of-behat/page-object-extension: ^0.3
- friends-of-behat/service-container-extension: ^1.0
- friends-of-behat/suite-settings-extension: ^1.0
- friends-of-behat/symfony-extension: ^2.0
- friends-of-behat/variadic-extension: ^1.1
- lchrusciel/api-test-case: ^4.0 || ^5.0
- matthiasnoback/symfony-config-test: ^4.0
- phpspec/phpspec: ^7.0
- phpstan/phpstan: ^0.12 || ^1.0
- phpstan/phpstan-doctrine: ^0.12 || ^1.0
- phpstan/phpstan-symfony: ^0.12 || ^1.0
- phpstan/phpstan-webmozart-assert: ^0.12 || ^1.0
- phpunit/phpunit: ^8.0
- roave/security-advisories: dev-master
- sensiolabs/security-checker: ^5.0
- sylius-labs/coding-standard: ^4.0
- symfony/browser-kit: ^3.4 || ^4.1
- symfony/debug-bundle: ^3.4 || ^4.1
- symfony/dotenv: ^4.2
- symfony/event-dispatcher: ^3.4 || ^4.1
- symfony/intl: ^3.4 || ^4.1
- symfony/web-profiler-bundle: ^3.4 || ^4.1
- symfony/web-server-bundle: ^3.4 || ^4.1
Conflicts
- symfony/browser-kit: 4.1.8
- symfony/dependency-injection: 4.1.8
- symfony/doctrine-bridge: 4.3.0
- symfony/dom-crawler: 4.1.8
- symfony/framework-bundle: 4.3.0
- symfony/routing: 4.1.8
- symfony/symfony: 4.1.8
- 3.x-dev
- 2.x-dev
- v2.2.1
- v2.2.0
- v2.1.6
- v2.1.5
- v2.1.4
- v2.1.3
- v2.1.2
- v2.1.1
- v2.1.0
- v2.0.2
- v2.0.1
- v2.0.0
- v2.0.0-beta.6
- v2.0.0-beta.5
- v2.0.0-beta.4
- v2.0.0-beta.3
- v2.0.0-beta.2
- v2.0.0-beta
- dev-master / 1.3.x-dev
- v1.3.2
- v1.3.1
- v1.3.0
- v1.2.0
- v1.1.4
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.2
- v1.0.1
- v1.0.0
- dev-l10n_master
- dev-php8
- dev-example-extend-entities
This package is auto-updated.
Last update: 2024-09-11 11:38:05 UTC
README
如果您想为您的产品添加品牌,请使用此插件。使用案例
- 将品牌标志添加到您的产品页面
- 在前端或后端按品牌过滤,例如产品列表
截图
安装
步骤 1:下载插件
打开命令行,进入您的项目目录,然后执行以下命令以下载此捆绑包的最新稳定版本
$ composer require loevgaard/sylius-brand-plugin
此命令要求您全局安装Composer,如Composer文档的安装章节中所述。
步骤 2:启用插件
然后,通过将其添加到项目中 config/bundles.php
文件中注册的插件/捆绑包列表中,在 SyliusGridBundle
之前(!)启用插件
<?php # config/bundles.php return [ // ... Loevgaard\SyliusBrandPlugin\LoevgaardSyliusBrandPlugin::class => ['all' => true], Sylius\Bundle\GridBundle\SyliusGridBundle::class => ['all' => true], // ... ];
步骤 3:配置插件
# config/packages/loevgaard_sylius_brand.yaml imports: # ... - { resource: "@LoevgaardSyliusBrandPlugin/Resources/config/app/config.yaml" } # If you want to see Brand column at admin products list - uncomment next line # - { resource: "@LoevgaardSyliusBrandPlugin/Resources/config/grids/sylius_admin_product.yaml" }
# config/routes/loevgaard_sylius_brand.yaml loevgaard_sylius_brand: resource: "@LoevgaardSyliusBrandPlugin/Resources/config/routing.yaml"
步骤 4:扩展服务和实体
扩展 Product
-
如果您使用
annotations
映射<?php declare(strict_types=1); namespace App\Entity; use Doctrine\ORM\Mapping as ORM; use Loevgaard\SyliusBrandPlugin\Model\ProductInterface as LoevgaardSyliusBrandPluginProductInterface; use Loevgaard\SyliusBrandPlugin\Model\ProductTrait as LoevgaardSyliusBrandPluginProductTrait; use Sylius\Component\Core\Model\Product as BaseProduct; /** * @ORM\Entity * @ORM\Table(name="sylius_product") */ class Product extends BaseProduct implements LoevgaardSyliusBrandPluginProductInterface { use LoevgaardSyliusBrandPluginProductTrait; }
-
如果您使用
xml
映射<?php // src/Model/Product.php declare(strict_types=1); namespace App\Model; use Loevgaard\SyliusBrandPlugin\Model\ProductInterface as LoevgaardSyliusBrandPluginProductInterface; use Loevgaard\SyliusBrandPlugin\Model\ProductTrait as LoevgaardSyliusBrandPluginProductTrait; use Sylius\Component\Core\Model\Product as BaseProduct; class Product extends BaseProduct implements LoevgaardSyliusBrandPluginProductInterface { use LoevgaardSyliusBrandPluginProductTrait; // ... }
<?xml version="1.0" encoding="UTF-8"?> <!-- config/doctrine/model/Product.orm.xml --> <doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> <mapped-superclass name="App\Model\Product" table="sylius_product"> <many-to-one field="brand" target-entity="Loevgaard\SyliusBrandPlugin\Model\BrandInterface" inversed-by="products"> <join-column name="brand_id" on-delete="SET NULL" /> </many-to-one> </mapped-superclass> </doctrine-mapping>
扩展 ProductRepository
<?php # src/Doctrine/ORM/ProductRepository.php declare(strict_types=1); namespace App\Doctrine\ORM; use Loevgaard\SyliusBrandPlugin\Doctrine\ORM\ProductRepositoryInterface as LoevgaardSyliusBrandPluginProductRepositoryInterface; use Loevgaard\SyliusBrandPlugin\Doctrine\ORM\ProductRepositoryTrait as LoevgaardSyliusBrandPluginProductRepositoryTrait; use Sylius\Bundle\CoreBundle\Doctrine\ORM\ProductRepository as BaseProductRepository; class ProductRepository extends BaseProductRepository implements LoevgaardSyliusBrandPluginProductRepositoryInterface { use LoevgaardSyliusBrandPluginProductRepositoryTrait; // ... }
配置
config/services.yaml sylius_product: resources: product: classes: model: App\Model\Product # Or App\Entity\Product repository: App\Doctrine\ORM\ProductRepository
步骤 5:更新您的数据库模式
$ php bin/console doctrine:migrations:diff $ php bin/console doctrine:migrations:migrate
固定数据
-
包含预先定义的品牌固定数据以在您的开发环境中使用
# config/packages/loevgaard_sylius_brand.yaml imports: - { resource: "@LoevgaardSyliusBrandPlugin/Resources/config/app/fixtures.yaml" }
-
或编写您自己的
-
在
config/packages
文件夹中添加一个新的 yaml 文件,并将其命名为您想要的名称,例如my_own_fixtures.yaml
。 -
在此 yaml 中填写您自己的品牌固定数据,并且不要忘记在此品牌定义之前声明您的产品定义,或者使用现有产品代码。
# config/packages/my_own_fixtures.yaml sylius_fixtures: suites: my_own_brand_fixtures: fixtures: loevgaard_sylius_brand_plugin_brand: options: custom: my_brand: name: 'My brand' code: 'my-brand' images: local_image: type: logo path: images/my-brand/logo.jpg 3rd_party_plugin_image: type: black-and-white path: '@SomePlugin/Resources/images/my-brand/black-and-white.jpg' products: - product_code_1 - product_code_2 - product_code_3
请参阅
src/Resources/config/app/fixtures.yaml
中的示例。
-
-
加载您的固定数据
php bin/console sylius:fixture:load my_own_brand_fixtures
插件开发和安装及使用
要运行测试应用程序进行交互,只需输入 composer try
。
可用的Sonata块
loevgaard_sylius_brand.admin.brand.create.tab_details
loevgaard_sylius_brand.admin.brand.update.tab_details
loevgaard_sylius_brand.admin.brand.create.tab_media
loevgaard_sylius_brand.admin.brand.update.tab_media
可用事件
loevgaard_sylius_brand.menu.admin.brand.form
以自定义Brand
管理表单,就像您通常通过sylius.menu.admin.product.form
事件自定义Product
表单一样。
测试
与API玩耍
-
安装 https://stedolan.github.io/jq/(在OSX终端中输入
brew install jq
) -
获取管理员API访问令牌
SYLIUS_ADMIN_API_ACCESS_TOKEN=$(curl https://:8000/api/oauth/v2/token \ --silent --show-error \ -d "client_id"=demo_client \ -d "client_secret"=secret_demo_client \ -d "grant_type"=password \ -d "username"=api@example.com \ -d "password"=sylius-api | jq '.access_token' --raw-output)
-
进行请求
(以下示例中的
GET
请求索引/显示资源,有关创建/更新/删除与品牌相关的资源、创建附加品牌的新产品、通过API上传图像文件的详细信息,请参阅tests/Controller/*ApiTest.php
)到品牌管理API
curl https://:8000/api/v1/brands/ \ -H "Authorization: Bearer $SYLIUS_ADMIN_API_ACCESS_TOKEN"
curl https://:8000/api/v1/brands/setono/ \ -H "Authorization: Bearer $SYLIUS_ADMIN_API_ACCESS_TOKEN"
品牌图像API
curl https://:8000/api/v1/brands/setono/images/ \ -H "Authorization: Bearer $SYLIUS_ADMIN_API_ACCESS_TOKEN"
按类型获取品牌图像API
curl https://:8000/api/v1/brands/setono/images/logo/ \ -H "Authorization: Bearer $SYLIUS_ADMIN_API_ACCESS_TOKEN"
curl https://:8000/api/v1/brands/setono/images/<ID>/ \ -H "Authorization: Bearer $SYLIUS_ADMIN_API_ACCESS_TOKEN"
品牌产品API
curl https://:8000/api/v1/brands/setono/products/ \ -H "Authorization: Bearer $SYLIUS_ADMIN_API_ACCESS_TOKEN"
产品详细信息API
curl https://:8000/api/v1/products/setono-mug/ \ -H "Authorization: Bearer $SYLIUS_ADMIN_API_ACCESS_TOKEN"
对于XML输出,请将
-H "Accept: application/xml"
添加到请求中
贡献
请,在提交之前运行 composer all
以运行所有检查和测试。
通过翻译进行贡献
我们使用Sylius翻译的同一服务,即 Crowdin。您可以通过将此项目翻译成您的母语来提供帮助 ;)
谢谢!