Glue API - Customer feature integration
Edit on GitHubInstall feature API
Prerequisites
To start feature integration, overview and install the necessary features:
Name | Version | Integration guide |
---|---|---|
Spryker Core | 201903.0 | Glue Application feature integration |
Customer Account Management | 201903.0 |
1)Install the Required Modules Using Composer
Run the following command to install the required modules:
composer require spryker/customers-rest-api:"^1.6.2" --update-with-dependencies
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
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
Activate the console command provided by the module:
Class | Specification | Prerequisites | Namespace |
---|---|---|---|
CustomerAddressesUuidWriterConsole |
Provides the customer-addresses:uuid:generate console command for generating UUIDs for existing spy_customer_address records. |
None | Spryker\Zed\WishlistsRestApi\Communication\Console |
src/Pyz/Zed/Console/ConsoleDependencyProvider.php
<?php
namespace Pyz\Zed\Console;
use Spryker\Zed\CustomersRestApi\Communication\Console\CustomerAddressesUuidWriterConsole;
use Spryker\Zed\Console\ConsoleDependencyProvider as SprykerConsoleDependencyProvider;
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;
}
}
Run the following console command:
console list
Make sure that customer-addresses:uuid:generate
appears in the list.
Migrate data in the database
Run the following command:
console customer-addresses:uuid:generate
Make sure that the uuid
field is filled for all records in the spy_customer_address
table. For this purpose, run the following SQL query and make sure that the result is 0 records:
`SELECT COUNT(*
Enable resources and relationships
Activate the following plugins:
Plugin | Specification | Prerequisites | Namespace |
---|---|---|---|
SetCustomerBeforeActionPlugin.uuid |
Sets customer data to the 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-password resource. |
None | Spryker\Glue\CustomersRestApi\Plugin |
CustomerRestorePasswordResourceRoutePlugin |
Registers the customer-restore-password resource. |
None | Spryker\Glue\CustomersRestApi\Plugin |
CustomerPasswordResourceRoutePlugin |
Registers the customer-password resource. |
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;
use Spryker\Glue\GlueApplicationExtension\Dependency\Plugin\ResourceRelationshipCollectionInterface;
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->addRelationship(
CustomersRestApiConfig::RESOURCE_CUSTOMERS,
new CustomersToAddressesRelationshipPlugin()
);
return $resourceRelationshipCollection;
}
}
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
addresses
resources.The Customer with the given ID should have at least one address.
Last review date: Apr 11, 2019
Thank you!
For submitting the form