/** * @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 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|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 $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; }
/** * Retrieve linked product collection * * @return ProductCollection */ public function getProductCollection() { $collection = $this->_productCollectionFactory->create()->setLinkModel($this); return $collection; }
/** * Retrieve linked product collection * * @return ProductCollection */ public function getProductCollection() { $collection = $this->_productCollectionFactory->create()->setLinkModel($this); $this->stockHelper->addInStockFilterToCollection($collection); return $collection; }