Customer Access feature integration

Edit on GitHub
You are browsing a previous version of the document. The latest version is 202212.0.

Install Feature Core

Prerequisites

To start feature integration, overview and install the necessary features:

NAME VERSION
Spryker Core 202108.0

1) Install the required modules using Composer

Run the following command(s) to install the required modules:

composer require spryker-feature/customer-access:"202108.0" --update-with-dependencies
Verification

Make sure that the following modules were installed:

MODULE EXPECTED DIRECTORY
CustomerAccess vendor/spryker/customer-access
CustomerAccessPermission vendor/spryker/customer-access-permission
CustomerAccessStorage vendor/spryker/customer-access-storage
CustomerAccessGui vendor/spryker/customer-access-gui

2) Set up configuration

Add your custom project configuration to adjust the module behavior.

Info

These are going to be the setup content types in your system, so make sure that you cover all types of content you would like hidden from unauthenticated users.

src/Pyz/Zed/CustomerAccess/CustomerAccessConfig.php

<?php

namespace Pyz\Zed\CustomerAccess;

use Spryker\Shared\CustomerAccess\CustomerAccessConfig as SprykerSharedCustomerAccessConfig;
use Spryker\Zed\CustomerAccess\CustomerAccessConfig as SprykerCustomerAccessConfig;

class CustomerAccessConfig extends SprykerCustomerAccessConfig
{
 /**
 * @return array
 */
 public function getContentTypes(): array
 {
            return [
                     SprykerSharedCustomerAccessConfig::CONTENT_TYPE_PRICE,
                                    SprykerSharedCustomerAccessConfig::CONTENT_TYPE_ORDER_PLACE_SUBMIT,
                SprykerSharedCustomerAccessConfig::CONTENT_TYPE_ADD_TO_CART,
                    SprykerSharedCustomerAccessConfig::CONTENT_TYPE_WISHLIST,
             SprykerSharedCustomerAccessConfig::CONTENT_TYPE_SHOPPING_LIST,
            ];
       }
}
Info

The verification of this step will happen when you import the infrastructural data related to this feature.

3) Set up the database schema

Adjust the schema definition so entity changes will trigger events.

AFFECTED ENTITY TRIGGERED EVENTS
spy_unauthenticated_customer_access Entity.spy_unauthenticated_customer_access.create
Entity.spy_unauthenticated_customer_access.update
Entity.spy_unauthenticated_customer_access.delete

src/Pyz/Zed/CustomerAccess/Persistence/Propel/Schema/spy_unauthenticated_customer_access.schema.xml

<?xml version="1.0"?>
<database xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="zed" xsi:noNamespaceSchemaLocation="http://static.spryker.com/schema-01.xsd" namespace="Orm\Zed\CustomerAccess\Persistence" package="src.Orm.Zed.CustomerAccess.Persistence">
<table name="spy_unauthenticated_customer_access" idMethod="native" phpName="SpyUnauthenticatedCustomerAccess">
<behavior name="event">
<parameter name="spy_unauthenticated_customer_access_all" column="*"/>
</behavior>
</table>
</database>

Run the following commands to apply database changes and generate entity and transfer changes:

console transfer:generate
console propel:install
console transfer:generate
Verification

Make sure that the following changes by checking your database:

DATABASE ENTITY TYPE EVENT
spy_unauthenticated_customer_access table created
spy_unauthenticated_customer_access_storage table created
Verification

Make sure that the following changes in transfer objects:

TRANSFER TYPE EVENT PATH
CustomerAccess class created src/Generated/Shared/Transfer/CustomerAccessTransfer
ContentTypeAccess class created src/Generated/Shared/Transfer/ContentTypeAccessTransfer
SpyUnauthenticatedCustomerAccessEntity class created src/Generated/Shared/SpyUnauthenticatedCustomerAccessEntity
SpyUnauthenticatedCustomerAccessStorageEntityTransfer class created src/Generated/Shared/SpyUnauthenticatedCustomerAccessStorageEntity
Verification

Make sure that the changes were implemented successfully. For this purpose, trigger the following methods and make sure that the above events have been triggered:

PATH METHOD NAME
src/Orm/Zed/CustomerAccess/Persistence/SpyUnauthenticatedCustomerAccess.php prepareSaveEventName()
addSaveEventToMemory()
addDeleteEventToMemory()

