/** * Check on customer login if they have any product view to capture * * @param Observer $observer */ public function execute(Observer $observer) { if ($this->_config->isEnabled()) { $this->_eventClient->saveCustomerData($this->_customerSession->getCustomerId()); $guestProductViews = $this->_getGuestCustomerProductViews(); if ($guestProductViews) { $this->_sendAllGuestProductViews($guestProductViews); } } }
/** * @param $productId * @return bool|void */ public function processViews($productId) { if (!$this->_config->isEnabled()) { return false; } if ($this->_customerSession->isLoggedIn()) { return $this->_eventClient->saveCustomerViewProduct($this->_customerSession->getCustomerId(), $productId); } return false; }
/** * Check the customer has an account and send the order product colllection * to PredictionIO * * @param Observer $observer */ public function execute(Observer $observer) { if (!$this->_config->isEnabled()) { return; } $order = $observer->getEvent()->getOrder(); $productCollection = $order->getItems(); if ($this->_customerSession->isLoggedIn()) { $this->_sendPurchaseEvent($productCollection); return; } }
/** * Get the crossell items for the basket page * Rewrites the target rules for Enterprise edition * * @return array */ public function getItemCollection() { if (!$this->_config->isEnabled() || !$this->_config->getItem(Config::COMPLEMENTARY_REPLACE_RULES)) { return parent::getItemCollection(); } $personalisedIds = $this->_crosssell->getProductCollection(); if (!$personalisedIds) { return parent::getItemCollection(); } $collection = $this->_crosssell->getPersonalisedProductCollection($personalisedIds); if ($this->_moduleManager->isEnabled('Magento_Checkout')) { $this->_addProductAttributesAndPrices($collection); } $this->_items = []; foreach ($collection as $item) { $this->_items[] = $item; } return $this->_items; }
/** * 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; }