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.

        ['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"

1 Answer 1


Maybe this helps? It is checking if entity_id column present in table.

use Magento\Framework\App\ResourceConnection;
$connection = $this->resourceConnection->getConnection();

$entityIdColumnExists = $connection->tableColumnExists('catalog_product_entity_varchar', 'entity_id');

Or, you could add a config in the admin panel, where the admin would chose what version is their store, CE or EE, and you can do your logic based on that value?

Otherwise, you can always just send a GET request to http://your-store/magento_version and get the response

  1. Magento/2.4 (Community)
  2. Magento/2.4 (B2B)


  • 1
    thanks that works, I used this as my code: $entityIdColumnExists = $connection->tableColumnExists('catalog_product_entity_varchar', 'entity_id'); if($entityIdColumnExists === true){ $colName = 'entity_id'; } else { $colName = 'row_id'; } Jan 26, 2022 at 9:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.