Glue API - Product Labels feature integration

Edit on GitHub

Follow the steps below to install Product Labels Feature API.

Prerequisites

Install the required features:

NAME VERSION REQUIRED SUB-FEATURE
Spryker Core 202212.0 Glue Application feature integration
Product Management 202212.0 Products API feature integration
Product Label 202212.0

1) Install the required modules

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

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

Set up the following behaviors.

Enable resources and relationships

Activate the following plugin:

PLUGIN SPECIFICATION PREREQUISITES NAMESPACE
ProductLabelsRelationshipByResourceIdPlugin Adds the product labels resource as a relationship to the 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;
use Spryker\Glue\GlueApplicationExtension\Dependency\Plugin\ResourceRelationshipCollectionInterface;

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;
    }
}

Verification

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

Send a request to http://mysprykershop.com/abstract-products/{{sku}}?include=product-labelsand verify if the abstract product with the given SKU has at least one assigned product label and the response includes relationships to the product-labels resources.