|
| 1 | +--- |
| 2 | +title: "Magento 2" |
| 3 | +date: 2023-06-07T15:00:02+02:00 |
| 4 | +draft: false |
| 5 | +type: "plugins" |
| 6 | +description: "Read from and write to a Magento 2 site." |
| 7 | +weight: 2 |
| 8 | +--- |
| 9 | + |
| 10 | +- [What is it?](#what-is-it) |
| 11 | +- [Installation](#installation) |
| 12 | +- [Usage](#usage) |
| 13 | + - [Building an extractor](#building-an-extractor) |
| 14 | + - [Building a lookup](#building-a-lookup) |
| 15 | +--- |
| 16 | + |
| 17 | +> Magento 2 is an e-commerce platform. |
| 18 | +
|
| 19 | +## What is it? |
| 20 | + |
| 21 | +This package includes classes to extract data from Magento, using a [custom connector](../custom). |
| 22 | + |
| 23 | +## Installation |
| 24 | + |
| 25 | +```shell |
| 26 | +composer require "php-etl/magento2-flow:*" |
| 27 | +``` |
| 28 | + |
| 29 | +This package includes classes and code that you will be able to use in your custom connector. |
| 30 | + |
| 31 | +## Usage |
| 32 | + |
| 33 | +### Building an extractor |
| 34 | +The package includes the following extractor classes: `CustomerExtractor`, `InvoiceExtractor`, `OrderExtractor`, `ProductExtractor`. |
| 35 | + |
| 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 | + |
| 45 | +```yaml |
| 46 | +custom: |
| 47 | + extractor: |
| 48 | + use: 'Kiboko\Component\Flow\Magento2\CustomerExtractor' |
| 49 | + services: |
| 50 | + Kiboko\Component\Flow\Magento2\CustomerExtractor: |
| 51 | + public: true |
| 52 | + arguments: |
| 53 | + - '@Monolog\Logger' # Logger |
| 54 | + - '@Kiboko\Magento\V2_1\Client' # Client |
| 55 | + - 500 # Page size |
| 56 | + - [] # Filter groups |
| 57 | + |
| 58 | + Kiboko\Magento\V2_1\Client: |
| 59 | + factory: |
| 60 | + class: 'Kiboko\Magento\V2_1\Client' # Client |
| 61 | + method: 'create' |
| 62 | + arguments: |
| 63 | + - '@Http\Client\Common\PluginClient' |
| 64 | + Http\Client\Common\PluginClient: |
| 65 | + arguments: |
| 66 | + - '@GuzzleHttp\Client' |
| 67 | + - [ '@Http\Client\Common\Plugin\BaseUriPlugin', '@Http\Client\Common\Plugin\AuthenticationPlugin' ] |
| 68 | + GuzzleHttp\Client: ~ |
| 69 | + Http\Client\Common\Plugin\BaseUriPlugin: |
| 70 | + arguments: |
| 71 | + - '@GuzzleHttp\Psr7\Uri' |
| 72 | + Http\Client\Common\Plugin\AuthenticationPlugin: |
| 73 | + arguments: |
| 74 | + - '@Http\Message\Authentication\Bearer' |
| 75 | + GuzzleHttp\Psr7\Uri: |
| 76 | + arguments: |
| 77 | + - 'http://example-magento.com' # URL of the website |
| 78 | + Http\Message\Authentication\Bearer: |
| 79 | + arguments: |
| 80 | + - '12345abcde' # Access token |
| 81 | + |
| 82 | + Monolog\Logger: |
| 83 | + arguments: |
| 84 | + - 'app' |
| 85 | + - [ '@Monolog\Handler\StreamHandler' ] |
| 86 | + Monolog\Handler\StreamHandler: |
| 87 | + arguments: |
| 88 | + - 'var/dev.log' # Path to the log file |
| 89 | + - 300 # Log level. 300 for Warning, 200 for Info... |
| 90 | +``` |
| 91 | +
|
| 92 | +#### With filters |
| 93 | +Filters and filter groups can be specified. |
| 94 | +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`). |
| 97 | +```yaml |
| 98 | +# ... |
| 99 | + Kiboko\Component\Flow\Magento2\CustomerExtractor: |
| 100 | + public: true |
| 101 | + arguments: |
| 102 | + - '@Monolog\Logger' |
| 103 | + - '@Kiboko\Magento\V2_1\Client' |
| 104 | + - 500 |
| 105 | + - [ '@date_filter_group', '@id_filter_group' ] |
| 106 | + # updated_at >= 1985-10-26 11:25:00 AND (entity_id = 17 OR entity_id = 46) |
| 107 | +
|
| 108 | +# ... |
| 109 | +
|
| 110 | + date_filter_group: |
| 111 | + class: Kiboko\Component\Flow\Magento2\FilterGroup |
| 112 | + calls: |
| 113 | + - withFilter: [ '@last_execution' ] |
| 114 | + last_execution: |
| 115 | + class: Kiboko\Component\Flow\Magento2\Filter |
| 116 | + arguments: |
| 117 | + - 'updated_at' |
| 118 | + - 'gteq' |
| 119 | + - '1985-10-26 11:25:00' |
| 120 | + |
| 121 | + id_filter_group: |
| 122 | + class: Kiboko\Component\Flow\Magento2\FilterGroup |
| 123 | + calls: |
| 124 | + - withFilter: [ '@id_to_check', '@other_id' ] |
| 125 | + id_to_check: |
| 126 | + class: Kiboko\Component\Flow\Magento2\Filter |
| 127 | + arguments: |
| 128 | + - 'entity_id' |
| 129 | + - 'eq' |
| 130 | + - '17' |
| 131 | + other_id: |
| 132 | + class: Kiboko\Component\Flow\Magento2\Filter |
| 133 | + arguments: |
| 134 | + - 'entity_id' |
| 135 | + - 'eq' |
| 136 | + - '46' |
| 137 | +# ... |
| 138 | +``` |
| 139 | + |
| 140 | +### Building a lookup |
| 141 | +There is a lookup class for Categories, and one for product Attributes. |
| 142 | + |
| 143 | +{{< tabs name="lookup">}} |
| 144 | + |
| 145 | +{{< tab name="Category" codelang="yaml">}} |
| 146 | +custom: |
| 147 | + transformer: |
| 148 | + use: 'Kiboko\Component\Flow\Magento2\CategoryLookup' |
| 149 | + services: |
| 150 | + Kiboko\Component\Flow\Magento2\CategoryLookup: |
| 151 | + public: true |
| 152 | + arguments: |
| 153 | + - '@Monolog\Logger' |
| 154 | + - '@Kiboko\Magento\V2_3\Client' # Client to use depending on the Magento version. |
| 155 | + # Available clients are: |
| 156 | + # V2_1, V2_2, V2_3, V2_4 |
| 157 | + - '@Symfony\Component\Cache\Psr16Cache' |
| 158 | + - 'category.%s' |
| 159 | + - '@Acme\Custom\LookupMapper' # Your custom mapper class |
| 160 | + - 'category_name' # Index of the category ID, in your line. |
| 161 | + |
| 162 | + Kiboko\Magento\V2_3\Client: |
| 163 | + factory: |
| 164 | + class: 'Kiboko\Magento\V2_3\Client' # Client |
| 165 | + method: 'create' |
| 166 | + arguments: |
| 167 | + - '@Http\Client\Common\PluginClient' |
| 168 | + Http\Client\Common\PluginClient: |
| 169 | + arguments: |
| 170 | + - '@GuzzleHttp\Client' |
| 171 | + - [ '@Http\Client\Common\Plugin\BaseUriPlugin', '@Http\Client\Common\Plugin\AuthenticationPlugin' ] |
| 172 | + GuzzleHttp\Client: ~ |
| 173 | + Http\Client\Common\Plugin\BaseUriPlugin: |
| 174 | + arguments: |
| 175 | + - '@GuzzleHttp\Psr7\Uri' |
| 176 | + Http\Client\Common\Plugin\AuthenticationPlugin: |
| 177 | + arguments: |
| 178 | + - '@Http\Message\Authentication\Bearer' |
| 179 | + GuzzleHttp\Psr7\Uri: |
| 180 | + arguments: |
| 181 | + - 'http://example-magento.com' # URL of the website |
| 182 | + Http\Message\Authentication\Bearer: |
| 183 | + arguments: |
| 184 | + - '12345abcde' # Access token |
| 185 | + |
| 186 | + Symfony\Component\Cache\Psr16Cache: |
| 187 | + arguments: |
| 188 | + - '@Symfony\Component\Cache\Adapter\ApcuAdapter' |
| 189 | + Symfony\Component\Cache\Adapter\ApcuAdapter: ~ |
| 190 | + |
| 191 | + # Your custom mapper class |
| 192 | + Acme\Custom\LookupMapper: ~ |
| 193 | + |
| 194 | + Monolog\Logger: |
| 195 | + arguments: |
| 196 | + - 'app' |
| 197 | + - [ '@Monolog\Handler\StreamHandler' ] |
| 198 | + Monolog\Handler\StreamHandler: |
| 199 | + arguments: |
| 200 | + - 'var/dev.log' # Path to the log file |
| 201 | + - 300 # Log level. 300 for Warning, 200 for Info... |
| 202 | +{{< /tab >}} |
| 203 | + |
| 204 | +{{< tab name="Product attribute" codelang="yaml">}} |
| 205 | +custom: |
| 206 | + transformer: |
| 207 | + use: 'Kiboko\Component\Flow\Magento2\Lookup' |
| 208 | + services: |
| 209 | + Kiboko\Component\Flow\Magento2\Lookup: |
| 210 | + public: true |
| 211 | + arguments: |
| 212 | + - '@Monolog\Logger' |
| 213 | + - '@Kiboko\Magento\V2_3\Client' # Client to use depending on the Magento version. |
| 214 | + # Available clients are: |
| 215 | + # V2_1, V2_2, V2_3, V2_4 |
| 216 | + - '@Symfony\Component\Cache\Psr16Cache' |
| 217 | + - 'collection.%s' # Cache key |
| 218 | + - '@Acme\Custom\LookupMapper' # Your custom mapper class |
| 219 | + - 'Collection' # Index of the attribute ID, in your line. |
| 220 | + - 'qv_collection' # Attribute code |
| 221 | + |
| 222 | + Kiboko\Magento\V2_3\Client: |
| 223 | + factory: |
| 224 | + class: 'Kiboko\Magento\V2_3\Client' # Client |
| 225 | + method: 'create' |
| 226 | + arguments: |
| 227 | + - '@Http\Client\Common\PluginClient' |
| 228 | + Http\Client\Common\PluginClient: |
| 229 | + arguments: |
| 230 | + - '@GuzzleHttp\Client' |
| 231 | + - [ '@Http\Client\Common\Plugin\BaseUriPlugin', '@Http\Client\Common\Plugin\AuthenticationPlugin' ] |
| 232 | + GuzzleHttp\Client: ~ |
| 233 | + Http\Client\Common\Plugin\BaseUriPlugin: |
| 234 | + arguments: |
| 235 | + - '@GuzzleHttp\Psr7\Uri' |
| 236 | + Http\Client\Common\Plugin\AuthenticationPlugin: |
| 237 | + arguments: |
| 238 | + - '@Http\Message\Authentication\Bearer' |
| 239 | + GuzzleHttp\Psr7\Uri: |
| 240 | + arguments: |
| 241 | + - 'http://example-magento.com' # URL of the website |
| 242 | + Http\Message\Authentication\Bearer: |
| 243 | + arguments: |
| 244 | + - '12345abcde' # Access token of the website |
| 245 | + |
| 246 | + Symfony\Component\Cache\Psr16Cache: |
| 247 | + arguments: |
| 248 | + - '@Symfony\Component\Cache\Adapter\ApcuAdapter' |
| 249 | + Symfony\Component\Cache\Adapter\ApcuAdapter: ~ |
| 250 | + |
| 251 | + # Your custom mapper class |
| 252 | + Acme\Custom\LookupMapper: ~ |
| 253 | + |
| 254 | + Monolog\Logger: |
| 255 | + arguments: |
| 256 | + - 'app' |
| 257 | + - [ '@Monolog\Handler\StreamHandler' ] |
| 258 | + Monolog\Handler\StreamHandler: |
| 259 | + arguments: |
| 260 | + - 'var/dev.log' # Path to the log file |
| 261 | + - 300 # Log level. 300 for Warning, 200 for Info... |
| 262 | +{{< /tab >}} |
| 263 | + |
| 264 | +{{< /tabs >}} |
| 265 | + |
| 266 | +[Learn how to create your custom mapper class.](../custom/lookup_mapper) |
0 commit comments