/** * @param PropertyGatewayInterface $propertyGateway * @param QueryBuilderFactory $queryBuilderFactory * @param QueryAliasMapper $queryAliasMapper */ public function __construct(PropertyGatewayInterface $propertyGateway, QueryBuilderFactory $queryBuilderFactory, QueryAliasMapper $queryAliasMapper) { $this->propertyGateway = $propertyGateway; $this->queryBuilderFactory = $queryBuilderFactory; if (!($this->fieldName = $queryAliasMapper->getShortAlias('sFilterProperties'))) { $this->fieldName = 'sFilterProperties'; } }
/** * @param QueryBuilderFactory $queryBuilderFactory * @param \Shopware_Components_Snippet_Manager $snippetManager * @param QueryAliasMapper $queryAliasMapper */ public function __construct(QueryBuilderFactory $queryBuilderFactory, \Shopware_Components_Snippet_Manager $snippetManager, QueryAliasMapper $queryAliasMapper) { $this->queryBuilderFactory = $queryBuilderFactory; $this->snippetNamespace = $snippetManager->getNamespace('frontend/listing/facet_labels'); if (!($this->fieldName = $queryAliasMapper->getShortAlias('shippingFree'))) { $this->fieldName = 'shippingFree'; } }
/** * @param ManufacturerServiceInterface $manufacturerService * @param QueryBuilderFactory $queryBuilderFactory * @param \Shopware_Components_Snippet_Manager $snippetManager * @param QueryAliasMapper $queryAliasMapper */ public function __construct(ManufacturerServiceInterface $manufacturerService, QueryBuilderFactory $queryBuilderFactory, \Shopware_Components_Snippet_Manager $snippetManager, QueryAliasMapper $queryAliasMapper) { $this->manufacturerService = $manufacturerService; $this->queryBuilderFactory = $queryBuilderFactory; $this->snippetNamespace = $snippetManager->getNamespace('frontend/listing/facet_labels'); if (!($this->fieldName = $queryAliasMapper->getShortAlias('sSupplier'))) { $this->fieldName = 'sSupplier'; } }
/** * @param CategoryServiceInterface $categoryService * @param QueryBuilderFactory $queryBuilderFactory * @param \Shopware_Components_Snippet_Manager $snippetManager * @param QueryAliasMapper $queryAliasMapper * @param Connection $connection */ public function __construct(CategoryServiceInterface $categoryService, QueryBuilderFactory $queryBuilderFactory, \Shopware_Components_Snippet_Manager $snippetManager, QueryAliasMapper $queryAliasMapper, Connection $connection) { $this->categoryService = $categoryService; $this->queryBuilderFactory = $queryBuilderFactory; $this->snippetNamespace = $snippetManager->getNamespace('frontend/listing/facet_labels'); $this->connection = $connection; if (!($this->fieldName = $queryAliasMapper->getShortAlias('sCategory'))) { $this->fieldName = 'sCategory'; } }
/** * @param PriceHelper $priceHelper * @param QueryBuilderFactory $queryBuilderFactory * @param \Shopware_Components_Snippet_Manager $snippetManager * @param QueryAliasMapper $queryAliasMapper */ public function __construct(PriceHelper $priceHelper, QueryBuilderFactory $queryBuilderFactory, \Shopware_Components_Snippet_Manager $snippetManager, QueryAliasMapper $queryAliasMapper) { $this->priceHelper = $priceHelper; $this->queryBuilderFactory = $queryBuilderFactory; $this->snippetNamespace = $snippetManager->getNamespace('frontend/listing/facet_labels'); if (!($this->minFieldName = $queryAliasMapper->getShortAlias('priceMin'))) { $this->minFieldName = 'priceMin'; } if (!($this->maxFieldName = $queryAliasMapper->getShortAlias('priceMax'))) { $this->maxFieldName = 'priceMax'; } }
/** * @param Criteria $criteria * @param $items * @return ValueListFacetResult */ private function createFacet(Criteria $criteria, $items) { if (!($fieldName = $this->queryAliasMapper->getShortAlias('sSupplier'))) { $fieldName = 'sSupplier'; } $label = $this->snippetManager->getNamespace('frontend/listing/facet_labels')->get('manufacturer', 'Manufacturer'); return new ValueListFacetResult('manufacturer', $criteria->hasCondition('manufacturer'), $label, $items, $fieldName); }
/** * @param Criteria $criteria * @return BooleanFacetResult */ private function createFacet(Criteria $criteria) { $label = $this->snippetManager->getNamespace('frontend/listing/facet_labels')->get('immediate_delivery', 'Immediate delivery'); if (!($fieldName = $this->queryAliasMapper->getShortAlias('immediateDelivery'))) { $fieldName = 'immediateDelivery'; } $criteriaPart = new BooleanFacetResult('immediate_delivery', $fieldName, $criteria->hasCondition('immediate_delivery'), $label); return $criteriaPart; }
/** * @param Category[] $categories * @param int[] $active * @return TreeFacetResult */ private function createTreeFacet($categories, $active) { $items = $this->getCategoriesOfParent($categories, null); $values = []; foreach ($items as $item) { $values[] = $this->createTreeItem($categories, $item, $active); } $label = $this->snippetManager->getNamespace('frontend/listing/facet_labels')->get('category', 'Categories'); if (!($fieldName = $this->queryAliasMapper->getShortAlias('sCategory'))) { $fieldName = 'sCategory'; } return new TreeFacetResult('category', $fieldName, empty($active), $label, $values, [], null); }
/** * @param Criteria $criteria * @return RadioFacetResult */ private function createFacet(Criteria $criteria) { $activeAverage = null; if ($criteria->hasCondition('vote_average')) { /**@var $condition VoteAverageCondition*/ $condition = $criteria->getCondition('vote_average'); $activeAverage = $condition->getAverage(); } $values = [new ValueListItem(1, '', $activeAverage == 1), new ValueListItem(2, '', $activeAverage == 2), new ValueListItem(3, '', $activeAverage == 3), new ValueListItem(4, '', $activeAverage == 4), new ValueListItem(5, '', $activeAverage == 5)]; $label = $this->snippetManager->getNamespace('frontend/listing/facet_labels')->get('vote_average', 'Ranking'); if (!($fieldName = $this->queryAliasMapper->getShortAlias('rating'))) { $fieldName = 'rating'; } return new RadioFacetResult('vote_average', $criteria->hasCondition('vote_average'), $label, $values, $fieldName, [], 'frontend/listing/filter/facet-rating.tpl'); }
/** * @param Criteria $criteria * @param float $min * @param float $max * @return RangeFacetResult */ private function createFacet(Criteria $criteria, $min, $max) { $activeMin = $min; $activeMax = $max; /**@var $condition PriceCondition */ if ($condition = $criteria->getCondition('price')) { $activeMin = $condition->getMinPrice(); $activeMax = $condition->getMaxPrice(); } $label = $this->snippetManager->getNamespace('frontend/listing/facet_labels')->get('price', 'Price'); if (!($minFieldName = $this->queryAliasMapper->getShortAlias('priceMin'))) { $minFieldName = 'priceMin'; } if (!($maxFieldName = $this->queryAliasMapper->getShortAlias('priceMax'))) { $maxFieldName = 'priceMax'; } return new RangeFacetResult('price', $criteria->hasCondition('price'), $label, (double) $min, (double) $max, (double) $activeMin, (double) $activeMax, $minFieldName, $maxFieldName, [], 'frontend/listing/filter/facet-currency-range.tpl'); }
/** * {@inheritdoc} */ public function match($pathInfo, Context $context) { if (strpos($pathInfo, '/backend/') === 0 || strpos($pathInfo, '/api/') === 0) { return $pathInfo; } if ($context->getShopId() === null) { // only frontend return $pathInfo; } // Rewrites queries $params = $context->getParams(); $params = $this->queryAliasMapper->replaceShortParams($params); /* templates/_emotion/frontend/_resources/javascript/jquery.shopware.js */ if (isset($params['sAction'])) { $params['action'] = $params['sAction']; } if (isset($params['sViewport'])) { $params['controller'] = $params['sViewport']; } $context->setParams($params); // /widgets and /index supports short request queries if ($pathInfo === '/' || strpos($pathInfo, '/widgets/') === 0) { return $pathInfo; } $pathInfo = ltrim($pathInfo, '/'); $statement = $this->getRouteStatement(); $statement->bindValue(':shopId', $context->getShopId(), \PDO::PARAM_INT); $statement->bindValue(':pathInfo', $pathInfo, \PDO::PARAM_STR); if ($statement->execute() && $statement->rowCount() > 0) { $route = $statement->fetch(\PDO::FETCH_ASSOC); $query = $this->getQueryFormOrgPath($route['orgPath']); if (empty($route['main']) || $route['shopId'] != $context->getShopId()) { $query['rewriteAlias'] = true; } else { $query['rewriteUrl'] = true; } return $query; } return $pathInfo; }
/** * @param Group[] $groups * @param int[] $actives * @return FacetResultGroup */ private function createCollectionResult(array $groups, $actives) { $results = []; if (!($fieldName = $this->queryAliasMapper->getShortAlias('sFilterProperties'))) { $fieldName = 'sFilterProperties'; } foreach ($groups as $group) { $items = []; $useMedia = false; $isActive = false; foreach ($group->getOptions() as $option) { $listItem = new MediaListItem($option->getId(), $option->getName(), in_array($option->getId(), $actives), $option->getMedia()); $isActive = $isActive || $listItem->isActive(); $useMedia = $useMedia || $listItem->getMedia() !== null; $items[] = $listItem; } if ($useMedia) { $results[] = new MediaListFacetResult('property', $isActive, $group->getName(), $items, $fieldName); } else { $results[] = new ValueListFacetResult('property', $isActive, $group->getName(), $items, $fieldName); } } return new FacetResultGroup($results, null, 'property'); }
/** * Returns a listing of products. Used for the backward compatibility category listings. * This function calls the new shopware core and converts the result to the old listing structure. * * @param $categoryId * @param StoreFrontBundle\Struct\ProductContextInterface $context * @param Enlight_Controller_Request_Request $request * @param SearchBundle\Criteria $criteria * @return array */ private function getListing($categoryId, StoreFrontBundle\Struct\ProductContextInterface $context, Enlight_Controller_Request_Request $request, SearchBundle\Criteria $criteria) { $searchResult = $this->searchService->search($criteria, $context); $articles = array(); /**@var $product StoreFrontBundle\Struct\ListProduct */ foreach ($searchResult->getProducts() as $product) { $article = $this->legacyStructConverter->convertListProductStruct($product); if (!empty($categoryId) && $categoryId != $context->getShop()->getCategory()->getId()) { $article["linkDetails"] .= "&sCategory={$categoryId}"; } if (isset($article['sVoteAverange']) && !empty($article['sVoteAverange'])) { // the listing pages use a 0 - 5 based average $article['sVoteAverange']['averange'] = $article['sVoteAverange']['averange'] / 2; } if ($this->config->get('useShortDescriptionInListing') && strlen($article['description']) > 5) { $article["description_long"] = $article['description']; } $article['description_long'] = $this->sOptimizeText($article['description_long']); $articles[$article['ordernumber']] = $article; } $pageSizes = explode("|", $this->config->get('numberArticlesToShow')); return array('sArticles' => $articles, 'criteria' => $criteria, 'facets' => $searchResult->getFacets(), 'sPage' => $request->getParam('sPage', 1), 'pageSizes' => $pageSizes, 'sPerPage' => $criteria->getLimit(), 'sNumberArticles' => $searchResult->getTotalCount(), 'shortParameters' => $this->queryAliasMapper->getQueryAliases(), 'sTemplate' => $request->getParam('sTemplate'), 'sSort' => $request->getParam('sSort', $this->config->get('defaultListingSorting'))); }
protected function getQueryAliasMapperService() { return $this->services['query_alias_mapper'] = \Shopware\Components\QueryAliasMapper::createFromConfig($this->get('config')); }
public function testRequestQueriesGettingReplacd() { $request = new \Enlight_Controller_Request_RequestHttp(); $request->setQuery('q', 'someValue'); $request->setQuery('p', 'someOtherValue'); $request->setQuery('someParam', 'someValue'); $mapping = ['sSearch' => 'q', 'sPage' => 'p']; $mapper = new QueryAliasMapper($mapping); $mapper->replaceShortRequestQueries($request); $expected = ['someParam' => 'someValue', 'sSearch' => 'someValue', 'sPage' => 'someOtherValue']; $this->assertEquals($expected, $request->getParams()); }
/** * @param array $query * @return string */ private function rewriteQuery($query) { $tmp = $this->queryAliasMapper->replaceLongParams($query); return http_build_query($tmp, '', '&'); }