Skip to content

Commit baf25ff

Browse files
Willyahocquard
authored andcommitted
API-412-413: Upsert and upsert list of product models PHP client
1 parent d3c65d2 commit baf25ff

File tree

1 file changed

+84
-25
lines changed

1 file changed

+84
-25
lines changed

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)