_getCountUsageSubselect()) . ')'; $columns['relatedCategories'] = '(' . new Zend_Db_Expr($this->_getCategoriesSubselect()) . ')'; return $columns; } protected function _getCountUsageSubselect() { $select = $this->_db->select(); $select->from($this->_getPair('CartItemPromo'), 'COUNT(*)'); $select->join( $this->_getPair('Cart'), '`Cart`.`id` = `CartItemPromo`.`cartId`', array() ); $select->where('`CartItemPromo`.`promoId` = `' . $this->_tableAlias . '`.`id`'); $select->where('`Cart`.`transactionId` IS NOT NULL'); return $select; } protected function _getCategoriesSubselect() { $select = $this->_db->select(); $select->from($this->_getPair($this->_tableAlias . '2ProductCategory', 'p2pc'), []); $select->joinLeft( $this->_getPair('ProductCategory', 'pc'), '`pc`.`id` = `p2pc`.`categoryId`', [ 'categories' => 'GROUP_CONCAT(`pc`.`title` SEPARATOR "' . self::CATEGORY_SEPARATOR . '")' ] ); $select->where('`p2pc`.`promoId` = `' . $this->_tableAlias . '`.`id`'); return $select; } }