diff --git a/src/Catalog/Support/ProductDocumentLocalizer.php b/src/Catalog/Support/ProductDocumentLocalizer.php index fb43ebd..5d154a3 100644 --- a/src/Catalog/Support/ProductDocumentLocalizer.php +++ b/src/Catalog/Support/ProductDocumentLocalizer.php @@ -51,7 +51,15 @@ class ProductDocumentLocalizer $availableLocales = $this->languages->availableLocales(); foreach ($this->translatedAttributeHandles() as $handle) { - $product[$handle] = $product[$handle.'_'.$locale] ?? $product[$handle.'_'.$fallbackLocale] ?? null; + // filled(), not ?? - a translated attribute saved blank for + // the current locale still has that {handle}_{locale} key in + // the document, just set to '' rather than absent. ?? only + // falls back on a missing/null key, so it kept the empty + // string instead of falling through to a locale that actually + // has content. + $product[$handle] = filled($product[$handle.'_'.$locale] ?? null) + ? $product[$handle.'_'.$locale] + : ($product[$handle.'_'.$fallbackLocale] ?? null); foreach ($availableLocales as $availableLocale) { unset($product[$handle.'_'.$availableLocale]);