-
-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Store] optimize Store Context resolving with fallback and admin/non-…
…admin
- Loading branch information
1 parent
7164bfa
commit d556fdd
Showing
5 changed files
with
101 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/CoreShop/Component/Store/Context/SiteBasedResolver.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* CoreShop | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - CoreShop Commercial License (CCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) CoreShop GmbH (https://www.coreshop.org) | ||
* @license https://www.coreshop.org/license GPLv3 and CCL | ||
* | ||
*/ | ||
|
||
namespace CoreShop\Component\Store\Context; | ||
|
||
use CoreShop\Component\Store\Model\StoreInterface; | ||
use CoreShop\Component\Store\Repository\StoreRepositoryInterface; | ||
use Pimcore\Model\Site; | ||
|
||
class SiteBasedResolver implements SiteBasedResolverInterface | ||
{ | ||
public function __construct( | ||
private StoreRepositoryInterface $storeRepository, | ||
) { | ||
} | ||
|
||
public function resolveSiteWithDefaultForStore(?Site $site): ?StoreInterface | ||
{ | ||
if (null !== $site) { | ||
$store = $this->storeRepository->findOneBySite($site->getId()); | ||
|
||
if ($store !== null) { | ||
return $store; | ||
} | ||
} | ||
|
||
$defaultStore = $this->storeRepository->findStandard(); | ||
|
||
if ($defaultStore) { | ||
return $defaultStore; | ||
} | ||
|
||
return null; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/CoreShop/Component/Store/Context/SiteBasedResolverInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* CoreShop | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - CoreShop Commercial License (CCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) CoreShop GmbH (https://www.coreshop.org) | ||
* @license https://www.coreshop.org/license GPLv3 and CCL | ||
* | ||
*/ | ||
|
||
namespace CoreShop\Component\Store\Context; | ||
|
||
use CoreShop\Component\Store\Model\StoreInterface; | ||
use Pimcore\Model\Site; | ||
|
||
interface SiteBasedResolverInterface | ||
{ | ||
public function resolveSiteWithDefaultForStore(?Site $site): ?StoreInterface; | ||
} |