thelia/customer-group-module

安装: 576

依赖项: 1

建议者: 0

安全: 0

星标: 0

关注者: 9

分支: 4

开放问题: 0

类型:thelia-module

0.1.5 2015-10-28 16:45 UTC

This package is auto-updated.

Last update: 2024-09-14 22:56:44 UTC


README

本模块添加客户组功能,您可以将客户放入这些组中。

安装

手动安装

  • 将模块复制到 <thelia_root>/local/modules/ 目录,并确保模块名称为 CustomerGroup
  • 在 Thelia 管理面板中激活它

Composer

在您的 Thelia 主要 composer.json 文件中添加它

composer require thelia/customer-group-module:~0.1

配置

使用客户组的模块必须在模块配置目录中的 customer-group.xml 文件中定义它们。当模块被激活时,将创建这些组。

可以将一个组定义为默认组。所有新客户将被自动添加到该组。

<?xml version="1.0" encoding="UTF-8" ?>
<customergroups xmlns="urn:thelia:module:customer-group">
    <customergroup code="customer">
        <descriptive locale="en_US">
            <title>Customer</title>
            <description>Basic customer<description>
        </descriptive>
        <descriptive locale="fr_FR">
            <title>Client</title>
            <description>Client de base<description>
        </descriptive>
    </customergroup>

    <customergroup code="vip">
        <descriptive locale="en_US">
            <title>VIP</title>
            <description>VIP customer !<description>
        </descriptive>
        <descriptive locale="fr_FR">
            <title>VIP</title>
            <description>Client VIP !<description>
        </descriptive>
    </customergroup>

    <default>customer</default>
</customergroups>

事件

应使用事件来执行与客户组相关的操作。

CustomerGroup\Event\CustomerGroupEvents 类包含此模块的事件名称常量。事件类也位于 CustomerGroup\Event 命名空间中。

将客户添加到组中

$event = new AddCustomerToCustomerGroupEvent();
$event->setCustomerId($myCustomer->getId());
$event->setCustomerGroupId($myGroup->getId());

$dispatcher->dispatch(
    CustomerGroupEvents::ADD_CUSTOMER_TO_CUSTOMER_GROUP,
    $event
);

处理器

customer_group.handler 服务提供检查客户是否属于某个组的功能。请参阅 CustomerGroupHandler 类以获取可用方法。

获取处理器(服务)

$groupHandler = $container->get("customer_group.handler");

获取会话客户的客户组信息

// get customerGroup of the current customer (session)
$groupHandler->getGroup();
// get customerGroup code of the current customer (session)
$groupHandler->checkGroupCode();

检查客户是否属于某个组

// check a customer
$groupHandler->checkCustomerHasGroup($myCustomer, "vip");

// check the customer currently logged-in
$groupHandler->checkGroup("vip");

循环

customergroup

此循环列出客户组。

输入参数

order 可以是以下之一

  • position(默认)
  • position-reverse
  • id
  • id-reverse
  • code
  • code-reverse
  • title
  • title-reverse
  • is_default
  • is_default-reverse

输出变量

customercustomergroup

此组列出客户与客户组之间的关联。

输入参数

输出变量

customer

此模块还向客户循环添加组信息,并允许通过组过滤客户。

附加输入参数

附加输出变量

查询

CustomerQuery

本模块提供了一个扩展基本 Thelia 查询并提供按组过滤客户方法的 CustomerQuery 类。

它可以替代基本 CustomerQuery 使用。

use CustomerGroup\Model\CustomerQuery as CustomerGroupCustomerQuery;

$customers = CustomerGroupCustomerQuery::create()
    ->filterByCustomerGroup("myGroup")
    ->find();

或通过使用静态方法将其与您自己的查询类混合。这些方法接受 ModelCriteria 查询类并在其上操作。

它们假定客户表已经存在于查询作用域中,因此您的查询必须例如扩展 CustomerQuery 或将客户表连接起来。

use CustomerGroup\Model\CustomerQuery as CustomerGroupCustomerQuery;

// MyQuery extends CustomerQuery
// or MyQuery has a join to the customer table somewhere
$myQuery = MyQuery::create();

CustomerGroupCustomerQuery::addCustomerGroupFilter($myQuery, "myGroup");