Exemple #1
0
 /**
  * Return the filter applied to the query.
  *
  * @SuppressWarnings(PHPMD.ElseExpression)
  *
  * @return QueryInterface
  */
 private function getQueryFilter()
 {
     $queryParams = [];
     $this->category->setIsActive(true);
     if ($this->category->getIsVirtualCategory() || $this->category->getId()) {
         $queryParams['must'][] = $this->category->getVirtualRule()->getCategorySearchQuery($this->category);
     } elseif (!$this->category->getId()) {
         $queryParams['must'][] = $this->getEntityIdFilterQuery([0]);
     }
     if ((bool) $this->category->getIsVirtualCategory() === false) {
         $addedProductIds = $this->category->getAddedProductIds();
         $deletedProductIds = $this->category->getDeletedProductIds();
         if ($addedProductIds && !empty($addedProductIds)) {
             $queryParams = ['should' => $queryParams['must']];
             $queryParams['should'][] = $this->getEntityIdFilterQuery($addedProductIds);
         }
         if ($deletedProductIds && !empty($deletedProductIds)) {
             $queryParams['mustNot'][] = $this->getEntityIdFilterQuery($deletedProductIds);
         }
     }
     return $this->queryFactory->create(QueryInterface::TYPE_BOOL, $queryParams);
 }
Exemple #2
0
 /**
  * Transform the virtual category into a QueryInterface used for filtering.
  *
  * @param CategoryInterface $category           Virtual category.
  * @param array             $excludedCategories Category already used into the building stack. Avoid short circuit.
  *
  * @return QueryInterface
  */
 private function getVirtualCategoryQuery(CategoryInterface $category, $excludedCategories = [])
 {
     return $category->getVirtualRule()->getConditions()->getSearchQuery($excludedCategories);
 }
Exemple #3
0
 /**
  * Append virtual rule params to the category.
  *
  * @param CategoryInterface $category Category.
  *
  * @return $this
  */
 private function addVirtualCategoryData(CategoryInterface $category)
 {
     $isVirtualCategory = (bool) $this->getRequest()->getParam('is_virtual_category');
     $category->setIsVirtualCategory($isVirtualCategory);
     if ($isVirtualCategory) {
         $category->getVirtualRule()->loadPost($this->getRequest()->getParam('virtual_rule', []));
         $category->setVirtualCategoryRoot($this->getRequest()->getParam('virtual_category_root', null));
     }
     return $this;
 }