Skip to content

Commit 7a8bd32

Browse files
samokissSamuel GomisLevFlavien
authored
fix(API-1962): fix snippet (#717)
* fix(API-1962): fix snippet * Update content/tutorials/guides/how-to-get-families-and-attributes.md Co-authored-by: LevFlavien <[email protected]> * fix(API-1962): add deprecation in doc getting-started/synchronize-pim-products-6x Co-authored-by: Samuel Gomis <[email protected]> Co-authored-by: LevFlavien <[email protected]>
1 parent a175106 commit 7a8bd32

File tree

3 files changed

+37
-30
lines changed

3 files changed

+37
-30
lines changed

content/getting-started/synchronize-pim-products-6x/step-4.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Synchronize products and product models
22

3+
:::warning
4+
This guide is being deprecated and will soon be unpublished. Please go to the newest guide [here](/tutorials/how-to-get-pim-product-information.html).
5+
:::
6+
37
## Products synchronization
48

59
### What do we synchronize?

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

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,6 @@ In this tutorial, we will introduce you to the two use cases you may encounter f
100100
**Use case 2**
101101
<br>
102102
We noticed that many e-commerce solutions understand product variation on only one level. This means that for Akeneo **a special recollection of the variations must be done to have them all on the same level.**
103-
<br>
104-
Stay tuned! Our teams are currently working on this specific use case and should release it very soon.
105103
:::
106104

107105
### 0 - Initialization
@@ -340,24 +338,19 @@ function getProductModels(): array
340338

341339
$productModels = array_merge(...$productModels);
342340

343-
// Get variants from storage
344-
$variants = getVariants();
341+
$familyVariants = getFamilyVariantsFromStorage();
345342
foreach ($productModels as $key => $productModel) {
346-
foreach ($variants as $variant) {
347-
if ($productModel['family_variant'] === $variant['code']) {
348-
// extract all variations level
349-
$axes = array_column($variant['variant_attribute_sets'], 'axes');
350-
// build flat axes
351-
$axes = array_column($axes, 0);
352-
$productModels[$key]['axes'] = $axes;
353-
}
354-
}
343+
$familyVariant = $familyVariants[$productModel['family_variant']];
344+
// extract all variations level
345+
$axes = array_column($familyVariant['variant_attribute_sets'], 'axes');
346+
// build flat axes
347+
$productModels[$key]['axes'] = array_merge(...$axes);
348+
355349
}
356350

357351
saveProductModels($productModels);
358352
}
359353

360-
361354
```
362355

363356
##### 1.2 - You are not following the App workflow?
@@ -394,18 +387,13 @@ function getProductModels(): array
394387

395388
$productModels = array_merge(...$productModels);
396389

397-
// Get variants from storage
398-
$variants = getVariants();
390+
$familyVariants = getFamilyVariantsFromStorage();
399391
foreach ($productModels as $key => $productModel) {
400-
foreach ($variants as $variant) {
401-
if ($productModel['family_variant'] === $variant['code']) {
402-
// extract all variations level
403-
$axes = array_column($variant['variant_attribute_sets'], 'axes');
404-
// build flat axes
405-
$axes = array_column($axes, 0);
406-
$productModels[$key]['axes'] = $axes;
407-
}
408-
}
392+
$familyVariant = $familyVariants[$productModel['family_variant']];
393+
// extract all variations level
394+
$axes = array_column($familyVariant['variant_attribute_sets'], 'axes');
395+
// build flat axes
396+
$productModels[$key]['axes'] = array_merge(...$axes);
409397
}
410398

411399
saveProductModels($productModels);

content/tutorials/guides/how-to-get-families-and-attributes.md

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,16 +147,31 @@ const API_URL = '/api/rest/v1/families/%s/variants?limit=' . MAX_ITEMS;
147147
// Get family codes from storage
148148
$codes = getFamilyCodes();
149149

150-
// Collect family variants from paginated API
151-
$variants = [];
150+
// Collect family variants from API
151+
$familyVariants = [];
152152
foreach ($codes as $code) {
153153
$response = $client->get(sprintf(API_URL, $code));
154154
$data = json_decode($response->getBody()->getContents(), true);
155-
$variants = array_merge($variants, $data['_embedded']['items']);
155+
$familyVariants[] = $data['_embedded']['items'];
156+
157+
while (array_key_exists('next', $data['_links'])) {
158+
$response = $client->get($data['_links']['next']['href']);
159+
$data = json_decode($response->getBody()->getContents(), true);
160+
$familyVariants[] = $data['_embedded']['items'];
161+
}
156162
}
157163

158-
// Save variants into storage
159-
saveVariants($variants);
164+
$familyVariants = array_merge(...$familyVariants);
165+
166+
//add index to $familyVariants
167+
$indexedFamilyVariants = [];
168+
foreach ($familyVariants as $familyVariant) {
169+
$indexedFamilyVariants[$familyVariant['code']] = $familyVariant;
170+
}
171+
172+
// Save family variants into storage
173+
saveFamilyVariants($indexedFamilyVariants);
174+
160175
```
161176

162177
### 3 - Collect attributes

0 commit comments

Comments
 (0)