Posted on

Code to Get row_id or entity_id for catalog_product_entity_varchar table for join query of product name Community vs Commerce editions

I’m using some code to join the catalog_product_entity_varchar in order to get the product name and it works for Community edition using entity_id but my client is hosting with Magento Cloud and there it uses row_id similar to how the Enterprise / Commerce edition does. I tried code like this:

$edition = $this->productMetadata->getEdition();
if($edition == ‘Community’){
$colName = ‘entity_id’;
} else {
$colName = ‘row_id’;
}

but it doesn’t work since they are on Community edition. What is the proper way to dynamically find out what column name Magento 2 is using here? The join query is like this but it fails on theirs since they are using row_id for the $colName.

$this->getSelect()->joinInner(
[‘at_name_default’ => $this->getTable(‘catalog_product_entity_varchar’)],
“at_name_default.” . $colName . ” = main_table.product_id ”
. “AND at_name_default.attribute_id = {$nameAttr->getAttributeId()} ”
. “AND at_name_default.store_id = 0”
);

Leave a Reply

Your email address will not be published.