Skip to content

Commit a175106

Browse files
samokissSamuel Gomis
andauthored
fix(API-1953): snippet + GT title (#716)
* fix(API-1953): snippet + GT title * fix(API-1953): fix class Co-authored-by: Samuel Gomis <[email protected]>
1 parent 9023956 commit a175106

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

content/tutorials/guides/how-to-collect-product-variations.md

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
<ul>
5050
<li>Step 1. <a href="how-to-get-your-app-token.html" target="_blank" rel="noopener noreferrer">Get your App token tutorial</a></li>
5151
<li>Step 2. <a href="how-to-retrieve-pim-structure.html" target="_blank" rel="noopener noreferrer">How to retrieve PIM structure</a></li>
52-
<li>Step 3. <a href="how-to-get-families-and-attributes.html" target="_blank" rel="noopener noreferrer">How to get families and attributes</a></li>
52+
<li>Step 3. <a href="how-to-get-families-and-attributes.html" target="_blank" rel="noopener noreferrer">How to get families, family variants, and attributes</a></li>
5353
<li>Step 4. <a href="how-to-get-pim-product-information.html" target="_blank" rel="noopener noreferrer">How to get PIM product information</a></li>
5454
</ul>
5555
</div>
@@ -63,7 +63,7 @@ In the PIM we handle product models and product variations.
6363
![scheme_variants](../../img/tutorials/how-to-collect-product-variations/scheme_variants.png)
6464

6565
::: tips
66-
Before digging into the code you can find out more about these concepts in our <a href="https://help.akeneo.com/pim/serenity/articles/what-about-products-variants.html#about-products-with-variants" class="endpoint-link" target="_blank" rel="noopener noreferrer">helpcenter</a>
66+
Before digging into the code you can find out more about these concepts in our <a href="https://help.akeneo.com/pim/serenity/articles/what-about-products-variants.html#about-products-with-variants" target="_blank" rel="noopener noreferrer">helpcenter</a>
6767
:::
6868

6969
Here are quick definitions:
@@ -130,7 +130,7 @@ function buildApiClient(): GuzzleHttp\Client
130130
#### 1. Collect product models
131131
##### 1.1 You are following the App workflow?
132132

133-
In the guided tutorial <a href="/tutorials/how-to-get-families-and-attributes.html" target="_blank" rel="noopener noreferrer">How to get families and attributes</a>, we have stored a **family_code_list**. It’s time to use it!
133+
In the guided tutorial <a href="/tutorials/how-to-get-families-and-attributes.html" target="_blank" rel="noopener noreferrer">How to get families, family variants, and attributes</a>, we have stored a **family_code_list**. It’s time to use it!
134134

135135
```php [activate:PHP]
136136

@@ -146,7 +146,7 @@ function getProductModels(): array
146146
$familyCodes = getFamilyCodes();
147147

148148
// Get locales from storage
149-
$locales = getLocales();
149+
$locales = getLocales(); // ['en_US', 'fr_FR']
150150

151151
$familyCodeChunks = array_chunk($familyCodes, $maxFamiliesPerQuery);
152152

@@ -157,10 +157,17 @@ function getProductModels(): array
157157
. '&limit=' . $maxProductsPerPage;
158158

159159

160-
// Collect product models from paginated API
160+
// Collect product models from API
161161
$productModels = [];
162162
foreach ($familyCodeChunks as $familyCodes) {
163-
$response = $client->get(sprintf($apiUrl, $locales, $scope, json_encode($familyCodes)));
163+
$response = $client->get(
164+
sprintf(
165+
$apiUrl,
166+
implode(',', $locales),
167+
$scope,
168+
json_encode($familyCodes)
169+
)
170+
);
164171
$data = json_decode($response->getBody()->getContents(), true);
165172
$productModels[] = $data['_embedded']['items'];
166173
}
@@ -209,12 +216,12 @@ function getProductModels(): array
209216

210217
#### 2. Process product model
211218
##### 2.1. Parse and store the product model
212-
Parse and store a product or a product model is definitely the same thing. Please have a how to our guided tutorial <a href="/tutorials/how-to-get-families-and-attributes.html" target="_blank" rel="noopener noreferrer">How to get families and attributes</a>.
219+
Parse and store a product or a product model is definitely the same thing. Please have a how to our guided tutorial <a href="/tutorials/how-to-get-families-and-attributes.html" target="_blank" rel="noopener noreferrer">How to get families, family variants, and attributes</a>.
213220

214221
##### 2.2. Collect its family variant
215222
###### 2.2.1 You are following the App workflow?
216223

217-
Good news: you already store the family variant in the guided tutorial <a href="/tutorials/how-to-get-families-and-attributes.html" target="_blank" rel="noopener noreferrer">How to get families and attributes</a>. Go ahead!
224+
Good news: you already store the family variant in the guided tutorial <a href="/tutorials/how-to-get-families-and-attributes.html" target="_blank" rel="noopener noreferrer">How to get families, family variants, and attributes</a>. Go ahead!
218225

219226
###### 2.2.2 You are not following the App workflow?
220227
Query the API.
@@ -282,15 +289,15 @@ function getProductVariants(): array
282289

283290
```
284291

285-
Again, treat each product like a simple product. Please refer to the guided tutorial <a href="/tutorials/how-to-get-families-and-attributes.html" target="_blank" rel="noopener noreferrer">How to get families and attributes</a>
292+
Again, treat each product like a simple product. Please refer to the guided tutorial <a href="/tutorials/how-to-get-families-and-attributes.html" target="_blank" rel="noopener noreferrer">How to get families, family variants, and attributes</a>
286293

287294
### Use case 2: Collect product variation information - set it all on 1 level
288295

289296
#### 1. Collect product models
290297

291298
##### 1.1 You are following the App workflow?
292299

293-
In the guided tutorial <a href="/tutorials/how-to-get-families-and-attributes.html" target="_blank" rel="noopener noreferrer">How to get families and attributes</a>, we have stored a **family_code_list**. It’s time to use it!
300+
In the guided tutorial <a href="/tutorials/how-to-get-families-and-attributes.html" target="_blank" rel="noopener noreferrer">How to get families, family variants, and attributes</a>, we have stored a **family_code_list**. It’s time to use it!
294301

295302
```php [activate:PHP]
296303

@@ -302,9 +309,10 @@ function getProductModels(): array
302309
$maxFamiliesPerQuery = 3;
303310
$scope = 'ecommerce';
304311

305-
// Get family codes and locales from storage
312+
// Get family codes from storage
306313
$familyCodes = getFamilyCodes();
307-
$locales = getLocales('fr');
314+
// Get locales from storage
315+
$locales = getLocales(); // ['en_US', 'fr_FR']
308316

309317
$familyCodeChunks = array_chunk($familyCodes, $maxFamiliesPerQuery);
310318

@@ -318,7 +326,14 @@ function getProductModels(): array
318326
// Collect product models from API
319327
$productModels = [];
320328
foreach ($familyCodeChunks as $familyCodes) {
321-
$response = $client->get(sprintf($apiUrl, $locales, $scope, json_encode($familyCodes)));
329+
$response = $client->get(
330+
sprintf(
331+
$apiUrl,
332+
implode(',', $locales),
333+
$scope,
334+
json_encode($familyCodes)
335+
)
336+
);
322337
$data = json_decode($response->getBody()->getContents(), true);
323338
$productModels[] = $data['_embedded']['items'];
324339
}
@@ -348,7 +363,7 @@ function getProductModels(): array
348363
##### 1.2 - You are not following the App workflow?
349364

350365
::: warning
351-
Make sure to get the list of your family variants before continuing like in <a href="/tutorials/how-to-get-families-and-attributes.html" target="_blank" rel="noopener noreferrer">How to get families and attributes</a>
366+
Make sure to get the list of your family variants before continuing like in <a href="/tutorials/how-to-get-families-and-attributes.html" target="_blank" rel="noopener noreferrer">How to get families, family variants, and attributes</a>
352367
:::
353368

354369
```php [activate:PHP]

0 commit comments

Comments
 (0)