_init('clnews/category', 'category_id'); } protected function _afterSave(Mage_Core_Model_Abstract $object) { $condition = $this->_getWriteAdapter()->quoteInto('category_id = ?', $object->getId()); $this->_getWriteAdapter()->delete($this->getTable('category_store'), $condition); if (!$object->getData('stores')) { $storeArray = array(); $storeArray['category_id'] = $object->getId(); $storeArray['store_id'] = Mage::app()->getStore(true)->getId(); $this->_getWriteAdapter()->insert($this->getTable('category_store'), $storeArray); } else { foreach ((array)$object->getData('stores') as $store) { $storeArray = array(); $storeArray['category_id'] = $object->getId(); $storeArray['store_id'] = $store; $this->_getWriteAdapter()->insert($this->getTable('category_store'), $storeArray); } } return parent::_afterSave($object); } protected function _afterLoad(Mage_Core_Model_Abstract $object) { $select = $this->_getReadAdapter()->select() ->from($this->getTable('category_store')) ->where('category_id = ?', $object->getId()); if ($data = $this->_getReadAdapter()->fetchAll($select)) { $storesArray = array(); foreach ($data as $row) { $storesArray[] = $row['store_id']; } $object->setData('store_id', $storesArray); } return parent::_afterLoad($object); } /* protected function _getLoadSelect($field, $value, $object) { $select = parent::_getLoadSelect($field, $value, $object); if ($object->getStoreId()) { $select->join(array('cps' => $this->getTable('cat_store')), $this->getMainTable().'.cat_id = `cps`.cat_id') ->where('`cps`.store_id in (0, ?) ', $object->getStoreId()) ->order('store_id DESC') ->limit(1); } return $select; } */ }