My scenario
each product related to one merchant (simplest)
product have attribute merchant_id (int). This attribute not describe product, only field link to merchant
table. merchan_id field associated with Merchant model
I have table merchant
contain fields : entity_id (int -> value in product), merchant_id (unique string)
After magento 2.3.2 core team have updated
my field cannot filter anymore. So how is the correct way to add merchant_identifier
field to product listing data ?
My Approach
1 Create field to catalog product listing
-
- text
- true
- asc
- text
- Merchant Identifier
- 10
2 Preference catalog
etc/adminhtml/di.xml
3 Add my Provider extend Magento Provider
class ProductDataProvider extends MagentoCatalogUiDataProviderProductProductDataProvider
in construct add join only
public function __construct(
//Dependencies
) {
/*Join with merchant table.*/
$this->collection->joinTable(
['merchant_tbl' => $this->collection->getTable('merchant')],
"entity_id=merchant_id",
['merchant_identifier'=>'merchant_id'],
null,
'left'
);
}
Here is how field show in catalog product listing
+-----------+------------+---------------------+
| entity_id | product_id | merchant_identifier |
+-----------+------------+---------------------+
| 1 | 123453 | merchant_ide123A_Af |
| 2 | 654657 | merchant_ide213A_Af |
| 3 | 345477 | merchant_ide312A_Af |
| 4 | 114673 | merchant_ide231A_Af |
+-----------+------------+---------------------+