Install the Category Management Glue API

Edit on GitHub

This document describes how to install the Category Management Glue API feature.

Prerequisites

Install the required features:

FEATURE VERSION REQUIRED SUB-FEATURE
Spryker Core 202212.0 Install the Spryker Core Glue API
Category Management 202212.0

1) Install the required modules

Run the following command to install the required modules:

composer require spryker/categories-rest-api:"^1.1.3" --update-with-dependencies
Verification

Make sure that the following module has been installed:

MODULE EXPECTED DIRECTORY
CategoriesRestApi vendor/spryker/categories-rest-api

2) Set up configuration

Set up the following configuration

src/Pyz/Glue/NavigationsRestApi/NavigationsRestApiConfig.php

<?php

namespace Pyz\\Glue\\NavigationsRestApi;

use Spryker\\Glue\\NavigationsRestApi\\NavigationsRestApiConfig as SprykerNavigationsRestApiConfig;

class NavigationsRestApiConfig extends SprykerNavigationsRestApiConfig
{
    /\*\*
     \* {@inheritDoc}
     \*
     \* @return string\[\]
     \*/
    public function getNavigationTypeToUrlResourceIdFieldMapping(): array
    {
        return \[
            'category' => 'fkResourceCategorynode',
            'cms\_page' => 'fkResourcePage',
        \];
    }
}

3) Set up transfer objects

Generate transfer changes:

console transfer:generate
Verification

Make sure that the following changes have occurred:

TRANSFER TYPE EVENT PATH
RestCategoryTreesTransfer class created src/Generated/Shared/Transfer/RestCategoryTreesTransfer
RestCategoryTreesAttributesTransfer class created src/Generated/Shared/Transfer/RestCategoryTreesAttributesTransfer
RestCategoryNodesAttributesTransfer class created src/Generated/Shared/Transfer/RestCategoryNodesAttributesTransfer

4) Enable resources and relationships

Activate the following plugins:

PLUGIN SPECIFICATION PREREQUISITES NAMESPACE
CategoriesResourceRoutePlugin Registers the category-tree resource. Spryker\Glue\CategoriesRestApi\Plugin
CategoryResourceRoutePlugin Registers the category-nodes resource. Spryker\Glue\CategoriesRestApi\Plugin
CategoryNodeRestUrlResolverAttributesTransferProviderPlugin Maps the data for RestUrlResolverAttributesTransfer from UrlStorageTransfer. Spryker\Glue\CategoriesRestApi\Plugin\UrlsRestApi

src/Pyz/Glue/GlueApplication/GlueApplicationDependencyProvider.php

<?php

namespace Pyz\Glue\GlueApplication;

use Spryker\Glue\CategoriesRestApi\Plugin\CategoriesResourceRoutePlugin;
use Spryker\Glue\CategoriesRestApi\Plugin\CategoryResourceRoutePlugin;
use Spryker\Glue\GlueApplication\GlueApplicationDependencyProvider as SprykerGlueApplicationDependencyProvider;

class GlueApplicationDependencyProvider extends SprykerGlueApplicationDependencyProvider
{
    /**
     * @return \Spryker\Glue\GlueApplicationExtension\Dependency\Plugin\ResourceRoutePluginInterface[]
     */
    protected function getResourceRoutePlugins(): array
    {
        return [
            new CategoriesResourceRoutePlugin(),
            new CategoryResourceRoutePlugin(),
        ];
    }
}

src/Pyz/Glue/UrlsRestApi/UrlsRestApiDependencyProvider.php

<?php

namespace Pyz\Glue\UrlsRestApi;

use Spryker\Glue\CategoriesRestApi\Plugin\UrlsRestApi\CategoryNodeRestUrlResolverAttributesTransferProviderPlugin;
use Spryker\Glue\UrlsRestApi\UrlsRestApiDependencyProvider as SprykerUrlsRestApiDependencyProvider;

class UrlsRestApiDependencyProvider extends SprykerUrlsRestApiDependencyProvider
{
    /**
     * @return \Spryker\Glue\UrlsRestApiExtension\Dependency\Plugin\RestUrlResolverAttributesTransferProviderPluginInterface[]
     */
    protected function getRestUrlResolverAttributesTransferProviderPlugins(): array
    {
        return [
            new CategoryNodeRestUrlResolverAttributesTransferProviderPlugin(),
        ];
    }
}
Verification

Make sure that the following endpoints are available:

  • https://glue.mysprykershop.com/category-trees
  • https://glue.mysprykershop.com/category-nodes/{{category_node_id}}