protected function _getMatchedIds($query) { if (!is_array($this->_attributes) || !count($this->_attributes)) { Mage::throwException('Searchable attributes not defined'); } $query = Mage::helper('core/string')->splitWords($query, true, 100); $select = $this->_collection->getSelect(); $having = array(); foreach ($query as $word) { $subhaving = array(); foreach ($this->_attributes as $attr => $weight) { $subhaving[] = $this->_getCILike($attr, $word, array('position' => 'any')); } $having[] = '(' . implode(' OR ', $subhaving) . ')'; } $havingCondition = implode(' AND ', $having); if ($havingCondition != '') { $select->having($havingCondition); } $read = Mage::getSingleton('core/resource')->getConnection('core_read'); $stmt = $read->query($select); $result = array(); while ($row = $stmt->fetch(Zend_Db::FETCH_ASSOC)) { $result[$row[$this->_primaryKey]] = 0; } return $result; }
public function toOptions(Mage_Core_Model_Mysql4_Collection_Abstract $collection, array $fields) { $key = key($fields); $value = $fields[$key]; $data = $collection->toArray(array($key, $value)); $result = ''; foreach ($data['items'] as $item) { $result[$item[$key]] = $item[$value]; } return $result; }
/** * Remove hidden items from a product or category collection * * @param Mage_Eav_Model_Entity_Collection_Abstract|Mage_Core_Model_Mysql4_Collection_Abstract $collection */ public function _removeHiddenCollectionItems($collection) { // Loop through each category or product foreach ($collection as $key => $item) { $catData = Mage::getModel("catalog/category")->load($item->getEntityId()); // If it is a category if ($item->getEntityTypeId() == 3 && $item->getLevel() != 2) { if (strtolower($catData->getUrlKey()) != 'get-the-look' && strtolower($catData->getUrlKey()) != 'new-arrivals') { if ($this->getProductCountCustom($catData) <= 0) { $collection->removeItemByKey($key); } } } } }
/** * Standard resource collection initalization * * @param string $model * @return Mage_Core_Model_Mysql4_Collection_Abstract */ protected function _init($model, $resourceModel = null) { parent::_init($model, $resourceModel); $this->_relationTable = $this->getMainTable() . '_relation'; $this->_localeTable = $this->getMainTable() . '_locale'; return $this; }
protected function _initSelect() { parent::_initSelect(); $modelCat = Mage::getResourceSingleton('downloads/categories'); $this->getSelect()->joinLeft(array('relation' => $this->getTable('downloads/relation')), 'main_table.file_id = relation.file_id', array('products_count' => 'COUNT(relation.product_id)'))->joinLeft(array('cat' => $modelCat->getMainTable()), 'main_table.category_id = cat.category_id', array('title'))->group('main_table.file_id'); return $this; }
protected function _afterLoad() { /*$items = $this->getColumnValues('post_id'); if (count($items)) { $select = $this->getConnection()->select() ->from($this->getTable('store')) ->where($this->getTable('store').'.post_id IN (?)', $items); if ($result = $this->getConnection()->fetchPairs($select)) { foreach ($this as $item) { if (!isset($result[$item->getData('post_id')])) { continue; } if ($result[$item->getData('post_id')] == 0) { $storeCode = key(Mage::app()->getStores(false, true)); } else { $storeCode = Mage::app()->getStore($result[$item->getData('post_id')])->getCode(); } $item->setData('store_code', $storeCode); } } }*/ if (count($this) > 0) { Mage::dispatchEvent("fontis_blog_post_collection_load_after", array("collection" => $this)); } return parent::_afterLoad(); }
public function addFieldToFilter($attribute, $condition = null) { if ($attribute == 'status') { $attribute = 'main_table.' . $attribute; } return parent::addFieldToFilter($attribute, $condition); }
/** * * * (overrides parent method) */ public function _initSelect() { parent::_initSelect(); // Add a simplified version of the transfer references (1 reference per 1 transfer) $this->_addTransferReferences($this->_getSingleReferenceSelect()); return $this; }
public function load($printQuery = false, $logQuery = false) { Varien_Profiler::start("aw::advancedreports::aggregator::load_collection"); parent::load($printQuery, $logQuery); Varien_Profiler::stop("aw::advancedreports::aggregator::load_collection"); return $this; }
protected function _initSelect() { parent::_initSelect(); $select = $this->getSelect(); $select->join(array('cust' => $this->getTable('rewardpoints/customer_entity')), 'rewardpoints_referral_parent_id = cust.entity_id'); return $this; }
/** * After load processing - adds store information to the datasets * */ protected function _afterLoad() { $connection = $this->getConnection(); foreach ($this as $item) { $page_stores = array(); if ($alias = $item->getData("alias")) { $cms_page = Mage::getModel("cms/page")->load($alias, "identifier"); if ($cms_page->getPageId()) { $page_stores = $cms_page->getStoreId(); $select = $connection->select()->from(array('cps' => $this->getTable('cms/page_store')))->where('cps.page_id = (?)', $cms_page->getPageId()); if ($result = $connection->fetchPairs($select)) { if ($result[$cms_page->getPageId()] == 0) { $stores = Mage::app()->getStores(false, true); $storeId = current($stores)->getId(); $storeCode = key($stores); } else { $storeId = $result[$cms_page->getPageId()]; $storeCode = Mage::app()->getStore($storeId)->getCode(); } $item->setData('_first_store_id', $storeId); $item->setData('store_code', $storeCode); } $stores = isset($stores) && $stores ? $stores : array(0); $item->setData("store_id", $page_stores); } } } parent::_afterLoad(); }
/** * @return Varien_Data_Collection_Db */ public function _afterLoad() { foreach ($this->getItems() as $item) { $this->getResource()->unserializeFields($item); } return parent::_afterLoadData(); }
protected function _initSelect() { parent::_initSelect(); // $this->getSelect()->where('main_table.post_type=?', 'post') // ->where('main_table.post_status=?', 'publish'); return $this; }
protected function _afterLoad() { parent::_afterLoad(); $this->_loadLabels(); $this->_loadPrices(); return $this; }
protected function _afterLoad() { parent::_afterLoad(); if (VPROF) { Varien_Profiler::start('TTT1:' . __METHOD__); } $this->_addProductAttributes(); if (VPROF) { Varien_Profiler::stop('TTT1:' . __METHOD__); } if (VPROF) { Varien_Profiler::start('TTT2:' . __METHOD__); } $this->_addAssociatedProductFilters(); if (VPROF) { Varien_Profiler::stop('TTT2:' . __METHOD__); } if (VPROF) { Varien_Profiler::start('TTT3:' . __METHOD__); } $this->_loadLabels(); if (VPROF) { Varien_Profiler::stop('TTT3:' . __METHOD__); } if (VPROF) { Varien_Profiler::start('TTT4:' . __METHOD__); } $this->_loadPrices(); if (VPROF) { Varien_Profiler::stop('TTT4:' . __METHOD__); } return $this; }
protected function _afterLoad() { foreach ($this->_items as $i) { $i->afterLoad(); } return parent::_afterLoad(); }
protected function _afterLoadData() { foreach ($this->getItems() as $item) { Mage::getResourceModel('aw_giftcard/history')->unserializeFields($item); } return parent::_afterLoadData(); }
/** * After load processing - adds store information to the datasets * */ protected function _afterLoad() { if ($this->_previewFlag) { $items = $this->getColumnValues('verticalmenu_id'); if (count($items)) { $select = $this->getConnection()->select()->from($this->getTable('ves_verticalmenu/verticalmenu_store'))->where($this->getTable('ves_verticalmenu/verticalmenu_store') . '.verticalmenu_id IN (?)', $items); if ($result = $this->getConnection()->fetchPairs($select)) { foreach ($this as $item) { if (!isset($result[$item->getData('verticalmenu_id')])) { continue; } if ($result[$item->getData('verticalmenu_id')] == 0) { $stores = Mage::app()->getStores(false, true); $storeId = current($stores)->getId(); $storeCode = key($stores); } else { $storeId = $result[$item->getData('verticalmenu_id')]; $storeCode = Mage::app()->getStore($storeId)->getCode(); } if ($item->getData('is_default') == 1) { $this->setData('is_default', Mage::helper('ves_verticalmenu')->__('<span class="hightlight">Default</span>')); } else { $this->setData('is_default', Mage::helper('ves_verticalmenu')->__('No')); } $item->setData('_first_store_id', $storeId); $item->setData('store_code', $storeCode); } } } } parent::_afterLoad(); }
/** * Join store relation table if there is store filter */ protected function _renderFiltersBefore() { if ($this->getFilter('store')) { $this->getSelect()->join(array('store_table' => $this->getTable('category_store')), 'main_table.category_id = store_table.category_id', array())->group('main_table.category_id'); } return parent::_renderFiltersBefore(); }
public function addFieldToFilter($field, $condition = null) { if ($field == 'meta_title_error') { if ($condition == 'missing') { $field = 'prepared_meta_title'; $condition = array('eq' => ''); } elseif ($condition == 'long') { $field = 'meta_title_len'; $condition = array('gt' => '70'); } elseif ($condition == 'duplicate') { $field = 'meta_title_dupl'; $condition = array('gt' => '1'); } } elseif ($field == 'name_error') { if ($condition == 'duplicate') { $field = 'name_dupl'; $condition = array('gt' => '1'); } } elseif ($field == 'meta_descr_error') { if ($condition == 'missing') { $field = 'meta_descr_len'; $condition = array('eq' => '0'); } elseif ($condition == 'long') { $field = 'meta_descr_len'; $condition = array('gt' => '150'); } } return parent::addFieldToFilter($field, $condition); }
protected function _afterLoad() { foreach ($this->_items as $model) { $model->setData('store_ids', explode(',', $model->getData('store_ids'))); } return parent::_afterLoad(); }
protected function _afterLoad() { if ($this->_previewFlag) { $items = $this->getColumnValues('splash_id'); if (count($items)) { $select = $this->getConnection()->select()->from($this->getTable('splash/splash_store'))->where($this->getTable('splash/splash_store') . '.splash_id IN (?)', $items); if ($result = $this->getConnection()->fetchPairs($select)) { foreach ($this as $item) { if (!isset($result[$item->getData('splash_id')])) { continue; } if ($result[$item->getData('splash_id')] == 0) { $stores = Mage::app()->getStores(false, true); $storeId = current($stores)->getId(); $storeCode = key($stores); } else { $storeId = $result[$item->getData('splash_id')]; $storeCode = Mage::app()->getStore($storeId)->getCode(); } $item->setData('_first_store_id', $storeId); $item->setData('store_code', $storeCode); } } } } parent::_afterLoad(); }
public function addListRestriction() { $statuses = Mage::getStoreConfig('rewardpoints/default/valid_statuses', Mage::app()->getStore()->getId()); $statuses_used = Mage::getStoreConfig('rewardpoints/default/valid_used_statuses', Mage::app()->getStore()->getId()); $status_field = Mage::getStoreConfig('rewardpoints/default/status_used', Mage::app()->getStore()->getId()); $order_states = explode(",", $statuses); $order_states_used = explode(",", $statuses_used); parent::_initSelect(); $select = $this->getSelect(); $select->from($this->getTable('rewardpoints/rewardpoints_account'), array(new Zend_Db_Expr('SUM(' . $this->getTable('rewardpoints/rewardpoints_account') . '.points_current) AS all_points_accumulated'), new Zend_Db_Expr('SUM(' . $this->getTable('rewardpoints/rewardpoints_account') . '.points_spent) AS all_points_spent')))->where($this->getTable('rewardpoints/rewardpoints_account') . '.customer_id = e.entity_id'); if (version_compare(Mage::getVersion(), '1.4.0', '>=')) { /*$select->where(" (".Mage::getModel("rewardpoints/stats")->constructSqlPointsType($this->getTable('rewardpoints/rewardpoints_account'))." or ".$this->getTable('rewardpoints/rewardpoints_account').".rewardpoints_$status_field in (?) ) ", $order_states);*/ $select->where(" (" . Mage::getModel("rewardpoints/stats")->constructSqlPointsType($this->getTable('rewardpoints/rewardpoints_account')) . "\n or (" . $this->getTable('rewardpoints/rewardpoints_account') . ".rewardpoints_{$status_field} in (?) AND " . $this->getTable('rewardpoints/rewardpoints_account') . ".points_current > 0)\n or (" . $this->getTable('rewardpoints/rewardpoints_account') . ".rewardpoints_{$status_field} in (?) AND " . $this->getTable('rewardpoints/rewardpoints_account') . ".points_spent > 0)\n ) ", $order_states, $order_states_used); } else { /*$select->where(" (".Mage::getModel("rewardpoints/stats")->constructSqlPointsType($this->getTable('rewardpoints/rewardpoints_account'))." or ".$this->getTable('rewardpoints/rewardpoints_account').".rewardpoints_state in ((?) ) ", $order_states);*/ $select->where(" (" . Mage::getModel("rewardpoints/stats")->constructSqlPointsType($this->getTable('rewardpoints/rewardpoints_account')) . "\n or (" . $this->getTable('rewardpoints/rewardpoints_account') . ".rewardpoints_{$status_field} in (?) AND " . $this->getTable('rewardpoints/rewardpoints_account') . ".points_current > 0)\n or (" . $this->getTable('rewardpoints/rewardpoints_account') . ".rewardpoints_{$status_field} in (?) AND " . $this->getTable('rewardpoints/rewardpoints_account') . ".points_spent > 0)\n ) ", $order_states, $order_states_used); } //v.2.0.0 if (Mage::getStoreConfig('rewardpoints/default/points_delay', Mage::app()->getStore()->getId())) { $this->getSelect()->where('( NOW() >= ' . $this->getTable('rewardpoints/rewardpoints_account') . '.date_start OR ' . $this->getTable('rewardpoints/rewardpoints_account') . '.date_start IS NULL)'); } if (Mage::getStoreConfig('rewardpoints/default/points_duration', Mage::app()->getStore()->getId())) { $select->where('( ' . $this->getTable('rewardpoints/rewardpoints_account') . '.date_end >= NOW() OR ' . $this->getTable('rewardpoints/rewardpoints_account') . '.date_end IS NULL)'); } $select->group($this->getTable('rewardpoints/rewardpoints_account') . '.customer_id'); return $this; }
public function _initSelect() { //die("<PRE>".$this->getSelect()->__toString(). "</PRE>"); parent::_initSelect(); $this->getSelect()->distinct(true)->joinInner(array('product_table' => $this->getTable('catalogrule/rule_product')), 'main_table.rule_id = product_table.rule_id', array())->where('from_time=0 or from_time<=? or to_time=0 or to_time>=?', now())->group('main_table.rule_id'); //die("<PRE>".$this->getSelect()->__toString()."</PRE>"); }
/** * Don't add item to the collection if only fixed are allowed and its carrier is not fixed * * @param Mage_Sales_Model_Quote_Address_Rate $rate * @return Mage_Sales_Model_Mysql4_Quote_Address_Rate_Collection; */ public function addItem(Varien_Object $rate) { if ($this->_allowFixedOnly && (!$rate->getCarrierInstance() || !$rate->getCarrierInstance()->isFixed())) { return $this; } return parent::addItem($rate); }
protected function _initSelect() { parent::_initSelect(); $select = $this->getSelect(); $select->join(array('cust' => $this->getTable('loyaltyprogram/customer_entity')), 'referer_id = cust.entity_id'); return $this; }
/** * @return Noovias_Cron_Model_Mysql4_Schedule_Config_Collection * * */ protected function _afterLoad() { parent::_afterLoad(); /** * Add availible cron jobs to collection, if they are not saved in the database, but * don't save the collection, new db entries are creted if a cron job is edited and saved * via the Backend Grid (Noovias - Cronjobs -> Settings) */ $availibleJobCodes = $this->helperCron()->getAvailableJobCodesAsArray(); foreach ($availibleJobCodes as $jobCode) { if (!$this->getItemByColumnValue('job_code', $jobCode)) { /** @var $itemToAdd Noovias_Cron_Model_Schedule_Config */ $itemToAdd = $this->getServiceInitializeConfig()->initByJobCode($jobCode, false); $this->addItem($itemToAdd); } } /** * Set the _totalRecords variable in order to render the cron jobs in the * grid (Noovias - Cronjobs -> Settings) (renders only if the getSize method * returns a value > 0) */ $this->_totalRecords = count($this->getItems()); /** Sort ascending by job_code */ $items = $this->getItems(); usort($items, array('Noovias_Cron_Model_Mysql4_Schedule_Config_Collection', 'sortByJobCode')); $this->_items = $items; return $this; }
protected function _initSelect() { parent::_initSelect(); $this->getSelect()->joinLeft(array('cat' => $this->getIndex()->getProperty('db_table_prefix') . 'categories'), 'cat.id=main_table.catid', array('path')); // echo $this->getSelect();die(); return $this; }
/** * Unserialize additional_information in each item * @return Mage_Core_Model_Mysql4_Collection_Abstract */ protected function _afterLoad() { foreach ($this->_items as $item) { $this->getResource()->unserializeFields($item); } return parent::_afterLoad(); }
public function load($printQuery = false, $logQuery = false) { if (!$this->_loadDefault) { $this->setWithoutDefaultFilter(); } return parent::load($printQuery, $logQuery); }