Merchant Product Restrictions feature integration

Edit on GitHub

Install Feature Core

Prerequisites

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

Name Version
Spryker Core 201903.0
Product Lists 201903.0

1) Install the required modules using Composer

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

composer require spryker-feature/merchant-product-restrictions:"^201903.0" --update-with-dependencies
Verification
Make sure that the following modules were installed:
ModuleExpected Directory
`MerchantRelationshipProductList``vendor/spryker/merchant-relationship-product-list`
`MerchantRelationshipProductListDataImport``vendor/spryker/merchant-relationship-product-list-data-import`
`MerchantRelationshipProductListGui``vendor/spryker/merchant-relationship-product-list-gui`

2) Set up Database Schema

Run the following commands to apply database changes, as well as 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_product_list.fk_merchant_relationship`columncreated

3) Import Data

Import Merchant Relationship to Product Lists

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

merchant_relation_key,product_list_key
mr-008,pl-001
mr-008,pl-002
mr-008,pl-003
mr-009,pl-004
mr-010,pl-005
mr-011,pl-006
mr-011,pl-007
mr-011,pl-008
Column REQUIRED? Data Type Data Example Data Explanation
merchant_relation_key mandatory string mr-008 Identifier of merchant relations. The merchant relations must exist already.
product_list_key mandatory string pl-001 Identifier of product lists. The product lists must exist already.

Register the following plugin to enable data import:

Plugin Specification Prerequisites Namespace
MerchantRelationshipProductListDataImportPlugin Imports basic product list data into the database.
  • Merchant relations must be imported first.
  • Product lists must be imported first.
Spryker\Zed\MerchantRelationshipProductListDataImport\Communication\Plugin
src/Pyz/Zed/DataImport/DataImportDependencyProvider.php
<?php

namespace Pyz\Zed\DataImport;

use Spryker\Zed\DataImport\DataImportDependencyProvider as SprykerDataImportDependencyProvider;
use Spryker\Zed\MerchantRelationshipProductListDataImport\Communication\Plugin\MerchantRelationshipProductListDataImportPlugin;

class DataImportDependencyProvider extends SprykerDataImportDependencyProvider
{
	/**
	 * @return array
	 */
	protected function getDataImporterPlugins(): array
	{
		return [
			new MerchantRelationshipProductListDataImportPlugin(),
		];
	}
}    

Run the following console command to import data:

console data:import merchant-relationship-product-list
Verification
Make sure that the configured data are added to the `spy_product_list` table in the database.

4) Set up Behavior

Activate the following plugins:

Plugin Specification Prerequisites Namespace
ProductListCustomerTransferExpanderPlugin
  • Expands the customer transfer object with their assigned product lists.
  • The product list information is based on the customer’s merchant relationship.
None Spryker\Zed\MerchantRelationshipProductList\Communication\Plugin\Customer
MerchantRelationshipProductListOwnerTypeFormExpanderPlugin
  • Provides the merchant relationship product list owner type.
  • Provides selectable merchant relationship options to assign to product lists.
None Spryker\Zed\MerchantRelationshipProductListGui\Communication\Plugin\ProductListGuiExtension
MerchantRelationshipTableExpanderPlugin Provides table header, config and data extensions for product lists with merchant relationship owner type. None Spryker\Zed\MerchantRelationshipProductListGui\Communication\Plugin\ProductListGuiExtension
src/Pyz/Zed/Customer/CustomerDependencyProvider.php
<?php

namespace Pyz\Zed\Customer;

use Spryker\Zed\Customer\CustomerDependencyProvider as SprykerCustomerDependencyProvider;
use Spryker\Zed\MerchantRelationshipProductList\Communication\Plugin\Customer\ProductListCustomerTransferExpanderPlugin;

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

src/Pyz/Zed/ProductListGui/ProductListGuiDependencyProvider.php
<?php

namespace Pyz\Zed\ProductListGui;

use Spryker\Zed\MerchantRelationshipProductListGui\Communication\Plugin\ProductListGuiExtension\MerchantRelationshipProductListOwnerTypeFormExpanderPlugin;
use Spryker\Zed\MerchantRelationshipProductListGui\Communication\Plugin\ProductListGuiExtension\MerchantRelationshipTableExpanderPlugin;
use Spryker\Zed\ProductListGui\ProductListGuiDependencyProvider as SprykerProductListGuiDependencyProvider;

class ProductListGuiDependencyProvider extends SprykerProductListGuiDependencyProvider
{
	/**
	 * @return \Spryker\Zed\ProductListGuiExtension\Dependency\Plugin\ProductListOwnerTypeFormExpanderPluginInterface[]
	 */
	protected function getProductListOwnerTypeFormExpanderPlugins(): array
	{
		return [
			new MerchantRelationshipProductListOwnerTypeFormExpanderPlugin(),
		];
	}

	/**
	 * @return \Spryker\Zed\ProductListGuiExtension\Dependency\Plugin\ProductListTableConfigExpanderPluginInterface[]
	 */
	protected function getProductListTableConfigExpanderPlugins(): array
	{
		return [
			new MerchantRelationshipTableExpanderPlugin(),
		];
	}

	/**
	  * @return \Spryker\Zed\ProductListGuiExtension\Dependency\Plugin\ProductListTableDataExpanderPluginInterface[]
	 */
	protected function getProductListTableDataExpanderPlugins(): array
		{
		return [
			new MerchantRelationshipTableExpanderPlugin(),
		];
		}

		/**
		 * @return \Spryker\Zed\ProductListGuiExtension\Dependency\Plugin\ProductListTableDataExpanderPluginInterface[]
		 */
		protected function getProductListTableHeaderExpanderPlugins(): array
		{
			return [
				new MerchantRelationshipTableExpanderPlugin(),
		];
	}
}

Verification
Make sure that when creating or editing a product list in Zed, you can select the merchant relationship as an owner type and see the selected value in the list of product lists.

Also, make sure that when a customer (with an assigned merchant relationship that has assigned product lists) logs in, they see products only according to their product list restrictions.