thelia / customer-scope-module
Requires
- thelia/installer: ~1.0
This package is auto-updated.
Last update: 2024-09-14 22:10:11 UTC
README
提供一种机制以将客户与实体关联起来。
安装
手动安装
- 将模块复制到
<thelia_root>/local/modules/
目录中,并确保模块名称为 CustomerScope。 - 在 Thelia 管理面板中激活它
Composer
将其添加到您主要的 Thelia composer.json 文件中
composer require thelia/customer-scope-module:~0.1
概念
一个 范围 是客户可以拥有的关联类型。它由一个代码和将关联的实体类定义。可以使用由 Propel 生成的任何模型类来创建一个范围。
范围必须与一个 范围组 关联。
客户可以与具有范围的类的一个特定实体实例关联,创建一个 客户范围。客户可以与任何数量的实体在任意数量的范围内关联。这种关联的意义取决于您的业务逻辑。
例如,假设您管理实体店铺,想要将客户与他们关联起来。您可以使用范围来完成这个任务。
假设您有一个 Store
类来表示您的店铺,您可以创建
- 使用
Store
类创建一个store
范围 - 一个
places
范围组来包含store
范围
然后您可以将客户与 Store
类的任何实例关联,然后在您的应用程序中轻松检查您的客户与哪些店铺关联。
用法
目前,范围和范围组必须直接插入到数据库中。例如,您可以在模块激活时在特定于您站点的模块中这样做。
处理程序
客户范围处理程序服务允许您向范围添加客户,并检查客户属于哪些范围。
它在容器中以 customerscope.customerscope.handler
的 ID 注册。请参阅 CustomerScopeHandler
类以获取可用方法。
循环
customer-scope
还有一个循环可用于访问客户范围。
输入参数
输出参数
查询
CustomerQuery
此模块提供了一个扩展基本 Thelia 查询并提供按范围过滤客户方法的 CustomerQuery
类。
它可以替换基本 CustomerQuery 使用。
use CustomerScope\Model\CustomerScope as CustomerScopeCustomerQuery; $customers = CustomerScopeCustomerQuery::create() ->filterByScope([ "ScopeEntity" => "myScope", "EntityId" => $myEntity->getId(), ]) ->find();
或者通过使用静态方法与您自己的查询类混合使用。这些方法接受一个 ModelCriteria
查询类,并在其中执行操作。
它们假设客户表已经存在于查询范围内,因此您的查询必须扩展 CustomerQuery
或与客户表进行连接。
use CustomerScope\Model\CustomerScope as CustomerScopeCustomerQuery; // MyQuery extends CustomerQuery // or MyQuery has a join to the customer table somewhere $myQuery = MyQuery::create(); CustomerScopeCustomerQuery::addScopeFilter( $myQuery, [ "ScopeEntity" => "myScope", "EntityId" => $myEntity->getId(), ] );