PHP code example of thelia / customer-group-module

1. Go to this page and download the library: Download thelia/customer-group-module library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

thelia / customer-group-module example snippets


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

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

$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");

use CustomerGroup\Model\CustomerQuery as CustomerGroupCustomerQuery;

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

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");