/** * Callback function that filters collection by field "Used" from grid * * @param AbstractCollection $collection * @param Column $column * @return void */ public function addIsUsedFilterCallback($collection, $column) { $filterValue = $column->getFilter()->getCondition(); $expression = $this->getConnection()->getCheckSql('main_table.times_used > 0', 1, 0); $conditionSql = $this->_getConditionSql($expression, $filterValue); $collection->getSelect()->where($conditionSql); }
/** * @param \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection $collection */ protected function _prepareCache($collection) { $stmt = $collection->getSelect()->query(); $ids = array(); foreach ($stmt as $item) { $ids = array_merge($ids, array_map('intval', explode('/', $item['path']))); } $ids = array_unique($ids); if (empty($ids)) { return; } /* @var $attribute \Magento\Eav\Model\Attribute */ $attribute = $collection->getFirstItem()->getResource()->getAttribute('name'); $resource = $collection->getResource(); $tableName = \Magento\Catalog\Model\Category::ENTITY . '_entity_' . $attribute->getBackendType(); $dbSelect1 = $resource->getConnection()->select()->from($resource->getTable($tableName), new \Zend_Db_Expr('MAX(`store_id`)'))->where("`entity_id` = `ccev`.`entity_id`")->where("`attribute_id` = `ccev`.`attribute_id`")->where("`store_id` = 0 OR `store_id` = ?", $this->getStoreId()); $dbSelect2 = $resource->getConnection()->select()->from(array('ccev' => $resource->getTable($tableName)), array('name' => 'value', 'category_id' => 'entity_id'))->where('ccev.entity_id IN (' . implode(',', $ids) . ')')->where('ccev.attribute_id = ?', $attribute->getAttributeId())->where('ccev.store_id = (' . $dbSelect1->__toString() . ')'); $cacheData = array(); foreach ($resource->getConnection()->fetchAll($dbSelect2) as $row) { $cacheData[$row['category_id']] = $row['name']; } $this->setData('categories_cache', $cacheData); }
public function testGetAllIdsWithBind() { $this->_model->getSelect()->where('code = :code'); $this->_model->addBindParam('code', 'admin'); $this->assertEquals(['0'], $this->_model->getAllIds()); }