3) Configure export to Redis

This step will publish tables on change (create, edit, delete) to the spy_unauthenticated_customer_access_storage and synchronize the data to Storage.

Set up event listeners

PLUGIN SPECIFICATION PREREQUISITES NAMESPACE
CustomerAccessStorageEventSubscriber Registers listeners that are responsible for publishing customer access data based on changes to customer access entities None Spryker\Zed\CustomerAccessStorage\Communication\Plugin\Event\Subscriber

src/Pyz/Zed/Event/EventDependencyProvider.php

<?php

namespace Pyz\Zed\Event;

use Spryker\Zed\CustomerAccessStorage\Communication\Plugin\Event\Subscriber\CustomerAccessStorageEventSubscriber;
use Spryker\Zed\Event\EventDependencyProvider as SprykerEventDependencyProvider;

class EventDependencyProvider extends SprykerEventDependencyProvider
{
 public function getEventSubscriberCollection()
 {
 $eventSubscriberCollection = parent::getEventSubscriberCollection();
 $eventSubscriberCollection->add(new CustomerAccessStorageEventSubscriber());

 return $eventSubscriberCollection;
 }
}
Verification

Make sure that when a product list is created, updated or deleted, they are exported (or removed to Redis and Elasticsearch accordingly.)

TARGET ENTITY EXAMPLE EXPECTED DATA IDENTIFIER
spy_unauthenticated_customer_access kv:unauthenticated_customer_access

Example Expected Data Fragment

{
								"content_type_access": [
								{
								"id_unauthenticated_customer_access": 1,
								"content_type": "price",
								"is_restricted": true
								},
								{
								"id_unauthenticated_customer_access": 2,
								"content_type": "order-place-submit",
								"is_restricted": true
								},
								{
								"id_unauthenticated_customer_access": 3,
								"content_type": "add-to-cart",
								"is_restricted": true
								},
								{
								"id_unauthenticated_customer_access": 4,
								"content_type": "wishlist",
								"is_restricted": true
								},
								{
								"id_unauthenticated_customer_access": 5,
								"content_type": "shopping-list",
								"is_restricted": true
								}
								],
								"_timestamp": 1553177014.3275149
					}

Set up re-sync features

PLUGIN SPECIFICATION PREREQUISITES NAMESPACE
CustomerAccessSynchronizationDataPlugin Allows populating empty storage table with data. None Spryker\Zed\CustomerAccessStorage\Communication\Plugin\Synchronization

src/Pyz/Zed/Synchronization/SynchronizationDependencyProvider.php

<?php

namespace Pyz\Zed\Synchronization;

use Spryker\Zed\CustomerAccessStorage\Communication\Plugin\Synchronization\CustomerAccessSynchronizationDataPlugin;
use Spryker\Zed\Synchronization\SynchronizationDependencyProvider as SprykerSynchronizationDependencyProvider;

class SynchronizationDependencyProvider extends SprykerSynchronizationDependencyProvider
{
 /**
 * @return \Spryker\Zed\SynchronizationExtension\Dependency\Plugin\SynchronizationDataPluginInterface[]
 */
 protected function getSynchronizationDataPlugins(): array
 {
 return [
 new CustomerAccessSynchronizationDataPlugin(),
 ];
 }
}

5) Import data

Add infrastructural data

PLUGIN SPECIFICATION PREREQUISITES NAMESPACE
CustomerAccessInstallerPlugin Installs configured content types None Spryker\Zed\CustomerAccess\Communication\Plugin

src/Pyz/Zed/Installer/InstallerDependencyProvider.php

<?php

namespace Pyz\Zed\Installer;

use Spryker\Zed\CustomerAccess\Communication\Plugin\CustomerAccessInstallerPlugin;
use Spryker\Zed\Installer\InstallerDependencyProvider as SprykerInstallerDependencyProvider;

class InstallerDependencyProvider extends SprykerInstallerDependencyProvider
{
 /**
 * @return \Spryker\Zed\Installer\Dependency\Plugin\InstallerPluginInterface[]
 */
 public function getInstallerPlugins()
 {
 return [
 new CustomerAccessInstallerPlugin(),
 ];
 }
}

