Skip to content

Commit cd35254

Browse files
authored
Alternate hreflang tags; also show current store (#831)
1 parent dffdd04 commit cd35254

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/Models/Traits/HasAlternatesThroughRewrites.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,25 @@ trait HasAlternatesThroughRewrites
1010
protected function alternates(): Attribute
1111
{
1212
return Attribute::make(
13-
get: fn () => $this
14-
->rewrites()
15-
->where('redirect_type', 0)
16-
->whereHas('store', fn ($query) => $query->where('store.group_id', config('rapidez.group')))
17-
->whereNot('store_id', config('rapidez.store'))
18-
->pluck('request_path', 'store_id')
19-
->mapWithKeys(function ($url, $storeId) {
13+
get: function () {
14+
$rewrites = $this->rewrites()
15+
->where('redirect_type', 0)
16+
->whereHas('store', fn ($query) => $query->where('store.group_id', config('rapidez.group')))
17+
->pluck('request_path', 'store_id');
18+
19+
if (! $rewrites->keys()->contains(fn ($store) => $store !== config('rapidez.store'))) {
20+
return collect();
21+
}
22+
23+
return $rewrites->mapWithKeys(function ($url, $storeId) {
2024
return Rapidez::withStore($storeId, function () use ($url) {
2125
$locale = str(Rapidez::config('general/locale/code', 'en_US'))->replace('_', '-')->lower()->value();
2226
$url = Rapidez::config('web/secure/base_url') . $url;
2327

2428
return [$locale => $url];
2529
});
26-
})
30+
});
31+
}
2732
);
2833
}
2934
}

0 commit comments

Comments
 (0)