Esempio n. 1
0
 /**
  * Get applied to layer filter items
  *
  * @return Item[]
  */
 public function getFilters()
 {
     try {
         if ($this->bxHelperData->isFilterLayoutEnabled($this->_layer)) {
             $category = $this->_categoryViewBlock->getCurrentCategory();
             if ($category != null && $category->getDisplayMode() == \Magento\Catalog\Model\Category::DM_PAGE) {
                 return parent::getFilters();
             }
             $filters = array();
             $facets = $this->p13nHelper->getFacets();
             if ($facets) {
                 foreach ($this->bxHelperData->getAllFacetFieldNames() as $fieldName) {
                     if ($facets->isSelected($fieldName)) {
                         $filter = $this->objectManager->create("Boxalino\\Intelligence\\Model\\LayerFilterItem");
                         $filter->setFacets($facets);
                         $filter->setFieldName($fieldName);
                         $filters[] = $filter;
                     }
                 }
             }
             return $filters;
         }
         return parent::getFilters();
     } catch (\Exception $e) {
         $this->bxHelperData->setFallback(true);
         $this->_logger->critical($e);
         return parent::getFilters();
     }
 }
Esempio n. 2
0
 private function getBxFacets()
 {
     if ($this->bxFacets == null) {
         $this->bxFacets = $this->p13nHelper->getFacets();
     }
     return $this->bxFacets;
 }
Esempio n. 3
0
 /**
  * @return $this
  */
 protected function _prepareData($execute = true)
 {
     if ($this->bxHelperData->isRelatedEnabled()) {
         $products = $this->_coreRegistry->registry('product');
         $config = $this->_scopeConfig->getValue('bxRecommendations/related', $this->scopeStore);
         $choiceId = isset($config['widget']) && $config['widget'] != "" ? $config['widget'] : 'similar';
         try {
             $entity_ids = $this->p13nHelper->getRecommendation($choiceId, $products, 'product', $config['min'], $config['max'], $execute);
         } catch (\Exception $e) {
             $this->bxHelperData->setFallback(true);
             $this->_logger->critical($e);
             return parent::_prepareData();
         }
         if (!$execute) {
             return null;
         }
         if (count($entity_ids) == 0) {
             $entity_ids = array(0);
         }
         $this->_itemCollection = $this->factory->create()->addFieldToFilter('entity_id', $entity_ids)->addAttributeToSelect('*');
         if ($this->moduleManager->isEnabled('Magento_Checkout')) {
             $this->_addProductAttributesAndPrices($this->_itemCollection);
         }
         $this->_itemCollection->setVisibility($this->_catalogProductVisibility->getVisibleInCatalogIds());
         $this->_itemCollection->load();
         foreach ($this->_itemCollection as $product) {
             $product->setDoNotUseCategoryId(true);
         }
         return $this;
     }
     return parent::_prepareData();
 }
Esempio n. 4
0
 /**
  * @param bool $execute
  * @return $this|array|null
  */
 public function getItems($execute = true)
 {
     if ($this->bxHelperData->isCrosssellEnabled()) {
         $config = $this->_scopeConfig->getValue('bxRecommendations/cart', $this->scopeStore);
         $products = array();
         foreach ($this->getQuote()->getAllItems() as $item) {
             $product = $item->getProduct();
             if ($product) {
                 $products[] = $product;
             }
         }
         $choiceId = isset($config['widget']) && $config['widget'] != "" ? $config['widget'] : 'basket';
         try {
             $entity_ids = $this->p13nHelper->getRecommendation($choiceId, $products, 'basket', $config['min'], $config['max'], $execute);
         } catch (\Exception $e) {
             $this->bxHelperData->setFallback(true);
             $this->_logger->critical($e);
             return parent::getItems();
         }
         if (!$execute) {
             return null;
         }
         if (count($entity_ids) == 0) {
             $entity_ids = array(0);
         }
         $items = $this->factory->create()->addFieldToFilter('entity_id', $entity_ids)->addAttributeToSelect('*');
         $items->load();
         foreach ($items as $product) {
             $product->setDoNotUseCategoryId(true);
         }
         return $items;
     }
     return parent::getItems();
 }
