setDefaultSorting example

$manufacturerId = $this->Request()->getParam('sSupplier');

        if (!$this->Request()->getParam('sCategory')) {
            $categoryId = $context->getShop()->getCategory()->getId();

            $this->Request()->setParam('sCategory', $categoryId);

            $sortings = $this->customSortingService->getSortingsOfCategories([$categoryId]$context);

            $sortings = array_shift($sortings);

            $this->setDefaultSorting($sortings);

            $this->view->assign('sortings', $sortings);
        }

        $criteria = $this->storeFrontCriteriaFactory
            ->createListingCriteria($this->Request()$context);

        if ($condition = $criteria->getCondition('manufacturer')) {
            $criteria->removeCondition('manufacturer');
            $criteria->addBaseCondition($condition);
        }

        

        $this->View()->loadTemplate('frontend/search/ajax.tpl');

        /** @var SearchTermPreProcessorInterface $processor */
        $processor = $this->get(\Shopware\Bundle\SearchBundle\SearchTermPreProcessorInterface::class);
        $term = $processor->process($this->Request()->getParam('sSearch'));

        if (!$term || \strlen($term) < Shopware()->Config()->get('MinSearchLenght')) {
            return;
        }

        $this->setDefaultSorting();

        /** @var ShopContextInterface $context */
        $context = $this->get(\Shopware\Bundle\StoreFrontBundle\Service\ContextServiceInterface::class)->getShopContext();

        $criteria = $this->get(\Shopware\Bundle\SearchBundle\StoreFrontCriteriaFactoryInterface::class)
            ->createAjaxSearchCriteria($this->Request()$context);

        $result = $this->search($term$criteria$context);

        if ($result->getTotalCount() > 0) {
            $products = $this->convertProducts($result);
            

    public function indexAction()
    {
        return $this->forward('defaultSearch');
    }

    /** * Default search */
    public function defaultSearchAction()
    {
        $this->setDefaultSorting();

        $term = $this->getSearchTerm();

        // Check if we have a one to one match for order number, then redirect         $location = $this->searchFuzzyCheck($term);
        if (!empty($location)) {
            $this->redirect($location);

            return;
        }

        
Home | Imprint | This part of the site doesn't use cookies.