Glue API - Product Labels feature integration

Edit on GitHub

Install feature API

Prerequisites

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

Name Version
Spryker Core 2018.12.0
Product Management 2018.12.0
Product Label 2018.12.0
ProductsRestApi 2.2.3

1) Install the required modules using Composer

Run the following command to install the required modules:

composer require spryker/product-labels-rest-api:"^1.0.1" --update-with-dependencies
“Verification”

Make sure that the following module is installed:

Module Expected Directory
ProductLabelsRestApi vendor/spryker/product-labels-rest-api

2) Set up Transfer Objects

Run the following commands to generate transfer changes:

console transfer:generate
“Verification”

Make sure that the following changes are present in transfer objects:

Transfer Type Event Path
RestProductLabelsAttributesTransfer class created src/Generated/Shared/Transfer/RestProductLabelsAttributesTransfer

3) Set up Behavior

Enable resources and relationships

Implementation

Activate the following plugin:

Plugin Specification Prerequisites Namespace
ProductLabelsRelationshipByResourceIdPlugin Adds the product labels resource as a relationship to an abstract product resource. None Spryker\Glue\ProductLabelsRestApi\Plugin\GlueApplication\ProductLabelsRelationshipByResourceIdPlugin
ProductLabelsResourceRoutePlugin Registers the product labels resource. None Spryker\Glue\ProductLabelsRestApi\Plugin\GlueApplication\ProductLabelsResourceRoutePlugin
src/Pyz/Glue/GlueApplication/GlueApplicationDependencyProvider.php
<?php
 
namespace Pyz\Glue\GlueApplication;
 
use Spryker\Glue\GlueApplication\GlueApplicationDependencyProvider as SprykerGlueApplicationDependencyProvider;
use Spryker\Glue\ProductLabelsRestApi\Plugin\GlueApplication\ProductLabelsRelationshipByResourceIdPlugin;
use Spryker\Glue\ProductLabelsRestApi\Plugin\GlueApplication\ProductLabelsResourceRoutePlugin;
 
class GlueApplicationDependencyProvider extends SprykerGlueApplicationDependencyProvider
{
    /**
     * @return \Spryker\Glue\GlueApplicationExtension\Dependency\Plugin\ResourceRoutePluginInterface[]
     */
    protected function getResourceRoutePlugins(): array
    {
        return [
            new ProductLabelsResourceRoutePlugin(),
        ];
    }
 
    /**
    * @param \Spryker\Glue\GlueApplicationExtension\Dependency\Plugin\ResourceRelationshipCollectionInterface $resourceRelationshipCollection
    *
    * @return \Spryker\Glue\GlueApplicationExtension\Dependency\Plugin\ResourceRelationshipCollectionInterface
    */
    protected function getResourceRelationshipPlugins(
        ResourceRelationshipCollectionInterface $resourceRelationshipCollection
    ): ResourceRelationshipCollectionInterface {
         $resourceRelationshipCollection->addRelationship(
            ProductsRestApiConfig::RESOURCE_ABSTRACT_PRODUCTS,
            new ProductLabelsRelationshipByResourceIdPlugin()
        );
 
        return $resourceRelationshipCollection;
    }
}

Make sure the following endpoint is available: http://mysprykershop.com/product-labels/{{abstract_sku}}

Make a request to http://mysprykershop.com/abstract-products/{{sku}}?include=product-labels. An abstract product with the given SKU should have at least one assigned product label. Make sure the response includes relationships to the product-labels resources.