Glue API - Customer 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
Customer Account Management 2018.12.0

1) Install the required modules

Run the following command to install the required modules:

composer require spryker/customers-rest-api:"^1.6.2" --update-with-dependencies
Verification
Make sure that the following modules are installed:
Module Expected Directory
CustomersRestApiExtensions vendor/spryker/customers-rest-api-extension
CustomersRestApi vendor/spryker/customers-rest-api

2) Set up Database Schema and Transfer objects

Run the following commands to apply database changes and also generate entity and transfer changes:

console transfer:generate
console propel:install
console transfer:generate

Verification

Make sure that the following changes have occurred in the database:
Transfer Type Event
spy_customer_address.uuid column created
spy_customer_address.spy_customer_address-unique-uuid index created
Make sure that the following changes have occurred in transfer objects:
Transfer Type Event Path
Address.uuid column created src/Generated/Shared/Transfer/Address
RestCustomersAttributes class created src/Generated/Shared/Transfer/RestCustomersAttributes
RestCustomersResponseAttributes class created src/Generated/Shared/Transfer/RestCustomersResponseAttributes
RestCustomersRegisterAttributes class created src/Generated/Shared/Transfer/RestCustomersRegisterAttributes
RestAddressAttributes class created src/Generated/Shared/Transfer/RestAddressAttributes
RestCustomerPasswordAttributes class created src/Generated/Shared/Transfer/RestCustomerPasswordAttributes
RestCustomerForgottenPasswordAttributes class created src/Generated/Shared/Transfer/RestCustomerForgottenPasswordAttributes

3) Set up behavior

Enable console command

Register the following console command in ConsoleDependencyProvider:

<?php
 
namespace Pyz\Zed\Console;
 
use Spryker\Zed\CustomersRestApi\Communication\Console\CustomerAddressesUuidWriterConsole;
 
class ConsoleDependencyProvider extends SprykerConsoleDependencyProvider
{
    /**
     * @param \Spryker\Zed\Kernel\Container $container
     *
     * @return \Symfony\Component\Console\Command\Command[]
     */
    protected function getConsoleCommands(Container $container)
    {
        $commands = [
            new CustomerAddressesUuidWriterConsole(),
        ];
 
        return $commands;
    }
}
Verification
Run the following console command:
```console list```
Make sure that `customer-addresses:uuid:generate appears` in the list.

Migrate data in database

Run the following command to generate the UUIDs for all the existing records in the spy_customer_address table:

console customer-addresses:uuid:generate
Verification
Make sure that the `uuid` field is filled for all the records in the `spy_customer_address` table. You can run the following SQL query and make sure that the result is 0 records.
```select count(*
from spy_customer_address where uuid is NULL;```)
Verification
Make sure that the `uuid` field is filled with all the records from the `spy_wishlist` table. You can run the following SQL query and make sure that the result is 0 records.
```select count(*
from spy_wishlist where uuid is NULL;```)

Enable resources and relationships

Activate the following plugins:

Plugin Specification Prerequisites Namespace
SetCustomerBeforeActionPlugin.uuid Sets customer data to session. It is expected that the user field will be set in the REST requests. Spryker\Glue\CustomersRestApi\Plugin
CustomersResourceRoutePlugin Registers the customers resource. None Spryker\Glue\CustomersRestApi\Plugin
AddressesResourceRoutePlugin Registers the addresses resource. None Spryker\Glue\CustomersRestApi\Plugin
CustomerForgottenPasswordResourceRoutePlugin Registers the customer-forgotten-passwordresource. None Spryker\Glue\CustomersRestApi\Plugin
CustomerRestorePasswordResourceRoutePlugin Registers the customer-restore-passwordresource. None Spryker\Glue\CustomersRestApi\Plugin
CustomerPasswordResourceRoutePlugin Registers the customer-passwordresource. None Spryker\Glue\CustomersRestApi\Plugin
CustomersToAddressesRelationshipPlugin Adds the addresses resource as a relationship to the customers resource. None Spryker\Glue\CustomersRestApi\Plugin
src/Pyz/Glue/GlueApplication/GlueApplicationDependencyProvider.php
<?php
 
namespace Pyz\Glue\GlueApplication;
 
use Spryker\Glue\CustomersRestApi\CustomersRestApiConfig;
use Spryker\Glue\CustomersRestApi\Plugin\AddressesResourceRoutePlugin;
use Spryker\Glue\CustomersRestApi\Plugin\CustomerForgottenPasswordResourceRoutePlugin;
use Spryker\Glue\CustomersRestApi\Plugin\CustomerPasswordResourceRoutePlugin;
use Spryker\Glue\CustomersRestApi\Plugin\CustomerRestorePasswordResourceRoutePlugin;
use Spryker\Glue\CustomersRestApi\Plugin\CustomersResourceRoutePlugin;
use Spryker\Glue\CustomersRestApi\Plugin\CustomersToAddressesRelationshipPlugin;
use Spryker\Glue\CustomersRestApi\Plugin\SetCustomerBeforeActionPlugin;
use Spryker\Glue\GlueApplication\GlueApplicationDependencyProvider as SprykerGlueApplicationDependencyProvider;
 
 
class GlueApplicationDependencyProvider extends SprykerGlueApplicationDependencyProvider
{
    /**
    * {@inheritdoc}
    *
    * @return \Spryker\Glue\GlueApplicationExtension\Dependency\Plugin\ResourceRoutePluginInterface[]
    */
    protected function getResourceRoutePlugins(): array
    {       
        return [
            new CustomersResourceRoutePlugin(),
            new CustomerForgottenPasswordResourceRoutePlugin(),
            new CustomerRestorePasswordResourceRoutePlugin(),
            new CustomerPasswordResourceRoutePlugin(),
            new AddressesResourceRoutePlugin(),
        ];
    }
 
    /**
    * {@inheritdoc}
    *
    * @return \Spryker\Glue\GlueApplicationExtension\Dependency\Plugin\ControllerBeforeActionPluginInterface[]
    */
    protected function getControllerBeforeActionPlugins(): array
    {
        return [
            new SetCustomerBeforeActionPlugin(),
        ];
    }
 
    /**
    * {@inheritdoc}
    *
    * @param \Spryker\Glue\GlueApplicationExtension\Dependency\Plugin\ResourceRelationshipCollectionInterface $resourceRelationshipCollection
    *
    * @return \Spryker\Glue\GlueApplicationExtension\Dependency\Plugin\ResourceRelationshipCollectionInterface
    */
    protected function getResourceRelationshipPlugins(
        ResourceRelationshipCollectionInterface $resourceRelationshipCollection
    ): ResourceRelationshipCollectionInterface {
        $resourceRelationshipCollection-&gt;addRelationship(
            CustomersRestApiConfig::RESOURCE_CUSTOMERS,
            new CustomersToAddressesRelationshipPlugin()
        );
 
        return $resourceRelationshipCollection;
    }
}

Verification

Make sure that the following endpoints are available:
  • https://glue.mysprykershop.com/customers

  • https://glue.mysprykershop.com/addresses

  • https://glue.mysprykershop.com/customer-password

  • https://glue.mysprykershop.com/customer-forgotten-password

  • https://glue.mysprykershop.com/customer-restore-password

Send a request to `https://glue.mysprykershop.com/customers/{{customer_id}}?include=addresses`. Make sure that the response includes relationships to the `addresses` resources.
*The Customer with the given ID should have at least one address.*