kermitsxb / sylius-customer-pools-plugin
Sylius 客户池管理插件。
v0.3.2
2022-05-30 09:57 UTC
Requires
- php: ^8.0
- sylius/sylius: ^1.11
Requires (Dev)
README
此插件为 Sylius 提供客户池管理功能。
仅支持 Doctrine ORM 驱动。
客户池是一组分配给特定渠道的客户集合。得益于这个概念,如果你有两个渠道,每个渠道都有一个单独的客户池,那么在渠道 A 中有账户但未在渠道 B 中注册的客户将无法使用在渠道 A 中指定的凭证登录到渠道 B(这是 Sylius 开源版中发生的行为)。此功能允许你通过多个渠道进行销售,同时创建出在完全不同的商店购物的错觉,而你仍然只需要一个管理面板。
屏幕截图
客户池
客户
安装
步骤 1:安装插件
打开命令行,进入项目目录并执行以下命令以下载此插件的最新稳定版本
$ composer require tavy315/sylius-customer-pools-plugin
此命令需要你全局安装了 Composer,具体请参考 Composer 文档中的 安装章节。
步骤 2:启用插件
然后,通过将其添加到项目中 config/bundles.php
文件中注册的插件/包列表中启用插件
<?php $bundles = [ Tavy315\SyliusCustomerPoolsPlugin\Tavy315SyliusCustomerPoolsPlugin::class => ['all' => true], ];
步骤 3:配置插件
# config/packages/tavy315_sylius_customer_pools.yaml imports: - { resource: "@Tavy315SyliusCustomerPoolsPlugin/Resources/config/app/config.yaml" }
步骤 4:自定义模型
有关 Sylius 模型自定义的更多信息,请参阅此处。
自定义你的客户模型
将 Tavy315\SyliusCustomerPoolsPlugin\Model\Customer\CustomerPoolTrait
特性添加到你的 App\Entity\Customer\Customer
类中。
-
如果你使用
注解
映射<?php // src/Entity/Customer/Customer.php namespace App\Entity\Customer; use Doctrine\ORM\Mapping as ORM; use Sylius\Component\Core\Model\Customer as BaseCustomer; use Tavy315\SyliusCustomerPoolsPlugin\Model\Customer\CustomerPoolAwareInterface; use Tavy315\SyliusCustomerPoolsPlugin\Model\Customer\CustomerPoolTrait; /** * @ORM\Entity * @ORM\Table(name="sylius_customer") */ class Customer extends BaseCustomer implements CustomerPoolAwareInterface { use CustomerPoolTrait; }
步骤 5:更新你的数据库模式
$ php bin/console doctrine:migrations:diff $ php bin/console doctrine:migrations:migrate
步骤 6:将 UserChecker 添加到 security.yaml
这将限制用户登录到具有不同客户池设置的渠道。如果客户或当前渠道未选择客户池,则将跳过检查并允许登录。
security: firewalls: shop: user_checker: tavy315_sylius_customer_pools.security.user_checker
用法
从现在起,你可以将客户池附加到任何客户。
代码质量
易于编码标准
vendor/bin/ecs check src
PHPSTAN
vendor/bin/phpstan analyse src