Skip to content

Commit 8ef7040

Browse files
Merge pull request #136 from akeneo/API-412
API-412-413: Upsert and Upsert list of entities PHP client
2 parents 09bf779 + baf25ff commit 8ef7040

File tree

3 files changed

+145
-27
lines changed

3 files changed

+145
-27
lines changed

content/php-client/resources/families.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ $client->getFamilyApi()->create('caps', [
7474
]);
7575
```
7676

77-
78-
7977
### Upsert a family
8078

8179
If the family does not exist yet, this method creates it, otherwise it updates it.

content/php-client/resources/family-variants.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,64 @@ There is a maximum limit allowed on server side for the parameter `pageSize`.
9898
:::
9999

100100
You can get more information about this method [here](/php-client/list-resources.html#with-a-cursor).
101+
102+
### Upsert a family variant
103+
104+
If the family variant does not exist yet, this method creates it, otherwise it updates it.
105+
106+
```php
107+
$client = new \Akeneo\Pim\AkeneoPimClientBuilder('http://akeneo.com/')->buildAuthenticatedByPassword('client_id', 'secret', 'admin', 'admin');
108+
109+
$client->getFamilyVariantApi()->upsert('boots', [
110+
'code' => 'rain_boots_color_size',
111+
'labels' => [
112+
'de_DE' => 'Stiefel nach Farbe und Größe',
113+
'en_US' => 'Updating label',
114+
'fr_FR' => 'Mise à jour du label'
115+
]
116+
]);
117+
```
118+
119+
### Upsert a list of family variants
120+
121+
This method allows to create or update a list of family variants.
122+
It has the same behavior as the `upsert` method for a single family variant, except that the code must be specified in the data of each family variant.
123+
124+
125+
```php
126+
$client = new \Akeneo\Pim\AkeneoPimClientBuilder('http://akeneo.com/')->buildAuthenticatedByPassword('client_id', 'secret', 'admin', 'admin');
127+
128+
$responseLines = $client->getFamilyVariantApi()->upsertList('boots', [
129+
[
130+
'code' => 'rain_boots_color_size',
131+
'labels' => [
132+
'de_DE' => 'Stiefel nach Farbe und Größe',
133+
'en_US' => 'Updating label',
134+
'fr_FR' => 'Mise à jour du label'
135+
]
136+
],
137+
[
138+
'code' => 'man_boots_color_size',
139+
'labels' => [
140+
'de_DE' => 'Stiefel nach Farbe und Größe',
141+
'en_US' => 'Updating label',
142+
'fr_FR' => 'Mise à jour du label'
143+
]
144+
]
145+
]);
146+
147+
foreach ($responseLines as $line) {
148+
echo $line['line'];
149+
echo $line['identifier'];
150+
echo $line['status_code'];
151+
if (isset($line['message'])) {
152+
echo $line['message'];
153+
}
154+
}
155+
```
156+
157+
::: warning
158+
There is a limit on the maximum number of family variants that you can upsert in one time on server side. By default this limit is set to 100.
159+
:::
160+
161+
You can get a complete description of the expected format and the returned format [here](/api-reference.html#get_families__family_code__variants).

content/php-client/resources/product-models.md

Lines changed: 84 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,48 @@ $client = new \Akeneo\Pim\AkeneoPimClientBuilder('http://akeneo.com/')->buildAut
2828
$productModel = $client->getProductModelApi()->get('rain_boots_red');
2929
```
3030

