Alternative products + Product Label feature integration

Edit on GitHub

Install feature core

Prerequisites

Please review and install the necessary features before beginning the integration.

NAME VERSION
Alternative Products 202108.0
Product Label 202108.0

1) Install the required modules using Composer

Run the following command to install the required modules:

composer require spryker/product-alternative-product-label-connector:"^1.0.0" --update-with-dependencies
Verification

Make sure that the following modules have been installed:

MODULE EXPECTED DIRECTORY
ProductAlternativeProductLabelConnector vendor/spryker/product-alternative-product-label-connector

2) Import data

Add infrastructural data

PLUGIN SPECIFICATION PREREQUISITES NAMESPACE
ProductAlternativeProductLabelConnectorInstallerPlugin Installs the configured infrastructural alternative product labels. None Spryker\Zed\ProductAlternativeProductLabelConnector\Communication\Plugin\Installer

Add the following to your project:

src/Pyz/Zed/Installer/InstallerDependencyProvider.php

<?php
 
namespace Pyz\Zed\Installer;
 
use Spryker\Zed\Installer\InstallerDependencyProvider as SprykerInstallerDependencyProvider;
use Spryker\Zed\ProductAlternativeProductLabelConnector\Communication\Plugin\Installer\ProductAlternativeProductLabelConnectorInstallerPlugin;
 
class InstallerDependencyProvider extends SprykerInstallerDependencyProvider
{
	/**
	 * @return \Spryker\Zed\Installer\Dependency\Plugin\InstallerPluginInterface[]
	 */
	public function getInstallerPlugins()
	{
		return [
			new ProductAlternativeProductLabelConnectorInstallerPlugin(),
		];
	}
}

Run the following console command to:

  • Execute registered installer plugins
  • Install the infrastructural data
console setup:init-db
Verification

Make sure that the configured infrastructural alternative product label has been added to the spy_product_label table in the database.

3) Set up behavior

Setup alternative products labels workflow

Enable the following behavior types by registering the plugins:

PLUGIN SPECIFICATION PREREQUISITES NAMESPACE
PostProductAlternativeCreatePlugin After the product alternative is created, adds product alternatives availability label to the abstract product. None Spryker\Zed\ProductAlternativeProductLabelConnector\Communication\Plugin
PostProductAlternativeDeletePlugin After the product alternative is deleted, removes product alternatives availability label from the abstract product. None Spryker\Zed\ProductAlternativeProductLabelConnector\Communication\Plugin
ProductAlternativeLabelUpdaterPlugin Used to persist alternative product label relation changes into the database.
The plugin is called when the ProductLabelRelationUpdaterConsole command is executed.
None Spryker\Zed\ProductAlternativeProductLabelConnector\Communication\Plugin

src/Pyz/Zed/ProductAlternative/ProductAlternativeDependencyProvider.php

<?php

namespace Pyz\Zed\ProductAlternative;
 
use Spryker\Zed\ProductAlternativeProductLabelConnector\Communication\Plugin\PostProductAlternativeCreatePlugin;
use Spryker\Zed\ProductAlternativeProductLabelConnector\Communication\Plugin\PostProductAlternativeDeletePlugin;
use Spryker\Zed\ProductAlternative\ProductAlternativeDependencyProvider as SprykerProductAlternativeDependencyProvider;
 
class ProductAlternativeDependencyProvider extends SprykerProductAlternativeDependencyProvider
{
    /**
     * @return \Spryker\Zed\ProductAlternativeExtension\Dependency\Plugin\PostProductAlternativeCreatePluginInterface[]
     */
    protected function getPostProductAlternativeCreatePlugins(): array
    {
        return [
            new PostProductAlternativeCreatePlugin(),
        ];
    }
 
    /**
     * @return \Spryker\Zed\ProductAlternativeExtension\Dependency\Plugin\PostProductAlternativeDeletePluginInterface[]
     */
    protected function getPostProductAlternativeDeletePlugins(): array
    {
        return [
            new PostProductAlternativeDeletePlugin(),
        ];
    }
}

src/Pyz/Zed/ProductLabel/ProductLabelDependencyProvider.php

<?php
 
namespace Pyz\Zed\ProductLabel;
 
use Spryker\Zed\ProductAlternativeProductLabelConnector\Communication\Plugin\ProductAlternativeLabelUpdaterPlugin;
use Spryker\Zed\ProductLabel\ProductLabelDependencyProvider as SprykerProductLabelDependencyProvider;
 
class ProductLabelDependencyProvider extends SprykerProductLabelDependencyProvider
{
    /**
     * @return \Spryker\Zed\ProductLabel\Dependency\Plugin\ProductLabelRelationUpdaterPluginInterface[]
     */
    protected function getProductLabelRelationUpdaterPlugins()
    {
        return [
            new ProductAlternativeLabelUpdaterPlugin(),
        ];
    }
}
Verification

Make sure that:

  • When you add product alternatives, it adds the corresponding label to the product.
  • When you remove product alternatives, it removes the corresponding label from the product.