Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FRW-5799 Added Install the Data Exchange API + Inventory Management feature #2151

Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
---
title: Data Exchange API + Inventory Management feature integration
description: Install the Data Exchange API + Inventory Management features in your project.
last_updated: Sep 06, 2023
template: feature-integration-guide-template
---

This document describes how to integrate the Data Exchange API + Inventory Management feature into a Spryker project.

## Install feature core

Follow the steps below to install the Data Exchange API + Inventory Management feature core.

### Prerequisites

Install the required features:

| NAME | VERSION | INTEGRATION GUIDE |
|-------------------|------------------|------------------|
| Data Exchange API | {{page.version}} | [Data Exchange API integration](/docs/scos/dev/feature-integration-guides/{{page.version}}/glue-api/dynamic-data-api/data-exchange-api-integration.html) |
| Inventory Management | {{page.version}} | [Install the Inventory Management feature](/docs/pbc/all/warehouse-management-system/{{page.version}}/unified-commerce/install-and-upgrade/install-the-inventory-management-feature.html) |

### 1) Set up behavior

Register the following plugins:

| PLUGIN | SPECIFICATION | PREREQUISITES | NAMESPACE |
|---|---|---|---|
| AvailabilityDynamicEntityPostUpdatePlugin | Checks if `spy_stock_product` is updated and updates availability. | None | Spryker\Zed\Availability\Communication\Plugin\DynamicEntity |
| AvailabilityDynamicEntityPostCreatePlugin | Checks if `spy_stock_product` is updated and updates availability. | None | Spryker\Zed\Availability\Communication\Plugin\DynamicEntity |

**src/Pyz/Zed/DynamicEntity/DynamicEntityDependencyProvider.php**

```php
<?php

namespace Pyz\Zed\DynamicEntity;

use Spryker\Zed\Availability\Communication\Plugin\DynamicEntity\AvailabilityDynamicEntityPostCreatePlugin;
use Spryker\Zed\Availability\Communication\Plugin\DynamicEntity\AvailabilityDynamicEntityPostUpdatePlugin;
use Spryker\Zed\DynamicEntity\DynamicEntityDependencyProvider as SprykerDynamicEntityDependencyProvider;

class DynamicEntityDependencyProvider extends SprykerDynamicEntityDependencyProvider
{
/**
* @return array<\Spryker\Zed\DynamicEntityExtension\Dependency\Plugin\DynamicEntityPostUpdatePluginInterface>
*/
protected function getDynamicEntityPostUpdatePlugins(): array
{
return [
new AvailabilityDynamicEntityPostUpdatePlugin(),
];
}

/**
* @return array<\Spryker\Zed\DynamicEntityExtension\Dependency\Plugin\DynamicEntityPostCreatePluginInterface>
*/
protected function getDynamicEntityPostCreatePlugins(): array
{
return [
new AvailabilityDynamicEntityPostCreatePlugin(),
];
}
}
```

{% info_block warningBox "Verification" %}

Let’s say you have an endpoint `/dynamic-data/stock-products` to operate with data in `spy_stock_product` table in database.
asmarovydlo marked this conversation as resolved.
Show resolved Hide resolved

By default, all routes within the Data Exchange API are protected to ensure data security.
To access the API, you need to obtain an access token by sending a POST request to the `/token/` endpoint with the appropriate credentials:

```bash
POST /token/ HTTP/1.1
Host: glue-backend.mysprykershop.com
Content-Type: application/x-www-form-urlencoded
Accept: application/json
Content-Length: 67

grant_type=password&username={username}&password={password}
```
asmarovydlo marked this conversation as resolved.
Show resolved Hide resolved

### Sending a `PATCH` request
This request needs to include the necessary headers, such as Content-Type, Accept, and Authorization, with the access token provided.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove some of the information and instead give reference to the howto guide? That is, I would suggest replacing lines 69-82 with the following text:
"Let's say you want to have a new endpoint /dynamic-data/stock-products to operate with data in spy_stock_product table in database. Send the PATCH request to update the product stock data according to the guidelines in [How to send a request in Data Exchange] API (/docs/scos/dev/glue-api-guides/202307.0/data-exchange-api/how-to-guides/how-to-send-request-in-data-exchange-api.html):"

What do you think?

Copy link
Contributor Author

@dimitriyTsemma dimitriyTsemma Oct 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't have information about the stock-products endpoint in the How To guide, so it looks like we can't remove anything here (

```bash
PATCH /dynamic-entity/stock-products HTTP/1.1
Host: glue-backend.mysprykershop.com
Content-Type: application/json
Accept: application/json
Authorization: Bearer {your_token}
Content-Length: 174
{
"data": [
{
"idStockProduct": 1,
"Quantity": 10
asmarovydlo marked this conversation as resolved.
Show resolved Hide resolved
}
]
}
```

Make sure that after updating stock data - product availability is updated as well. For this go to the Storefront and check the availability of the product.
asmarovydlo marked this conversation as resolved.
Show resolved Hide resolved

{% endinfo_block %}