Skip to content

Commit 03f206c

Browse files
authored
Propagate Shopify translations to entry localizations (#313)
Signed-off-by: Philipp Daun <[email protected]>
1 parent 6c81c11 commit 03f206c

File tree

3 files changed

+8
-15
lines changed

3 files changed

+8
-15
lines changed

docs/content/en/CMS/multisite.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Ensure your API key has enabled the `read_translations` permission for this feat
1414

1515
You need to enable multi-site on the `Products` collection and `Collections`, `Product Types`, `Tags` and `Vendor` taxonomies. You can do this by editing the configuration and adding the sites you want to enable to the `sites` field.
1616

17-
On the Products collection ensure that `Propogate` is toggled on, and that the `Origin Behaviour` is set to `Use the site the entry was created in`.
17+
On the Products collection ensure that `Propagate` is toggled on, and that the `Origin Behaviour` is set to `Use the site the entry was created in`.
1818

1919
## How it works
2020

src/Jobs/ImportSingleProductJob.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ public function handle()
350350

351351
$translations = Arr::get($response->getDecodedBody(), 'data.translatableResource.translations', []);
352352

353-
if ($translations) {
353+
if ($translations || $entry->collection()->propagate()) {
354354
$localizedEntry = $entry->in($site->handle());
355355

356356
if (! $localizedEntry) {
@@ -503,7 +503,7 @@ private function importVariants(array $returnedVariants, string $product_slug)
503503

504504
$translations = Arr::get($response->getDecodedBody(), 'data.translatableResource.translations', []);
505505

506-
if ($translations) {
506+
if ($translations || $entry->collection()->propagate()) {
507507
$localizedEntry = $entry->in($site->handle());
508508

509509
if (! $localizedEntry) {

src/Tags/Shopify.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -249,18 +249,11 @@ protected function fetchProductVariants($productSlug)
249249
return null;
250250
}
251251

252-
return $entries->map(function ($variant) {
253-
$values = [];
254-
$values['id'] = $variant->id();
255-
$values['slug'] = $variant->slug();
256-
257-
// Map all variant values to data to ensure we are getting everything.
258-
foreach ($variant->data() as $key => $value) {
259-
$values[$key] = $value;
260-
}
261-
262-
return $values;
263-
});
252+
return $entries->map(fn ($variant) => [
253+
'id' => $variant->id(),
254+
'slug' => $variant->slug(),
255+
...$variant->values(),
256+
])->unique('variant_id')->values();
264257
}
265258

266259
/**

0 commit comments

Comments
 (0)