** Edit ** Just a note, I can get this working by manually instantiating the object manager and getting the ids I need, but I'd prefer if I can do it the way that I am supposed to be doing it by using the DI in the constructor. Here is the "hack" method:
/**
* Join Products table to get product names
*
* @return $this
*/
public function joinProductNames()
{
$attr = $this->getAttributeIdofProductName();
$storeid = $this->getStoreId();
$this->getSelect()
->joinLeft(
['catalog_product_entity_varchar' => $this->getTable('catalog_product_entity_varchar')],
"main_table.product_id = catalog_product_entity_varchar.entity_id",
["product_name" => "value"])
->where(
"catalog_product_entity_varchar.store_id = " . $storeid)
->where(
"catalog_product_entity_varchar.attribute_id = " . $attr
);
return $this;
}
/**
* Get EAV id of the product name attribute
*
* @return mixed
*/
private function getAttributeIdofProductName(){
$om = \Magento\Framework\App\ObjectManager::getInstance();
/** @var \Magento\Store\Model\StoreManagerInterface $manager */
$attr = $om->get('\Magento\Eav\Api\AttributeRepositoryInterface');
$productNameAttributeId = $attr->get('catalog_product', 'name')->getId();
return $productNameAttributeId;
}
/**
* Get store id of current store id of admin
*
* @return int
*/
private function getStoreId()
{
$om = \Magento\Framework\App\ObjectManager::getInstance();
/** @var \Magento\Store\Model\StoreManagerInterface $manager */
$manager = $om->get('Magento\Store\Model\StoreManagerInterface');
$storeid = $manager->getStore()->getId();
if($storeid == 1){
return 0;
} else {
return $storeid;
}
}