You can get the category product table name dynamically using Magento 2 Catalog module.
catalog_category_product table used for category-product relation.
The table contains entity_id, category_id, product_id and position field to manage relationships with products.
A class responsible to get the category table name is Magento\Catalog\Model\ResourceModel\Category.
<?php namespace Rbj\Catalog\Model; use Magento\Catalog\Model\ResourceModel\Category; class CategoryProductTable { /** * @var Category */ private $category;; public function __construct( Category $category ) { $this->category = $category; } /** * category product table full name with prefix * * @return string */ public function getCategoryProductTable() { $categoryProduct = $this->category->getCategoryProductTable(); return $categoryProduct; } }
call from template or other class,
echo $categoryProductTable = $this->getCategoryProductTable();
Output:
catalog_category_product (if prefix available, output is with prefix tablename)