Skip to content

Commit

Permalink
Get site based on Magento store ID (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinmeijer97 authored May 14, 2024
1 parent 07126f1 commit f8e0a8e
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/RapidezStatamicServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function bootComposers() : self
View::composer('rapidez::product.overview', function (RenderedView $view) {
$entry = Entry::query()
->where('collection', 'products')
->where('site', config('rapidez.store_code'))
->where('site', $this->getSiteHandleByStoreId())
->where('linked_product', config('frontend.product.sku'))
->first();

Expand All @@ -145,7 +145,7 @@ public function bootComposers() : self
View::composer('rapidez::category.overview', function (RenderedView $view) {
$entry = Entry::query()
->where('collection', 'categories')
->where('site', config('rapidez.store_code'))
->where('site', $this->getSiteHandleByStoreId())
->where('linked_category', config('frontend.category.entity_id'))
->first();

Expand Down Expand Up @@ -218,4 +218,13 @@ public function currentSiteIsEnabled(): bool
{
return !config('statamic.sites.sites.' . Site::current()->handle() . '.attributes.disabled', false);
}

public function getSiteHandleByStoreId(): string
{
$site = Site::all()
->filter(fn($_site) => ($_site?->attributes()['magento_store_id'] ?? null) === config('rapidez.store'))
->first();

return $site?->handle() ?? config('rapidez.store_code');
}
}

0 comments on commit f8e0a8e

Please sign in to comment.