Skip to content

Commit

Permalink
Added category column to product datagrid
Browse files Browse the repository at this point in the history
  • Loading branch information
adampiotrowski committed Mar 25, 2014
1 parent c18d1d0 commit 98c835d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 3 additions & 1 deletion application/Gekosale/Core/Datagrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,10 @@ public function loadData($request)
$this->query->take((int)$request['limit']);
$this->query->orderBy($request['order_by'], $request['order_dir']);

$connection = $this->getDb()->getConnection();
foreach ($this->columns as $key => $column) {
$this->query->addSelect(sprintf('%s AS %s', $column['source'], $key));
$col = $connection->raw(sprintf('%s AS %s', $column['source'], $key));
$this->query->addSelect($col);
}
foreach ($request['where'] as $where) {
$column = $this->columns[$where['column']]['source'];
Expand Down
16 changes: 15 additions & 1 deletion application/Gekosale/Plugin/Product/DataGrid/ProductDataGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,10 @@ public function init()
'visible' => false
],
'process_function' => function ($id) {
if((int)$id == 0){
if ((int)$id == 0) {
return '';
}

return $this->getImageGallery()->getImageUrl($id, 100, 100);
}
]);
Expand All @@ -107,6 +108,17 @@ public function init()
]
]);

$this->addColumn('category', [
'source' => 'GROUP_CONCAT(DISTINCT SUBSTRING(CONCAT(\' \', category_translation.name), 1))',
'caption' => $this->trans('Category'),
'appearance' => [
'width' => 120,
],
'filter' => [
'type' => DataGridInterface::FILTER_INPUT
]
]);

$this->addColumn('ean', [
'source' => 'product.ean',
'caption' => $this->trans('EAN'),
Expand Down Expand Up @@ -182,6 +194,8 @@ public function init()
$this->query = $this->getDb()
->table('product')
->join('product_translation', 'product_translation.product_id', '=', 'product.id')
->leftJoin('product_category', 'product_category.product_id', '=', 'product.id')
->leftJoin('category_translation', 'category_translation.category_id', '=', 'product_category.category_id')
->groupBy('product.id');

$event = new ProductDataGridEvent($this);
Expand Down

0 comments on commit 98c835d

Please sign in to comment.