Get product category on export
-
How can I get product category in this query builder?
$queryBuilder = DB::table('product_flat') ->leftJoin('products', 'product_flat.product_id', '=', 'products.id') ->leftJoin('attribute_families', 'products.attribute_family_id', '=', 'attribute_families.id') ->leftJoin('product_inventories', 'product_flat.product_id', '=', 'product_inventories.product_id') ->select( 'product_flat.locale', 'product_flat.channel', 'product_flat.product_id', 'products.sku as product_sku', 'product_flat.name as product_name', 'products.type as product_type', 'product_flat.status', 'product_flat.price', 'attribute_families.name as attribute_family', DB::raw('SUM(DISTINCT ' . DB::getTablePrefix() . 'product_inventories.qty) as quantity') );
-
Hi @LilD,
Use this,
->leftJoin('product_categories', 'product_flat.product_id', '=', 'product_categories.product_id') ->leftJoin('category_translations', 'product_categories.category_id', '=', 'category_translations.category_id') ->select( ... 'category_translations.name as category_name', ... );
Rest you need to add some Datagrid stuffs, like adding columns, etc.