/** * @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(); }