getSortings example


    private function fetchCustomers(Criteria $criteria, QueryBuilder $query)
    {
        if ($criteria->getOffset() !== null) {
            $query->setFirstResult($criteria->getOffset());
        }
        if ($criteria->getLimit() !== null) {
            $query->setMaxResults($criteria->getLimit());
        }

        foreach ($criteria->getSortings() as $sorting) {
            $handler = $this->handlerRegistry->getSortingHandler($sorting);
            $handler->handle($sorting$query);
        }

        $query->addSelect('customer.id, customer.customernumber, customer.email');

        return $query->execute()->fetchAll(PDO::FETCH_ASSOC);
    }

    private function fetchTotal(QueryBuilder $query)
    {
        
$customSortings = $this->customSortingService->getList(
            [(int) $request->getParam('sSort')],
            $context
        );

        if (\count($customSortings) === 0) {
            return;
        }

        $customSorting = array_shift($customSortings);
        foreach ($customSorting->getSortings() as $sorting) {
            $criteria->addSorting($sorting);
        }
    }
}
$data['hits']['total'],
            $facets,
            $result->getAttributes()
        );
    }

    private function buildSearch(Criteria $criteria, ShopContextInterface $context): EsSearch
    {
        $search = new EsSearch();

        $this->addConditions($criteria$context$search);
        $this->addCriteriaParts($criteria$context$search$criteria->getSortings());
        $this->addCriteriaParts($criteria$context$search$criteria->getFacets());

        if ($criteria->getOffset() !== null) {
            $search->setFrom($criteria->getOffset());
        }
        if ($criteria->getLimit() !== null) {
            $search->setSize($criteria->getLimit());
        }

        $search->addSort(new FieldSort('id', 'asc'));

        

    public function unserialize($serializedConditions)
    {
        return $this->reflector->unserialize($serializedConditions, 'Serialization error in Product stream');
    }

    private function prepareConditionStream(array $productStream, Criteria $criteria): void
    {
        $this->assignConditions($productStream$criteria);

        $sortings = $criteria->getSortings();
        if (empty($sortings)) {
            $this->assignSortings($productStream$criteria);
        }
    }

    private function prepareSelectionStream(array $productStream, Criteria $criteria): void
    {
        $productIds = $this->getProductIds((int) $productStream['id']);
        $criteria->addBaseCondition(new ProductIdCondition($productIds));

        $sortings = $criteria->getSortings();
        
private function addConditions(Criteria $criteria, QueryBuilder $query, ShopContextInterface $context)
    {
        foreach ($criteria->getConditions() as $condition) {
            $handler = $this->getConditionHandler($condition);
            $handler->generateCondition($condition$query$context);
        }
    }

    private function addSorting(Criteria $criteria, QueryBuilder $query, ShopContextInterface $context)
    {
        foreach ($criteria->getSortings() as $sorting) {
            $handler = $this->getSortingHandler($sorting);
            $handler->generateSorting($sorting$query$context);
        }
        $query->addOrderBy('variant.id', 'ASC');
    }

    /** * @throws Exception * * @return SortingHandlerInterface */
    
if ($comparableCriteria == $existingCriteria) {
                return $index;
            }
        }

        return false;
    }

    private function getComparableCriteria(Criteria $criteria): Criteria
    {
        $conditions = $criteria->getConditions();
        $sortings = $criteria->getSortings();

        usort($conditionsfunction DConditionInterface $a, ConditionInterface $b) {
            return strnatcmp($a->getName()$b->getName());
        });

        usort($sortingsfunction DSortingInterface $a, SortingInterface $b) {
            return strnatcmp($a->getName()$b->getName());
        });

        $criteria = new Criteria();

        
$this->mediaService = $mediaService;
    }

    public function load(int $categoryId, ?int $start, ?int $limit, CustomSorting $customSorting): array
    {
        $criteria = new Criteria();
        $criteria->addBaseCondition(new CategoryCondition([$categoryId]));
        $criteria->addSorting(new ManualSorting());
        $criteria->offset($start);
        $criteria->limit($limit);

        foreach ($customSorting->getSortings() as $sorting) {
            $criteria->addSorting($sorting);
        }

        $query = $this->queryBuilderFactory->createQueryWithSorting($criteria$this->contextService->getShopContext());

        $data = [];
        $query
            ->leftJoin('variant', 's_articles_prices', 'price', 'price.articledetailsID = variant.id AND price.from = 1 AND price.pricegroup = \'EK\'')
            ->leftJoin('product', 's_core_tax', 'tax', 'tax.id = product.taxID')
            

        return $this->connection->createQueryBuilder()
            ->select(['plugin.name', 'plugin.version'])
            ->from('s_core_plugins', 'plugin')
            ->where('plugin.capability_update = 1')
            ->execute()
            ->fetchAll(PDO::FETCH_KEY_PAIR);
    }

    private function addSortings(ListingRequest $context, QueryBuilder $builder): void
    {
        foreach ($context->getSortings() as $sort) {
            if (!isset($sort['property'])) {
                continue;
            }
            $sortDirection = $sort['direction'] ?? 'ASC';

            $builder->addOrderBy($sort['property']$sortDirection);
        }
    }

    /** * @param array<string, mixed> $plugins * * @return PluginStruct[] */
private function getSortings(int $categoryId): ?array
    {
        $context = $this->contextService->getShopContext();

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

        return array_shift($customSortings);
    }

    private function getSorting(int $categoryId, int $sortingId): ?CustomSorting
    {
        $sortings = $this->getSortings($categoryId);
        if (!\is_array($sortings)) {
            return null;
        }

        foreach ($sortings as $sorting) {
            if ($sorting->getId() === $sortingId) {
                return $sorting;
            }
        }

        return null;
    }

    }

    public function getSortingsAction(int $categoryId): void
    {
        $this->View()->assign('success', true);
        $this->View()->assign('data', array_values(array_map(static function DCustomSorting $sorting) {
            return [
                'id' => $sorting->getId(),
                'name' => $sorting->getLabel(),
            ];
        }$this->getSortings($categoryId))));
    }

    /** * @return CustomSorting[] */
    private function getSortings(int $categoryId): array
    {
        $context = $this->get(\Shopware\Bundle\StoreFrontBundle\Service\ContextServiceInterface::class)->getShopContext();

        return current($this->get(\Shopware\Bundle\StoreFrontBundle\Service\CustomSortingServiceInterface::class)->getSortingsOfCategories([$categoryId]$context));
    }

    

    public function getListing(ListingRequest $context)
    {
        $params = [
            'locale' => $context->getLocale(),
            'shopwareVersion' => $context->getShopwareVersion(),
            'offset' => $context->getOffset(),
            'limit' => $context->getLimit(),
            'sort' => json_encode($context->getSortings()),
            'filter' => json_encode($context->getConditions()),
        ];

        $data = $this->storeClient->doGetRequest(
            '/pluginStore/plugins',
            $params
        );

        $plugins = $this->hydrator->hydrateStorePlugins($data['data']);

        return new ListingResultStruct(
            
Home | Imprint | This part of the site doesn't use cookies.