Skip to content

Commit a08024f

Browse files
committed
better explanation for arguments of Client,
move the explanation about Lookup Mapper to a separate page
1 parent ad9b0ee commit a08024f

File tree

4 files changed

+80
-85
lines changed

4 files changed

+80
-85
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
title: "Lookup mapper"
3+
date: 2023-07-31T12:07:47+02:00
4+
draft: false
5+
type: "plugins"
6+
icon: "ti-settings"
7+
description: "Learn how to write a custom mapper"
8+
weight: 1
9+
---
10+
11+
A lookup mapper is a class that implements `Kiboko\Contract\Mapping\CompiledMapperInterface`.
12+
13+
Its purpose is to merge the result of the lookup back into your line.
14+
15+
`$output` is your line, and `$input` is the result of the lookup.
16+
17+
```php
18+
<?php
19+
20+
declare(strict_types=1);
21+
22+
namespace Acme\Custom;
23+
24+
use Kiboko\Contract\Mapping\CompiledMapperInterface;
25+
26+
class LookupMapper implements CompiledMapperInterface
27+
{
28+
public function __invoke($input, $output = null)
29+
{
30+
$output['actual_customer_id'] = $input['id'];
31+
32+
return $output;
33+
}
34+
}
35+
```

content/connectivity/magento-2/_index.en.md

Lines changed: 34 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ This package includes classes and code that you will be able to use in your cust
3333
### Building an extractor
3434
The package includes the following extractor classes: `CustomerExtractor`, `InvoiceExtractor`, `OrderExtractor`, `ProductExtractor`.
3535

