asdoria / AsdoriaSyliusProductCustomerGroup

asdoria sylius product customer group plugin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Example of a product's customer group customization

Asdoria Product Product Customer Group Plugin

Manage which user can access certain Products by whitelisting Customer Groups for each item in your catalog

Features

  • Use your Customer Groups to filter which products your users can access
  • Create a whitelist of Groups for each product

Example of a product's groups whitelisting

Example of a product's groups whitelisting

Creating a Customer Group and setting which Groups are authorized to access a product

Installation


  1. Add the repository to composer.json
"repositories": [
    {
    "type": "git",
    "url": "https://github.com/asdoria/AsdoriaSyliusProductCustomerGroup.git"
    }
],
  1. run composer require asdoria/sylius-product-customer-group-plugin

  2. Add the bundle in config/bundles.php. You must put it ABOVE SyliusGridBundle

Asdoria\SyliusProductCustomerGroupPlugin\AsdoriaSyliusProductCustomerGroupPlugin::class => ['all' => true],

4.In src/Entity/Product/Product.php. Import the following classes, traits and methods.

use Sylius\Component\Core\Model\Product as BaseProduct;

use Asdoria\SyliusProductCustomerGroupPlugin\Model\Aware\CustomerGroupsAwareInterface;
use Asdoria\SyliusProductCustomerGroupPlugin\Traits\CustomerGroupsTrait;

class Product extends BaseProduct implements CustomerGroupsAwareInterface
{
    use CustomerGroupsTrait;
    
    public function __construct()
    {
        parent::__construct();
        $this->initializeCustomerGroupsCollection();
    }
    
    ...
}

5.In src/Entity/Customer/CustomerGroup.php. Import the following classes, traits and methods.

use Asdoria\SyliusProductCustomerGroupPlugin\Model\Aware\ProductsAwareInterface;
use Asdoria\SyliusProductCustomerGroupPlugin\Traits\ProductsTrait;
use Doctrine\ORM\Mapping as ORM;
use Sylius\Component\Customer\Model\CustomerGroup as BaseCustomerGroup;

/**
 * @ORM\Entity
 * @ORM\Table(name="sylius_customer_group")
 */
class CustomerGroup extends BaseCustomerGroup implements ProductsAwareInterface
{
    use ProductsTrait;
    public function __construct()
    {
        $this->initializeProductsCollection();
    }
    ...
}
  1. run php bin/console do:mi:mi to update the database schema

  2. Add the additional Product xml mapping in src/Resources/config/doctrine/Product.orm.xml

<?xml version="1.0" encoding="UTF-8"?>

<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
                                      http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
    
    <mapped-superclass name="Product">
        <many-to-many field="customerGroups" target-entity="Sylius\Component\Customer\Model\CustomerGroupInterface">
            <join-table name="asdoria_products_customer_groups">
                <join-columns>
                    <join-column name="product_id" referenced-column-name="id" />
                </join-columns>
                <inverse-join-columns>
                    <join-column name="customer_group_id" referenced-column-name="id" />
                </inverse-join-columns>
            </join-table>
        </many-to-many>
    </mapped-superclass>
    
</doctrine-mapping>
  1. Copy the template override from the plugin directory

From: [shop_dir]/vendor/asdoria/sylius-product-customer-group-plugin/src/Resources/views/bundles/SyliusShopBundle/Product/Box/_content.html.twig

To: [shop_dir]/templates/bundles/SyliusShopBundle/Product/Box/_content.html.twig

Linux CMD : cp -r vendor/asdoria/sylius-product-customer-group-plugin/src/Resources/views/bundles/SyliusShopBundle/Product/Box templates/bundles/SyliusShopBundle/Product/Box


Demo

If you want to try to create pictograms, go on the admin authentication page and connect with:

Login: asdoria
Password: asdoria

Then go on "Groups" in the back office and follow usage lines below.

Note that we have developed several other open source plugins for Sylius, whose demos and documentation are listed on the following page.

Usage

  1. Create or use existing Customer Groups
  2. Go to a product's configuration page and enter the "Customer Groups" tab
  3. Select any Group that will gain access to the product

About

asdoria sylius product customer group plugin


Languages

Language:PHP 80.3%Language:JavaScript 12.9%Language:Twig 6.8%