示例#1
0
 /**
  * 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')));
 }
 public function testCanBeInitializedByArray()
 {
     $mapping = ['foo' => 'bar', 'omg' => 'baz'];
     $mapper = new QueryAliasMapper($mapping);
     $this->assertEquals($mapping, $mapper->getQueryAliases());
 }