wemea / sylius-menu-plugin
插件允许在Sylius后台管理中管理店铺菜单
Requires
- php: ^8.0
- sylius/mailer-bundle: ^1.8 || ^2.0@beta
- sylius/sylius: ^1.12
- symfony/webpack-encore-bundle: ^1.15
Requires (Dev)
- behat/behat: ^3.6.1
- behat/mink-selenium2-driver: ^1.4
- dmore/behat-chrome-extension: ^1.3
- dmore/chrome-mink-driver: ^2.7
- ergebnis/composer-normalize: ^2.31
- friends-of-behat/mink: ^1.8
- friends-of-behat/mink-browserkit-driver: ^1.4
- friends-of-behat/mink-debug-extension: ^2.0.0
- friends-of-behat/mink-extension: ^2.4
- friends-of-behat/page-object-extension: ^0.3
- friends-of-behat/suite-settings-extension: ^1.0
- friends-of-behat/symfony-extension: ^2.1
- friends-of-behat/variadic-extension: ^1.3
- friendsofphp/php-cs-fixer: ^3.38
- friendsoftwig/twigcs: >=4
- matthiasnoback/symfony-config-test: ^4.3
- php-parallel-lint/php-parallel-lint: ^1.3
- phpro/grumphp: ^1.16
- phpspec/phpspec: ^7.2
- phpstan/extension-installer: ^1.0
- phpstan/phpstan: ^1.8.1
- phpstan/phpstan-doctrine: 1.3.37
- phpstan/phpstan-strict-rules: ^1.3.0
- phpstan/phpstan-webmozart-assert: ^1.2.0
- phpunit/phpunit: ^9.5
- polishsymfonycommunity/symfony-mocker-container: ^1.0
- sylius-labs/coding-standard: ^4.2
- symfony/browser-kit: ^5.4 || ^6.0
- symfony/debug-bundle: ^5.4 || ^6.0
- symfony/dotenv: ^5.4 || ^6.0
- symfony/flex: ^2.2.2
- symfony/intl: ^5.4 || ^6.0
- symfony/web-profiler-bundle: ^5.4 || ^6.0
- vimeo/psalm: 5.9.0
Conflicts
- symfony/framework-bundle: 6.2.8
This package is auto-updated.
Last update: 2024-09-23 11:57:13 UTC
README
Sylius菜单插件
插件允许从后台管理中管理商店菜单
功能
- 使用命令创建/删除菜单
wemea:menu:create <code>
wemea:menu:delete <code>
- 管理菜单的可见性
- 管理菜单项(链接、标题、描述、顺序/优先级、图标)
- 默认链接类型
- 自定义:将任何链接放入其中
- 产品:选择链接到产品,路径会动态生成
- 分类:选择链接到分类,路径会动态生成
摘要
安装
-
使用Composer安装插件
composer require wemea/sylius-menu-plugin
-
如果您尚未自动添加,请将以下内容添加到您的
config/bundles.php
Wemea\SyliusMenuPlugin\WemeaSyliusMenuPlugin::class => ['all' => true],
-
在您的
config/packages/_sylius.yaml
中导入配置imports: [...] - { resource: "@WemeaSyliusMenuPlugin/Resources/config/app/config.yml" }
-
在您的
config/routes.yml
中导入路由wemea_menu_routing: resource: "@WemeaSyliusMenuPlugin/Resources/config/routing.yml"
-
将菜单添加到您的模板中。有关更多信息,请参阅使用 - 添加菜单
-
运行集成测试。
⚠️ 仅针对管理员部分有集成测试。 您 应该添加您自己的商店部分的测试。
使用
添加菜单
技巧 :
只能使用Symfony命令创建和删除菜单,以避免商店管理员意外删除菜单并阻止UI。在BO中可以禁用菜单。
-
创建新菜单
运行
bin/console wemea:menu:create <your_menu_code>
您可以通过运行
bin/console wemea:menu:create --help
来查看可用选项 -
在您的模板中添加此菜单:在您想引入菜单的页面(s)中添加此内容
{{ render(controller('wemea_sylius_menu.controller.render_menu::renderAction', { 'code': '<your_menu_code>' })) }}
默认情况下,菜单使用
@WemeaSyliusMenuPlugin/Shop/Menu/_default.html.twig
。如果您想使用自己的模板,请在渲染时添加模板选项{{ render(controller('wemea_sylius_menu.controller.render_menu::renderAction', { 'code': '<your_menu_code>', 'template': '@App/your/menu/template.html.twig' })) }}
-
添加behat测试以检查菜单集成
更改默认资源路由映射
如果您更改了应用程序的默认路由,则需要更改链接资源的路由映射。您可以在 config/packages/wemea_sylius_menu.yml
中使用此配置进行操作
## Default configuration wemea_sylius_menu: resource_path_resolver_configuration: custom: # route is null for custom type because is not use the router resolver route: null parameters: [] product: route: 'sylius_shop_product_show' parameters: slug: 'getSlug' taxon: route: 'sylius_shop_product_index' parameters: slug: 'getSlug'
参数节点是路由参数和访问资源属性的方法名称之间的关联数组
向另一个资源添加新链接类型
此插件允许创建新的资源链接。您可能需要它来重定向到自定义资源(例如品牌,我们使用此示例进行说明)
-
覆盖默认MenuLink实体
<?php declare(strict_types=1); namespace App\Entity; use Doctrine\ORM\Mapping as ORM; use Wemea\SyliusMenuPlugin\Entity\MenuLink as BaseMenuLink; /** * @ORM\Entity * @ORM\Table(name="wemea_menu_link") */ class MenuLink extends BaseMenuLink { //Add your new property /** * @var Brand|null $brand * @ORM\ManyToOne(targetEntity="Brand") * @ORM\JoinColumn(name="brand_id", referencedColumnName="id") */ protected $brand; //add this property name to know properties public static function getLinkProperties() : array{ return array_merge( parent::getLinkProperties(), ['brand'] // your property name ); } }
-
在
config/packages/_sylius.yml
中将此实体声明为资源模型sylius_resource: resources: wemea_sylius_menu.menu_link: classes: model: App\Entity\MenuLink
-
为
Wemea\SyliusMenuPlugin\Form\Type\MenuLinkType
添加表单扩展(自动完成?)选择类型。检查官方文档以创建表单扩展。此字段不应该被映射
$builder ->add('brand', BrandAutocompleteChoiceType::class, [ 'mapped' => false, ]);
此新字段将自动添加到模板中。默认情况下,它使用:
{{ form_row(form.brand) }}
。如果您想使用自定义模板,您可以创建
templates/bundles/WemeaSyliusMenuPlugin/Admin/MenuLink/Form/Fields/_<field_name>.html.twig
并使用具有属性form
的字段。 -
在
config/packages/wemea_sylius_menu.yml
文件中添加路由配置wemea_sylius_menu: resource_path_resolver_configuration: # Use property name as key brand: route: 'app_shop_brand_show' parameters: [ 'code' => 'getCode' ]
-
清除缓存并进行迁移以更新数据库模式
使用菜单样本
如果您需要程序化加载菜单,可以使用如下菜单固定数据
sylius_fixtures: suites: <suite_name>: fixtures: menu: name: menu options: custom: - code: <menu_code> visibility: public # use private or public value (is public by default) enabled: true # menu is enabled by default #Transltion accept associative array of [locale => [title => <expected title> ]] translations: en_US: title: The title #channels is array of channels code channels: ['FASHION_WEB'] #Define items of menu items: - target: _self # target accept _self or _blank. By default is _self #Transaltions is defined like menu translation with 'description' optional node translations: en_US: title: <title> description: <description> # link node allow to defined the target resource of menu item link: # for a custom link, use associative array of locale => path custom_link: en_US: /the/expected/path # for a product link use the code of target product product_code: <product_code> # for a taxon link use the code of target product taxon_code: <taxon_code>
要查看完整的实现示例,可以检查文件 footer_help_menu.yaml。
问题/待完成工作
- 为菜单项图片添加固定数据
- 添加将锚点作为自定义链接的功能
- 在商店使用本地化URL的情况下,管理自定义链接的当前语言环境的路径解析