This commit is contained in:
Peter Bech
2019-10-10 14:16:47 +02:00
parent 668a1cb636
commit da59b50e8f
3 changed files with 14 additions and 12 deletions
@@ -17,25 +17,34 @@ use FOS\RestBundle\View\ViewHandler;
use Sylius\Component\Taxonomy\Repository\TaxonRepositoryInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Sylius\Component\Locale\Context\LocaleContextInterface;
final class TaxonSearchAction
{
/** @var TaxonRepositoryInterface */
private $taxonRepository;
/** @var LocaleContextInterface */
private $localeContext;
/** @var ViewHandler */
private $viewHandler;
public function __construct(TaxonRepositoryInterface $taxonRepository, ViewHandler $viewHandler)
public function __construct(
TaxonRepositoryInterface $taxonRepository,
LocaleContextInterface $localeContext,
ViewHandler $viewHandler
)
{
$this->taxonRepository = $taxonRepository;
$this->localeContext = $localeContext;
$this->viewHandler = $viewHandler;
}
public function __invoke(Request $request): Response
{
$product = $this->taxonRepository->findByNamePart($request->get('phrase', ''));
$view = View::create($product);
$taxon = $this->taxonRepository->findByNamePart($request->get('phrase', ''), $this->localeContext->getLocaleCode());
$view = View::create($taxon);
$this->viewHandler->setExclusionStrategyGroups(['Autocomplete']);
$view->getContext()->enableMaxDepth();
+2 -1
View File
@@ -17,7 +17,8 @@ services:
class: BitBag\SyliusCmsPlugin\Controller\Action\Admin\TaxonSearchAction
public: true
arguments:
- "@bitbag_sylius_cms_plugin.repository.taxon"
- "@sylius.repository.taxon"
- "@sylius.context.locale"
- "@fos_rest.view_handler.default"
bitbag_sylius_cms_plugin.controller.action.admin.import_data:
@@ -1,8 +0,0 @@
services:
bitbag_sylius_cms_plugin.repository.product:
class: BitBag\SyliusCmsPlugin\Repository\ProductRepository
parent: sylius.repository.taxon
bitbag_sylius_cms_plugin.repository.taxon:
class: BitBag\SyliusCmsPlugin\Repository\TaxonRepository
parent: sylius.repository.taxon