00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 class Mage_Checkout_Model_Mysql4_Agreement extends Mage_Core_Model_Mysql4_Abstract
00028 {
00029 protected function _construct()
00030 {
00031 $this->_init('checkout/agreement', 'agreement_id');
00032 }
00033
00034 protected function _beforeSave(Mage_Core_Model_Abstract $object)
00035 {
00036
00037 $height = $object->getContentHeight();
00038 if (!$height) {
00039 $height = '';
00040 }
00041 if ($height && preg_match('/[0-9]$/', $height)) {
00042 $height .= 'px';
00043 }
00044 $object->setContentHeight($height);
00045 return parent::_beforeSave($object);
00046 }
00047
00048 protected function _afterSave(Mage_Core_Model_Abstract $object)
00049 {
00050 $condition = $this->_getWriteAdapter()->quoteInto('agreement_id = ?', $object->getId());
00051 $this->_getWriteAdapter()->delete($this->getTable('checkout/agreement_store'), $condition);
00052
00053 foreach ((array)$object->getData('stores') as $store) {
00054 $storeArray = array();
00055 $storeArray['agreement_id'] = $object->getId();
00056 $storeArray['store_id'] = $store;
00057 $this->_getWriteAdapter()->insert($this->getTable('checkout/agreement_store'), $storeArray);
00058 }
00059
00060 return parent::_afterSave($object);
00061 }
00062
00063 protected function _afterLoad(Mage_Core_Model_Abstract $object)
00064 {
00065 $select = $this->_getReadAdapter()->select()
00066 ->from($this->getTable('checkout/agreement_store'))
00067 ->where('agreement_id = ?', $object->getId());
00068
00069 if ($data = $this->_getReadAdapter()->fetchAll($select)) {
00070 $storesArray = array();
00071 foreach ($data as $row) {
00072 $storesArray[] = $row['store_id'];
00073 }
00074 $object->setData('store_id', $storesArray);
00075 }
00076
00077 return parent::_afterLoad($object);
00078 }
00079
00080 protected function _getLoadSelect($field, $value, $object)
00081 {
00082 $select = parent::_getLoadSelect($field, $value, $object);
00083
00084 if ($object->getStoreId()) {
00085 $select->join(array('cps' => $this->getTable('checkout/agreement_store')), $this->getMainTable().'.agreement_id = `cps`.agreement_id')
00086 ->where('is_active=1 AND `cps`.store_id in (0, ?) ', $object->getStoreId())
00087 ->order('store_id DESC')
00088 ->limit(1);
00089 }
00090 return $select;
00091 }
00092 }