-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[shopsys] added order filter by domain in admin (#2796)
- Loading branch information
Showing
11 changed files
with
191 additions
and
162 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Shopsys\FrameworkBundle\Component\Domain; | ||
|
||
use Shopsys\FrameworkBundle\Component\Domain\Config\DomainConfig; | ||
use Shopsys\FrameworkBundle\Component\Domain\Exception\InvalidDomainIdException; | ||
use Symfony\Component\HttpFoundation\Exception\SessionNotFoundException; | ||
use Symfony\Component\HttpFoundation\RequestStack; | ||
|
||
class AdminDomainFilterTabsFacade | ||
{ | ||
protected const SESSION_PREFIX = 'admin_domain_filter_tabs_'; | ||
|
||
/** | ||
* @param \Symfony\Component\HttpFoundation\RequestStack $requestStack | ||
* @param \Shopsys\FrameworkBundle\Component\Domain\Domain $domain | ||
*/ | ||
public function __construct( | ||
protected readonly RequestStack $requestStack, | ||
protected readonly Domain $domain, | ||
) { | ||
} | ||
|
||
/** | ||
* @param string $namespace | ||
* @return int|null | ||
*/ | ||
public function getSelectedDomainId(string $namespace): ?int | ||
{ | ||
return $this->getSelectedDomainConfig($namespace)?->getId(); | ||
} | ||
|
||
/** | ||
* @param string $namespace | ||
* @param int|null $domainId | ||
*/ | ||
public function setSelectedDomainId(string $namespace, ?int $domainId): void | ||
{ | ||
$this->requestStack->getSession()->set($this->getSessionKey($namespace), $domainId); | ||
} | ||
|
||
/** | ||
* @param string $namespace | ||
* @return \Shopsys\FrameworkBundle\Component\Domain\Config\DomainConfig|null | ||
*/ | ||
public function getSelectedDomainConfig(string $namespace): ?DomainConfig | ||
{ | ||
try { | ||
$domainId = $this->requestStack->getSession()->get($this->getSessionKey($namespace)); | ||
|
||
if ($domainId === null) { | ||
return null; | ||
} | ||
|
||
return $this->domain->getDomainConfigById($domainId); | ||
} catch (InvalidDomainIdException|SessionNotFoundException) { | ||
$this->requestStack->getSession()->set($this->getSessionKey($namespace), null); | ||
|
||
return null; | ||
} | ||
} | ||
|
||
/** | ||
* @param string $namespace | ||
* @return string | ||
*/ | ||
protected function getSessionKey(string $namespace): string | ||
{ | ||
return static::SESSION_PREFIX . $namespace; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Shopsys\FrameworkBundle\Controller\Admin; | ||
|
||
use Shopsys\FrameworkBundle\Component\Domain\AdminDomainFilterTabsFacade; | ||
use Shopsys\FrameworkBundle\Component\Domain\Domain; | ||
use Symfony\Component\HttpFoundation\RedirectResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
|
||
class DomainFilterController extends AdminBaseController | ||
{ | ||
/** | ||
* @param \Shopsys\FrameworkBundle\Component\Domain\Domain $domain | ||
* @param \Shopsys\FrameworkBundle\Component\Domain\AdminDomainFilterTabsFacade $adminDomainFilterTabsFacade | ||
*/ | ||
public function __construct( | ||
protected readonly Domain $domain, | ||
protected readonly AdminDomainFilterTabsFacade $adminDomainFilterTabsFacade, | ||
) { | ||
} | ||
|
||
/** | ||
* @param string $namespace | ||
* @return \Symfony\Component\HttpFoundation\Response | ||
*/ | ||
public function domainFilterTabsAction(string $namespace): Response | ||
{ | ||
return $this->render('@ShopsysFramework/Admin/Inline/Domain/filter.html.twig', [ | ||
'domainConfigs' => $this->domain->getAll(), | ||
'namespace' => $namespace, | ||
'selectedDomainId' => $this->adminDomainFilterTabsFacade->getSelectedDomainId($namespace), | ||
]); | ||
} | ||
|
||
/** | ||
* @Route("/multidomain/filter-domain/{namespace}/{domainId}", requirements={"domainId" = "\d+"}) | ||
* @param \Symfony\Component\HttpFoundation\Request $request | ||
* @param string $namespace | ||
* @param int|null $domainId | ||
* @return \Symfony\Component\HttpFoundation\RedirectResponse | ||
*/ | ||
public function selectDomainAction(Request $request, string $namespace, ?int $domainId = null): RedirectResponse | ||
{ | ||
$this->adminDomainFilterTabsFacade->setSelectedDomainId($namespace, $domainId); | ||
|
||
$referer = $request->server->get('HTTP_REFERER'); | ||
|
||
if ($referer === null) { | ||
return $this->redirectToRoute('admin_default_dashboard'); | ||
} | ||
|
||
return $this->redirect($referer); | ||
} | ||
} |
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
Oops, something went wrong.