예제 #1
0
 /**
  * @param \Magento\Catalog\Model\Product $product
  * @return array
  */
 public function getCategoryIds(\Magento\Catalog\Model\Product $product)
 {
     if (!$this->_config->getItem(Config::SIMILARITY_USE_CATEGORY_FILTER)) {
         return [];
     }
     return $product->getCategoryIds();
 }
 /**
  * Complementary constructor.
  * @param Factory $factory
  * @param PersonalisedProductsLogger $logger
  * @param Config $config
  * @param Urls $urls
  */
 public function __construct(Factory $factory, PersonalisedProductsLogger $logger, Config $config, Urls $urls)
 {
     $this->_factory = $factory;
     $this->_logger = $logger;
     $this->_config = $config;
     $this->_urls = $urls;
     $this->_engineClient = $this->_factory->create('engine', $this->_urls->buildUrl($this->_config->getItem(Config::COMPLEMENTARY_ENGINE_URL), $this->_config->getItem(Config::COMPLEMENTARY_ENGINE_PORT)));
 }
 /**
  * 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;
 }