36+
Extractor classes take 4 arguments:
37+
38+
| name | description | type | default value |
39+
|---------------|--------------------------------------------------------------------------------------------------|--------------------------|---------------|
40+
| logger | the service that will log exceptions | \Psr\Log\LoggerInterface | |
41+
| client | client to choose depending on the Magento version. Available clients are: V2_1, V2_2, V2_3, V2_4 | Client | |
42+
| page size | (Optional) maximum amount of entities to retrieve in a single payload | int | 100 |
43+
| filter groups | (Optional) groups of filters to use when searching for entities | array | [] |
44+
3645
```yaml
3746
custom:
3847
extractor:
@@ -41,16 +50,14 @@ custom:
4150
Kiboko\Component\Flow\Magento2\CustomerExtractor:
4251
public: true
4352
arguments:
44-
- '@Monolog\Logger'
45-
- '@Kiboko\Magento\V2_1\Client' # Client to use depending on the Magento version.
46-
# Available clients are:
47-
# V2_1, V2_2, V2_3, V2_4
53+
- '@Monolog\Logger' # Logger
54+
- '@Kiboko\Magento\V2_1\Client' # Client
4855
- 500 # Page size
49-
- [] # Optional filter groups
56+
- [] # Filter groups
5057

5158
Kiboko\Magento\V2_1\Client:
5259
factory:
53-
class: 'Kiboko\Magento\V2_1\Client'
60+
class: 'Kiboko\Magento\V2_1\Client' # Client
5461
method: 'create'
5562
arguments:
5663
- '@Http\Client\Common\PluginClient'
@@ -85,6 +92,8 @@ custom:
8592
#### With filters
8693
Filters and filter groups can be specified.
8794
Filters in a group are chained with `OR`. Groups are chained with `AND`.
95+
96+
In this example we will search for customers that were updated after 1985 (`@date_filter_group`) and which have either the ID 17 or 46 (`@id_filter_group`).
8897
```yaml
8998
# ...
9099
Kiboko\Component\Flow\Magento2\CustomerExtractor:
@@ -94,8 +103,10 @@ Filters in a group are chained with `OR`. Groups are chained with `AND`.
94103
- '@Kiboko\Magento\V2_1\Client'
95104
- 500
96105
- [ '@date_filter_group', '@id_filter_group' ]
97-
# updated_at >= 1985-10-26 11:25:00 AND (entity_id = 12 OR entity_id = 64)
98-
106+
# updated_at >= 1985-10-26 11:25:00 AND (entity_id = 17 OR entity_id = 46)
107+
108+
# ...
109+
99110
date_filter_group:
100111
class: Kiboko\Component\Flow\Magento2\FilterGroup
101112
calls:
@@ -110,24 +121,24 @@ Filters in a group are chained with `OR`. Groups are chained with `AND`.
110121
id_filter_group:
111122
class: Kiboko\Component\Flow\Magento2\FilterGroup
112123
calls:
113-
- withFilter: [ '@id_to_check', '@id_that_doesnt_work' ]
124+
- withFilter: [ '@id_to_check', '@other_id' ]
114125
id_to_check:
115126
class: Kiboko\Component\Flow\Magento2\Filter
116127
arguments:
117128
- 'entity_id'
118129
- 'eq'
119-
- '12'
120-
id_that_doesnt_work:
130+
- '17'
131+
other_id:
121132
class: Kiboko\Component\Flow\Magento2\Filter
122133
arguments:
123134
- 'entity_id'
124135
- 'eq'
125-
- '64'
136+
- '46'
126137
# ...
127138
```
128139

129140
### Building a lookup
130-
There is a lookup class for Categories, and one for product attributes.
141+
There is a lookup class for Categories, and one for product Attributes.
131142

132143
{{< tabs name="lookup">}}
133144

@@ -145,15 +156,12 @@ custom:
145156
# V2_1, V2_2, V2_3, V2_4
146157
- '@Symfony\Component\Cache\Psr16Cache'
147158
- 'category.%s'
148-
- '@Acme\Magento\LookupMapper' # Your custom mapper class
149-
- 'category_name' # Index of the search criteria.
150-
# In the case of the CategoryLookup, it should be the category ID.
151-
# Here we temporarily store the category id in this field.
152-
# LookupMapper will then replace it with the actual name.
159+
- '@Acme\Custom\LookupMapper' # Your custom mapper class
160+
- 'category_name' # Index of the category ID, in your line.
153161

154162
Kiboko\Magento\V2_3\Client:
155163
factory:
156-
class: 'Kiboko\Magento\V2_3\Client'
164+
class: 'Kiboko\Magento\V2_3\Client' # Client
157165
method: 'create'
158166
arguments:
159167
- '@Http\Client\Common\PluginClient'
@@ -181,7 +189,7 @@ custom:
181189
Symfony\Component\Cache\Adapter\ApcuAdapter: ~
182190

183191
# Your custom mapper class
184-
Acme\Magento\LookupMapper: ~
192+
Acme\Custom\LookupMapper: ~
185193

186194
Monolog\Logger:
187195
arguments:
@@ -207,13 +215,13 @@ custom:
207215
# V2_1, V2_2, V2_3, V2_4
208216
- '@Symfony\Component\Cache\Psr16Cache'
209217
- 'collection.%s' # Cache key
210-
- '@Acme\Magento\LookupMapper' # Your custom mapper class
211-
- 'Collection' # Index of the search criteria.
212-
- 'qv_collection' # attribute code
218+
- '@Acme\Custom\LookupMapper' # Your custom mapper class
219+
- 'Collection' # Index of the attribute ID, in your line.
220+
- 'qv_collection' # Attribute code
213221

214222
Kiboko\Magento\V2_3\Client:
215223
factory:
216-
class: 'Kiboko\Magento\V2_3\Client'
224+
class: 'Kiboko\Magento\V2_3\Client' # Client
217225
method: 'create'
218226
arguments:
219227
- '@Http\Client\Common\PluginClient'
@@ -241,7 +249,7 @@ custom:
241249
Symfony\Component\Cache\Adapter\ApcuAdapter: ~
242250

243251
# Your custom mapper class
244-
Acme\Magento\LookupMapper: ~
252+
Acme\Custom\LookupMapper: ~
245253

246254
Monolog\Logger:
247255
arguments:
@@ -255,30 +263,4 @@ custom:
255263

256264
{{< /tabs >}}
257265

258-
Next, you will need to create the `LookupMapper`, a class that implements `Kiboko\Contract\Mapping\CompiledMapperInterface`.
259-
Its purpose is to merge the result of the lookup back into the line.
260-
261-
In the case of a CategoryLookup, the line has a field `category_name` that contains the category ID.
262-
We want to replace that ID with the actual category name that the lookup has found.
263-
264-
`$output` is your line, and `$input` is the result of the Magento lookup.
265-
266-
```php
267-
<?php
268-
269-
declare(strict_types=1);
270-
271-
namespace Acme\Magento;
272-
273-
use Kiboko\Contract\Mapping\CompiledMapperInterface;
274-
275-
class LookupMapper implements CompiledMapperInterface
276-
{
277-
public function __invoke($input, $output = null)
278-
{
279-
$output['category_name'] = $input->getName();
280-
281-
return $output;
282-
}
283-
}
284-
```
266+
[Learn how to create your custom mapper class.](../custom/lookup_mapper)

content/connectivity/zoho/_index.en.md

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ custom:
9090
- '@Kiboko\Component\Flow\ZohoCRM\Client\Client'
9191
- '@Monolog\Logger'
9292
- '@Symfony\Component\Cache\Psr16Cache'
93-
- '@Acme\Zoho\LookupMapper' # Your custom mapper class
94-
- 'customer_id' # Index of the search criteria.
93+
- '@Acme\Custom\LookupMapper' # Your custom mapper class
94+
- 'customer_id' # Index of the search criteria, in your line.
9595
# In the case of the ContactLookup, it should be an email.
9696
# Here we temporarily store the customer email in this field.
9797
# LookupMapper will then replace it with the actual ID.
@@ -115,15 +115,15 @@ custom:
115115
- 'n7g0a4xfqyemc61uertqplks' # Refresh token
116116
GuzzleHttp\Client: ~
117117
GuzzleHttp\Psr7\HttpFactory: ~
118-
118+
119119
Symfony\Component\Cache\Psr16Cache:
120120
arguments:
121121
- '@Symfony\Component\Cache\Adapter\ApcuAdapter'
122122
Symfony\Component\Cache\Adapter\ApcuAdapter: ~
123-
123+
124124
# Your custom mapper class
125-
Acme\ZohoCRM\LookupMapper: ~
126-
125+
Acme\Custom\LookupMapper: ~
126+
127127
Monolog\Logger:
128128
arguments:
129129
- 'app'
@@ -134,30 +134,4 @@ custom:
134134
- 300 # Log level. 300 for Warning, 200 for Info...
135135
```
136136
137-
Next, you will need to create the `LookupMapper`, a class that implements `Kiboko\Contract\Mapping\CompiledMapperInterface`.
138-
Its purpose is to merge the result of the lookup back into the line.
139-
140-
In our case, the line has a field `customer_id` that contains an email.
141-
We want to replace that email with the actual customer ID that the lookup has found.
142-
143-
`$output` is your line, and `$input` is the result of the Zoho lookup.
144-
145-
```php
146-
<?php
147-
148-
declare(strict_types=1);
149-
150-
namespace Acme\Zoho;
151-
152-
use Kiboko\Contract\Mapping\CompiledMapperInterface;
153-
154-
class LookupMapper implements CompiledMapperInterface
155-
{
156-
public function __invoke($input, $output = null)
157-
{
158-
$output['customer_id'] = $input['id'];
159-
160-
return $output;
161-
}
162-
}
163-
```
137+
[Learn how to create your custom mapper class.](../custom/lookup_mapper)

themes/middleware/assets/css/style.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
html {
2+
overflow-x: hidden;
3+
}
4+
15
body {
26
line-height: 1.5;
37
font-family: var(--font-family), sans-serif;

0 commit comments

Comments
 (0)