Esempio n. 5
0
 /**
  * @return $this|MageCrosssell
  */
 protected function _prepareData($execute = true)
 {
     if ($this->bxHelperData->isCrosssellEnabled()) {
         $products = $this->_coreRegistry->registry('product');
         $config = $this->_scopeConfig->getValue('bxRecommendations/cart', $this->scopeStore);
         $choiceId = isset($config['widget']) && $config['widget'] != "" ? $config['widget'] : 'complementary';
         try {
             $entity_ids = $this->p13nHelper->getRecommendation($choiceId, $products, 'basket', $config['min'], $config['max'], $execute);
         } catch (\Exception $e) {
             $this->bxHelperData->setFallback(true);
             $this->_logger->critical($e);
             return parent::_prepareData();
         }
         if (!$execute) {
             return null;
         }
         if (count($entity_ids) == 0) {
             $entity_ids = array(0);
         }
         $this->_itemCollection = $this->factory->create()->addFieldToFilter('entity_id', $entity_ids)->addAttributeToSelect('*');
         $this->_itemCollection->load();
         foreach ($this->_itemCollection as $product) {
             $product->setDoNotUseCategoryId(true);
         }
         return $this;
     }
     return parent::_prepareData();
 }
Esempio n. 6
0
 /**
  * @return int|mixed
  */
 public function hasSubPhrases()
 {
     if ($this->bxHelperData->isSearchEnabled()) {
         if ($this->subPhrases == null) {
             $this->subPhrases = $this->p13Helper->areThereSubPhrases();
         }
         return $this->subPhrases;
     }
     return false;
 }
Esempio n. 7
0
 /**
  * @return array|null
  */
 public function getSliderValues()
 {
     $facets = $this->p13nHelper->getFacets();
     if (empty($facets) || empty($facets->getFacetValues($facets->getPriceFieldName()))) {
         return null;
     }
     $priceRange = $this->explodePrice($facets->getPriceRanges()[0]);
     $selectedPrice = $this->getRequest()->getParam('bx_discountedPrice') !== null ? $this->explodePrice($this->getRequest()->getParam('bx_discountedPrice')) : $priceRange;
     if ($priceRange[0] == $priceRange[1]) {
         $priceRange[1]++;
     }
     return array_merge($selectedPrice, $priceRange);
 }
Esempio n. 8
0
 /**
  * @return \Magento\Framework\Controller\Result\Json|\Magento\Framework\Controller\Result\Redirect|null
  */
 public function aroundExecute()
 {
     $query = $this->request->getParam('q', false);
     if (!$query) {
         /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
         $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
         $resultRedirect->setUrl($this->url->getBaseUrl());
         return $resultRedirect;
     }
     if ($this->bxHelperData->isAutocompleteEnabled()) {
         $responseData = $this->p13nHelper->autocomplete($query, $this->autocompleteHelper);
         /** @var \Magento\Framework\Controller\Result\Json $resultJson */
         $resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON);
         $resultJson->setData($responseData);
         return $resultJson;
     }
     return null;
 }
Esempio n. 9
0
 /**
  * Display search result
  *
  * @return void
  */
 public function execute()
 {
     if ($this->bxHelperData->isSearchEnabled()) {
         $this->layerResolver->create(Resolver::CATALOG_LAYER_SEARCH);
         /* @var $query \Magento\Search\Model\Query */
         $query = $this->_queryFactory->get();
         try {
             if ($this->p13Helper->areThereSubPhrases()) {
                 $queries = $this->p13Helper->getSubPhrasesQueries();
                 if (count($queries) == 1) {
                     $this->_redirect('*/*/*', array('_current' => true, '_query' => array('q' => $queries[0])));
                 }
             }
             if ($this->p13Helper->areResultsCorrected()) {
                 $correctedQuery = $this->p13Helper->getCorrectedQuery();
                 $query->setQueryText($correctedQuery);
             }
         } catch (\Exception $e) {
             $this->bxHelperData->setFallback(true);
             $this->_logger->critical($e);
         }
         $query->setStoreId($this->_storeManager->getStore()->getId());
         if ($query->getQueryText() != '') {
             if ($this->_objectManager->get('Magento\\CatalogSearch\\Helper\\Data')->isMinQueryLength()) {
                 $query->setId(0)->setIsActive(1)->setIsProcessed(1);
             } else {
                 $query->saveIncrementalPopularity();
                 if ($query->getRedirect()) {
                     $this->getResponse()->setRedirect($query->getRedirect());
                     return;
                 }
             }
             $this->_objectManager->get('Magento\\CatalogSearch\\Helper\\Data')->checkNotes();
             $this->_view->loadLayout();
             $this->_view->renderLayout();
         } else {
             $this->getResponse()->setRedirect($this->_redirect->getRedirectUrl());
         }
     } else {
         parent::execute();
     }
 }
