Example #1
0
 /**
  * Get attributes for the recommender system
  * @return array
  */
 protected function getAttributes()
 {
     if ($this->_attributes === null) {
         $this->_attributes = array_fill_keys($this->_config->getProductAttributes(), true);
     }
     return $this->_attributes;
 }
Example #2
0
 /**
  * Get products by IDs
  * @param array    $productIds
  * @param null|int $chunkSize
  * @param bool     $filterVisibility
  * @return \Magento\Catalog\Model\Resource\Product\Collection
  */
 public function getProducts(array $productIds = [], $chunkSize = null, $filterVisibility = true)
 {
     $this->_productCollection->addAttributeToSelect('sku')->addAttributeToSelect($this->_config->getProductAttributes())->addAttributeToSelect('status')->addAttributeToSelect('visibility');
     if ($filterVisibility) {
         $this->_productCollection->addAttributeToFilter('visibility', ['in' => [Visibility::VISIBILITY_IN_CATALOG, Visibility::VISIBILITY_BOTH]])->addAttributeToFilter('status', Status::STATUS_ENABLED);
     }
     if (!empty($productIds)) {
         $this->_productCollection->addIdFilter($productIds);
     }
     if ($chunkSize !== null) {
         $this->_productCollection->setPageSize($chunkSize);
     }
     return $this->_productCollection;
 }