/** * Rewrite parent getAllItems method to use PredictionIO results when available * Rewrites the target rules for Enterprise edition * * @return array */ public function getAllItems() { if (!$this->_config->isEnabled() || !$this->_config->getItem(Config::SIMILARITY_REPLACE_RULES)) { return parent::getAllItems(); } $product = $this->_coreRegistry->registry('product'); $categoryIds = $this->_upsell->getCategoryIds($product); $personalisedIds = $this->_upsell->getProductCollection([$product->getId()], $categoryIds); if (!$personalisedIds) { return parent::getAllItems(); } $collection = $this->_upsell->getPersonalisedProductCollection($personalisedIds); if ($this->_moduleManager->isEnabled('Magento_Checkout')) { $this->_addProductAttributesAndPrices($collection); } $items = []; foreach ($collection as $product) { $product->setDoNotUseCategoryId(true); $items[] = $product; } return $items; }
/** * Rewrite parent _prepareData method to use PredictionIO results when available * * @return $this */ protected function _prepareData() { if (!$this->_config->isEnabled()) { return parent::_prepareData(); } $product = $this->_coreRegistry->registry('product'); $categoryIds = $this->_upsell->getCategoryIds($product); $personalisedIds = $this->_upsell->getProductCollection([$product->getId()], $categoryIds); if (!$personalisedIds) { return parent::_prepareData(); } $this->_isPredictedResults = true; $collection = $this->_upsell->getPersonalisedProductCollection($personalisedIds); $this->_itemCollection = $collection; if ($this->moduleManager->isEnabled('Magento_Checkout')) { $this->_addProductAttributesAndPrices($this->_itemCollection); } $this->_eventManager->dispatch('catalog_product_upsell', ['product' => $product, 'collection' => $this->_itemCollection, 'limit' => null]); foreach ($this->_itemCollection as $product) { $product->setDoNotUseCategoryId(true); } return $this; }