Esempio n. 10
0
 /**
  * @return array
  */
 public function getTopFilters()
 {
     try {
         if ($this->bxHelperData->isFilterLayoutEnabled($this->layer) && $this->isTopFilterEnabled()) {
             $facets = $this->p13nHelper->getFacets();
             if ($facets) {
                 $fieldName = $this->bxHelperData->getTopFacetFieldName();
                 $attribute = $this->objectManager->create("Magento\\Catalog\\Model\\ResourceModel\\Eav\\Attribute");
                 $filter = $this->objectManager->create("Boxalino\\Intelligence\\Model\\Attribute", ['data' => ['attribute_model' => $attribute], 'layer' => $this->layer]);
                 $filter->setFacets($facets);
                 $filter->setFieldName($fieldName);
                 return $filter->getItems();
             }
         }
     } catch (\Exception $e) {
         $this->bxHelperData->setFallback(true);
         $this->_logger->critical($e);
     }
     return array();
 }
Esempio n. 11
0
 /**
  * Retrieve search result count
  *
  * @return string
  */
 public function getResultCount()
 {
     if ($this->fallback) {
         return parent::getResultCount();
     }
     if (!$this->getData('result_count')) {
         $query = $this->_getQuery();
         $size = $this->hasSubPhrases() ? $this->p13nHelper->getSubPhraseTotalHitCount($this->queries[\Boxalino\Intelligence\Block\Product\BxListProducts::$number]) : $this->p13nHelper->getTotalHitCount();
         $this->setResultCount($size);
         $query->saveNumResults($size);
     }
     return $this->getData('result_count');
 }
Esempio n. 12
0
 /**
  * @param $entity_ids
  */
 protected function _setupCollection($entity_ids)
 {
     $list = $this->_objectManager->create('\\Boxalino\\Intelligence\\Model\\Collection');
     $list->setStoreId($this->_storeManager->getStore()->getId())->addFieldToFilter('entity_id', $entity_ids)->addAttributeToSelect('*');
     $list->getSelect()->order(new \Zend_Db_Expr('FIELD(e.entity_id,' . implode(',', $entity_ids) . ')'));
     $list->load();
     $list->setCurBxPage($this->getToolbarBlock()->getCurrentPage());
     $limit = $this->getRequest()->getParam('product_list_limit') ? $this->getRequest()->getParam('product_list_limit') : $this->getToolbarBlock()->getDefaultPerPageValue();
     $totalHitCount = $this->p13nHelper->getTotalHitCount();
     if (ceil($totalHitCount / $limit) < $list->getCurPage() && $this->getRequest()->getParam('p')) {
         $url = $this->_url->getCurrentUrl();
         $url = preg_replace('/(\\&|\\?)p=+(\\d|\\z)/', '$1p=1', $url);
         $this->_response->setRedirect($url);
     }
     $lastPage = ceil($totalHitCount / $limit);
     $list->setLastBxPage($lastPage);
     $list->setBxTotal($totalHitCount);
     $this->_productCollection = $list;
 }
 /**
  * @return $this
  */
 protected function _prepareData()
 {
     $context = isset($this->_data['context']) ? $this->_data['context'] : array();
     $entity_ids = array();
     try {
         $entity_ids = $this->p13nHelper->getRecommendation($this->_data['widget'], $context);
     } catch (\Exception $e) {
         $this->bxHelperData->setFallback(true);
         $this->_logger->critical($e);
         return $this;
     }
     if (count($entity_ids) == 0) {
         $entity_ids = array(0);
     }
     $this->_itemCollection = $this->factory->create()->addFieldToFilter('entity_id', $entity_ids)->addAttributeToSelect('*');
     $this->_itemCollection->load();
     foreach ($this->_itemCollection as $product) {
         $product->setDoNotUseCategoryId(true);
     }
     return $this;
 }