/** * @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(); }
/** * @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(); }
/** * @param \Magento\Catalog\Model\Layer $layer * @return array|\Magento\Catalog\Model\Layer\Filter\AbstractFilter[] */ public function getFilters(\Magento\Catalog\Model\Layer $layer) { try { if ($this->bxHelperData->isFilterLayoutEnabled($layer) && $this->bxHelperData->isLeftFilterEnabled()) { $filters = array(); $facets = $this->getBxFacets(); if ($facets) { foreach ($this->bxHelperData->getLeftFacetFieldNames() as $fieldName) { $attribute = $this->objectManager->create("Magento\\Catalog\\Model\\ResourceModel\\Eav\\Attribute"); $filter = $this->objectManager->create("Boxalino\\Intelligence\\Model\\Attribute", ['data' => ['attribute_model' => $attribute], 'layer' => $layer]); $filter->setFacets($facets); $filter->setFieldName($fieldName); $filters[] = $filter; } } return $filters; } else { return parent::getFilters($layer); } } catch (\Exception $e) { $this->bxHelperData->setFallback(true); $this->_logger->critical($e); return parent::getFilters($layer); } }
/** * @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(); }
/** * @return AbstractCollection|mixed */ public function _getProductCollection() { try { $layer = $this->getLayer(); if ($this->bxHelperData->isFilterLayoutEnabled($layer)) { if (count($this->_productCollection) && !$this->p13nHelper->areThereSubPhrases()) { return $this->_productCollection; } if ($layer instanceof \Magento\Catalog\Model\Layer\Category) { if ($this->categoryViewBlock->isContentMode()) { return parent::_getProductCollection(); } } if ($this->p13nHelper->areThereSubPhrases()) { $this->queries = $this->p13nHelper->getSubPhrasesQueries(); $entity_ids = $this->p13nHelper->getSubPhraseEntitiesIds($this->queries[self::$number]); $entity_ids = array_slice($entity_ids, 0, $this->bxHelperData->getSubPhrasesLimit()); } else { $entity_ids = $this->p13nHelper->getEntitiesIds(); } if (count($entity_ids) == 0) { $entity_ids = array(0); } $this->_setupCollection($entity_ids); return $this->_productCollection; } else { return parent::_getProductCollection(); } } catch (\Exception $e) { $this->bxHelperData->setFallback(true); $this->_logger->critical($e); return parent::_getProductCollection(); } }
/** * 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(); } }
/** * 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(); } }
/** * @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(); }
/** * @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; }
/** * @return $this|\Magento\Catalog\Model\Layer\Filter\AbstractFilter */ public function _initItems() { try { if ($this->bxDataHelper->isFilterLayoutEnabled($this->_layer)) { $this->is_bx_attribute = $this->bxDataHelper->isBxAttribute($this->fieldName); $data = $this->_getItemsData(); $items = []; foreach ($data as $itemData) { $selected = isset($itemData['selected']) ? $itemData['selected'] : null; $type = isset($itemData['type']) ? $itemData['type'] : null; $items[] = $this->_createItem($itemData['label'], $itemData['value'], $itemData['count'], $selected, $type); } $this->_items = $items; return $this; } return parent::_initItems(); } catch (\Exception $e) { $this->bxDataHelper->setFallback(true); $this->_logger->critical($e); return parent::_initItems(); } }