Ejemplo n.º 1
0
 public function loadPreviewAction()
 {
     $conditions = $this->Request()->getParam('conditions');
     $conditions = json_decode($conditions, true);
     $sorting = $this->Request()->getParam('sort');
     $criteria = new Criteria();
     /** @var RepositoryInterface $streamRepo */
     $streamRepo = $this->get('shopware_product_stream.repository');
     $sorting = $streamRepo->unserialize($sorting);
     foreach ($sorting as $sort) {
         $criteria->addSorting($sort);
     }
     $conditions = $streamRepo->unserialize($conditions);
     foreach ($conditions as $condition) {
         $criteria->addCondition($condition);
     }
     $criteria->offset($this->Request()->getParam('start', 0));
     $criteria->limit($this->Request()->getParam('limit', 20));
     $context = $this->createContext($this->Request()->getParam('shopId'), $this->Request()->getParam('currencyId'), $this->Request()->getParam('customerGroupKey'));
     $criteria->addBaseCondition(new CustomerGroupCondition([$context->getCurrentCustomerGroup()->getId()]));
     $category = $context->getShop()->getCategory()->getId();
     $criteria->addBaseCondition(new CategoryCondition([$category]));
     $result = Shopware()->Container()->get('shopware_search.product_search')->search($criteria, $context);
     $products = array_values($result->getProducts());
     $this->View()->assign(['success' => true, 'data' => $products, 'total' => $result->getTotalCount()]);
 }
 /**
  * @param Request $request
  * @param Criteria $criteria
  */
 private function addOffset(Request $request, Criteria $criteria)
 {
     $page = $request->getParam('sPage', 1);
     $criteria->offset(($page - 1) * $criteria->getLimit());
 }