cancel
Showing results for 
Search instead for 
Did you mean: 

Magento 2 Join with ProductRepositoryInterface result

Magento 2 Join with ProductRepositoryInterface result

I want to add join query with productRepository. Here is my class. Can anyone help with this.

I have used \Magento\Catalog\Api\ProductRepositoryInterface::getList() method to get product list and now i want to add join with other table.

I am getting products data.

<?php

namespace Example\Product\Model;

use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Framework\Api\SortOrder;
use Magento\Framework\Api\SortOrderBuilder;

/**
* Class Productlist
*
* @package Example\Product\Model
*/
class Productlist implements \Example\Product\Api\ProductlistInterface
{


/**
* Product repository
* @var ProductRepositoryInterface
*/
private $productRepository;

/**
* SearchCriteria builder
* @var SearchCriteriaBuilder
*/
private $searchCriteriaBuilder;

/**
* SortOrder builder
* @var SortOrderBuilder
*/
private $sortOrderBuilder;

/**
* ListProduct constructor
*
* @param ProductRepositoryInterface $productRepository
* @param SearchCriteriaBuilder $searchCriteriaBuilder
* @param SortOrderBuilder $sortOrderBuilder
*/
public function __construct(
ProductRepositoryInterface $productRepository,
SearchCriteriaBuilder $searchCriteriaBuilder,
SortOrderBuilder $sortOrderBuilder
) {
$this->productRepository = $productRepository;
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
$this->sortOrderBuilder = $sortOrderBuilder;
}

/**
* Get list of products
*
* @return ProductInterface[]
*/
public function getProductList($params)
{
// Create the SearchCriteria
$searchCriteria = $this->searchCriteriaBuilder->create();

// Load the products
$products = $this->productRepository
->getList($searchCriteria)->setSearchCriteria();

foreach ($products->getItems() as $product){
echo $product->getName();
}
exit;
}

}