31+
### Get a list of product models
32+
33+
There are two ways of getting product models.
34+
35+
#### By getting pages
36+
37+
This method allows to get product models page per page, as a classical pagination.
38+
It's possible to get the total number of product models with this method.
39+
40+
```php
41+
$client = new \Akeneo\Pim\AkeneoPimClientBuilder('http://akeneo.com/')->buildAuthenticatedByPassword('client_id', 'secret', 'admin', 'admin');
42+
43+
$firstPage = $client->getProductModelApi()->listPerPage(50, true);
44+
```
45+
46+
::: warning
47+
There is a maximum limit allowed on server side for the parameter `limit`.
48+
:::
49+
50+
::: warning
51+
Setting the parameter `with_count` to `true` can drastically decrease the performance.
52+
It's recommended to let this parameter with the default value `false` if the total number of product models is not needed in the response.
53+
:::
54+
55+
You can get more information about this method [here](/php-client/list-resources.html#by-getting-pages).
56+
57+
#### With a cursor
58+
59+
This method allows to iterate the product models. It will automatically get the next pages for you.
60+
61+
```php
62+
$client = new \Akeneo\Pim\AkeneoPimClientBuilder('http://akeneo.com/')->buildAuthenticatedByPassword('client_id', 'secret', 'admin', 'admin');
63+
64+
$productModels = $client->getProductModelApi()->all(50);
65+
```
66+
67+
:::warning
68+
There is a maximum limit allowed on server side for the parameter `pageSize`.
69+
:::
70+
71+
You can get more information about this method [here](/php-client/list-resources.html#with-a-cursor).
72+
3173
### Create a product model
3274

3375
If the product model does not exist yet, this method creates it, otherwise it throws an exception.
@@ -60,44 +102,61 @@ $client->getProductModelApi()->create('saddle_rain_boots', [
60102

61103
Product model values use the same format as the product values. If you want to know more, take a look at [here](/documentation/resources.html#product-values).
62104

63-
### Get a list of product models
64-
65-
There are two ways of getting product models.
66-
67-
#### By getting pages
105+
### Upsert a product model
68106

69-
This method allows to get product models page per page, as a classical pagination.
70-
It's possible to get the total number of product models with this method.
107+
If the product model does not exist yet, this method creates it, otherwise it updates it.
71108

72109
```php
73110
$client = new \Akeneo\Pim\AkeneoPimClientBuilder('http://akeneo.com/')->buildAuthenticatedByPassword('client_id', 'secret', 'admin', 'admin');
74111

75-
$firstPage = $client->getProductModelApi()->listPerPage(50, true);
112+
$client->getProductModelApi()->upsert('rain_boots_red', [
113+
'categories' => ['2014_collection', 'winter_boots']
114+
]);
76115
```
77116

78-
::: warning
79-
There is a maximum limit allowed on server side for the parameter `limit`.
80-
:::
117+
### Upsert a list of product models
81118

82-
::: warning
83-
Setting the parameter `with_count` to `true` can drastically decrease the performance.
84-
It's recommended to let this parameter with the default value `false` if the total number of product models is not needed in the response.
85-
:::
119+
This method allows to create or update a list of product models.
120+
It has the same behavior as the `upsert` method for a single product model, except that the code must be specified in the data of each product models.
86121

87-
You can get more information about this method [here](/php-client/list-resources.html#by-getting-pages).
88-
89-
#### With a cursor
90-
91-
This method allows to iterate the product models. It will automatically get the next pages for you.
92122

93123
```php
94124
$client = new \Akeneo\Pim\AkeneoPimClientBuilder('http://akeneo.com/')->buildAuthenticatedByPassword('client_id', 'secret', 'admin', 'admin');
95125

96-
$productModels = $client->getProductModelApi()->all(50);
126+
$responseLines = $client->getProductModelApi()->upsertList([
127+
[
128+
'code' => 'rain_boots_red',
129+
'family_variant' => 'rain_boots_color_size',
130+
'parent' => 'rain_boots',
131+
'categories' => ['2014_collection', 'winter_boots']
132+
],
133+
[
134+
'code' => 'rain_boots_saddle',
135+
'family_variant' => 'rain_boots_color_size',
136+
'parent' => 'rain_boots',
137+
'categories' => ['2014_collection', 'winter_boots'],
138+
'values' => [
139+
'description' => [
140+
[
141+
'locale' => 'en_US',
142+
'scope' => 'ecommerce',
143+
'data' => 'Saddle rain boots made of rubber for winter.'
144+
]
145+
]
146+
]
147+
]
148+
]);
149+
150+
foreach ($responseLines as $line) {
151+
echo $line['line'];
152+
echo $line['identifier'];
153+
echo $line['status_code'];
154+
if (isset($line['message'])) {
155+
echo $line['message'];
156+
}
157+
}
97158
```
98159

99-
:::warning
100-
There is a maximum limit allowed on server side for the parameter `pageSize`.
160+
::: warning
161+
There is a limit on the maximum number of product models that you can upsert in one time on server side. By default this limit is set to 100.
101162
:::
102-
103-
You can get more information about this method [here](/php-client/list-resources.html#with-a-cursor).

0 commit comments

Comments
 (0)