Run the following console command to execute registered installer plugins and install infrastructural data:

console setup:init-db
Verification

Make sure that all configured content types above are saved in the database table spy_unauthenticated_customer_access with the configured content type access.

6) Set up behavior

Enable the following behaviors by registering the plugins:

PLUGIN SPECIFICATION PREREQUISITES NAMESPACE
SeePricePermissionPlugin Provides the ability to see prices on all pages None Spryker\Client\CustomerAccessPermission\Plugin
SeeOrderPlaceSubmitPermissionPlugin Provides ability to place order after going through checkout process None Spryker\Client\CustomerAccessPermission\Plugin
SeeAddToCartPermissionPlugin Provides ability to add item to cart on product detail page None Spryker\Client\CustomerAccessPermission\Plugin
SeeWishlistPermissionPlugin Provides ability to add item to wish list on product detail page None Spryker\Client\CustomerAccessPermission\Plugin
SeeShoppingListPermissionPlugin Provides ability to add item to shopping list on product detail page None Spryker\Client\CustomerAccessPermission\Plugin
CustomerAccessPermissionStoragePlugin Provides ability to fetch customer access permissions on customer login None Spryker\Client\CustomerAccessPermission\Plugin

src/Pyz/Client/Permission/PermissionDependencyProvider.php

<?php

namespace Pyz\Client\Permission;

use Spryker\Client\CustomerAccessPermission\Plugin\CustomerAccessPermissionStoragePlugin;
use Spryker\Client\CustomerAccessPermission\Plugin\SeeAddToCartPermissionPlugin;
use Spryker\Client\CustomerAccessPermission\Plugin\SeeOrderPlaceSubmitPermissionPlugin;
use Spryker\Client\CustomerAccessPermission\Plugin\SeePricePermissionPlugin;
use Spryker\Client\CustomerAccessPermission\Plugin\SeeShoppingListPermissionPlugin;
use Spryker\Client\CustomerAccessPermission\Plugin\SeeWishlistPermissionPlugin;
use Spryker\Client\Permission\PermissionDependencyProvider as SprykerPermissionDependencyProvider;

class PermissionDependencyProvider extends SprykerPermissionDependencyProvider
{
 /**
 * @return \Spryker\Client\PermissionExtension\Dependency\Plugin\PermissionStoragePluginInterface[]
 */
 protected function getPermissionStoragePlugins(): array
 {
 return [
 new CustomerAccessPermissionStoragePlugin(),
 ];
 }
 /**
 * @return \Spryker\Shared\PermissionExtension\Dependency\Plugin\PermissionPluginInterface[]
 */
 protected function getPermissionPlugins(): array
 {
 return [
 new SeePricePermissionPlugin(),
 new SeeOrderPlaceSubmitPermissionPlugin(),
 new SeeAddToCartPermissionPlugin(),
 new SeeWishlistPermissionPlugin(),
 new SeeShoppingListPermissionPlugin(),
 ];
 }
}
Verification

Make sure that everything works fine (checks should be done for not logged-in customers:

  • SeePricePermissionPlugin will show or hide prices at all pages depending on configuration value.
  • SeeOrderPlaceSubmitPermissionPlugin will allow or disallow order submitting after going through the checkout process depending on configuration value.
  • SeeAddToCartPermissionPlugin is responsible for “Add to Cart” button on PDP. It will be available or not depending on configuration value.
  • SeeWishlistPermissionPlugin takes care about “Add to Wishlist” button on PDP. It will be shown or not depending on configuration value.
  • SeeShoppingListPermissionPlugin will allow or disallow adding product to shopping list from PDP depending on configuration value.
  • CustomerAccessPermissionStoragePlugin is responsible for customer permissions retrieving.

Install feature frontend

Prerequisites

Overview and install the necessary features before beginning the integration step.

NAME VERSION
Spryker Core 202108.0

1) Add translations

Append glossary according to your configuration:

src/data/import/glossary.csv

customer.access.cannot_see_price,Please login to see the price,en_US
customer.access.cannot_see_price,Bitte melden Sie sich an um den Preis zu sehen,de_DE

Run the following console command to import data:

console data:import glossary
Verification

Make sure that in the database the configured data has been added to the spy_glossary table.