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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | <?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)