Business on Behalf feature integration

Edit on GitHub

Install Feature Core

Prerequisites

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

Name Version
Spryker Core 2018.11.0
Company Account 2018.11.0
Verification
Make sure that the following modules were installed:
ModuleExpected Directory
`BusinessOnBehalf``vendor/spryker/business-on-behalf`
`BusinessOnBehalfDataImport``vendor/spryker/business-on-behalf-data-import`

1) Set up Database Schema and Transfer Objects

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 have been applied by checking your database:
Database EntityTypeEvent
`spy_company_user.is_default`columncreated
Verification
Make sure that the following changes in transfer objects have been applied:
TransferTypeEventPath
`Customer.isOnBehalf`propertycreated`src/Generated/Shared/Transfer/CustomerTransfer`
`CompanyUser.isDefault`propertycreated`src/Generated/Shared/Transfer/CompanyUserTransfer`

2) Import Data

Import Business On Behalf Company Users

Info
Company user data import and business on behalf data import have currently very similar structure, however, both importers represent a different concept.
Include only business on behalf company users in the current data import step and do not mix data with company user data importer.

Prepare your data according to your requirements using our demo data:

vendor/spryker/business-on-behalf-data-import/data/import/company_user.csv
customer_reference,company_key,business_unit_key,default
DE--6,BoB-Hotel-Mitte,business-unit-mitte-1,0
DE--6,BoB-Hotel-Mitte,business-unit-mitte-2,0
DE--6,BoB-Hotel-Mitte,business-unit-mitte-3,0
DE--7,BoB-Hotel-Jim,business-unit-jim-1,0
DE--7,BoB-Hotel-Mitte,business-unit-mitte-1,0
DE--7,BoB-Hotel-Kudamm,business-unit-kudamm-1,0
DE--7,spryker_systems,spryker_systems_HQ,0

Column Is obligatory? Data type Data example Data explanation
customer_reference mandatory string DE–6 The company user will be connected to this customer.
company_key mandatory string BoB-Hotel-Mitte The company user will be connected to this company.
business_unit_key mandatory string business-unit-mitte-1 The company user will be connected to this business unit.
default mandatory bool integer 0 Decides if this is the default company user of the customer.

Register the following plugins to enable data import:

Plugin Specification Prerequisites Namespace
BusinessOnBehalfCompanyUserDataImportPlugin Imports business on behalf company users.
  • Expects customers to be in database already
  • Expects companies to be in the database already
  • Expects business units to be in the database already
Spryker\Zed\BusinessOnBehalfDataImport\Communication\Plugin\DataImport
src/Pyz/Zed/DataImport/DataImportDependencyProvider.php
 <?php

namespace Pyz\Zed\DataImport;

use Spryker\Zed\DataImport\DataImportDependencyProvider as SprykerDataImportDependencyProvider;
use Spryker\Zed\BusinessOnBehalfDataImport\Communication\Plugin\DataImport\BusinessOnBehalfCompanyUserDataImportPlugin;

class DataImportDependencyProvider extends SprykerDataImportDependencyProvider
{
 protected function getDataImporterPlugins(): array
 {
 return [
 new BusinessOnBehalfCompanyUserDataImportPlugin(),
 ];
 }
} 

Run the following console command to import data:

console data:import company-user-on-behalf
Verification
Make sure that in the database that the configured data are added to the `spy_company_user table`.

3) Set up Behavior

Set up Customer Transfer Expanders

Enable the following behaviors by registering the plugins:

Plugin Specification Prerequisites Namespace
DefaultCompanyUserCustomerTransferExpanderPlugin Sets default company user for a business on behalf customer if no company user was selected yet. None Spryker\Zed\BusinessOnBehalf\Communication\Plugin\Customer
IsOnBehalfCustomerTransferExpanderPlugin Sets CustomerTransfer.IsOnBehalf property so other features can determine if the selected company user is a business on behalf company user. None Spryker\Zed\BusinessOnBehalf\Communication\Plugin\Customer
src/Pyz/Zed/Stock/StockDependencyProvider.php
<?php

namespace Pyz\Zed\Customer;

use Spryker\Zed\Customer\CustomerDependencyProvider as SprykerCustomerDependencyProvider;
use Spryker\Zed\BusinessOnBehalf\Communication\Plugin\Customer\DefaultCompanyUserCustomerTransferExpanderPlugin;
use Spryker\Zed\BusinessOnBehalf\Communication\Plugin\Customer\IsOnBehalfCustomerTransferExpanderPlugin;

class CustomerDependencyProvider extends SprykerCustomerDependencyProvider
{
/**
* @return \Spryker\Zed\Customer\Dependency\Plugin\CustomerTransferExpanderPluginInterface[]
*/
protected function getCustomerTransferExpanderPlugins()
{
return [
new IsOnBehalfCustomerTransferExpanderPlugin(),
new DefaultCompanyUserCustomerTransferExpanderPlugin(),
];
}
} 

Verification
To check that the step has been completed correctly:
Log in with a customer who has multiple company users and a default company user.
Check in the session if the default company user was assigned to the customer.
Check in the session if the IsOnBehalf property is set correctly for the customer.

Install feature frontend

Prerequisites

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

Name Version
Spryker Core E-commerce 2018.11.0
Customer Account Management 2018.11.0
Company Account 2018.11.0
Verification
Make sure that the following modules were installed:
ModuleExpected Directory
`BusinessOnBehalfWidget``vendor/spryker-shop/business-on-behalf-widget`

1) Add Translations

Append glossary according to your configuration:

src/data/import/glossary.csv
business_on_behalf_widget.no_selected_company,No selected company,en_US
business_on_behalf_widget.no_selected_company,Kein Unternehmen ausgewählt,de_DE
business_on_behalf_widget.change_company_user,Change Company User,en_US
business_on_behalf_widget.change_company_user,Firmenbenutzer Profil ändern,de_DE
company_user.business_on_behalf.error.company_not_active,"You can not select this company user, company is not active.",en_US
company_user.business_on_behalf.error.company_not_active,"Sie können diesen Firmennutzer nicht auswählen da die Firma inaktiv ist",de_DE
company_user.business_on_behalf.error.company_user_invalid,"You can not select this company user, it is invalid.",en_US
company_user.business_on_behalf.error.company_user_invalid,"Sie können diesen Firmennutzer nicht auswählen da er ungültig ist",de_DE 

Run the following console command to import the data:

console data:import glossary
Verification
Make sure that in the database the configured data are added to the `spy_glossary` table.

2) Set up Widgets

Enable the following global widget:

Widget Description Namespace
BusinessOnBehalfStatusWidget Displays the selected company users and allows for business on behalf customers to change it through a link. `SprykerShop\Yves\BusinessOnBehalfWidget
src/Pyz/Yves/ShopApplication/ShopApplicationDependencyProvider.php
<?php

namespace Pyz\Yves\ShopApplication;

use SprykerShop\Yves\BusinessOnBehalfWidget\Widget\BusinessOnBehalfStatusWidget;
use SprykerShop\Yves\ShopApplication\ShopApplicationDependencyProvider as SprykerShopApplicationDependencyProvider;

class ShopApplicationDependencyProvider extends SprykerShopApplicationDependencyProvider
{
	/**
	 * @return string[]
	 */
	protected function getGlobalWidgets(): array
	{
		return [
			BusinessOnBehalfStatusWidget::class,
		];
	}
} 

Run the following command to enable Javascript and CSS changes:

console frontend:yves:build 
Verification
Log in with a business on behalf customer and see the selected company user status widget in the top menu.