select 
<@LANGUAGE_ID@> language_id,
p.id products_id, 
 convert(groups.meta_value, UNSIGNED INTEGER) categories_id,
'' categories_image,
tx.parent parent_id,
0 sort_order,
t.name categories_name 
FROM  <@PREFIX>posts p
left join <@PREFIX>postmeta groups on groups.post_id = p.id
and groups.meta_key = '_primary_term_product_cat'
 
join <@PREFIX>terms t on t.term_id = convert(groups.meta_value, UNSIGNED INTEGER)
join <@PREFIX>term_taxonomy tx on tx.term_id = t.term_id and tx.taxonomy ='product_cat'  
