1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27:
28: 29: 30: 31: 32: 33: 34:
35: class Mage_Checkout_Model_Resource_Agreement extends Mage_Core_Model_Resource_Db_Abstract
36: {
37: 38: 39: 40:
41: protected function _construct()
42: {
43: $this->_init('checkout/agreement', 'agreement_id');
44: }
45:
46: 47: 48: 49: 50: 51:
52: protected function _beforeSave(Mage_Core_Model_Abstract $object)
53: {
54:
55: $height = $object->getContentHeight();
56: $height = Mage::helper('checkout')->stripTags($height);
57: if (!$height) {
58: $height = '';
59: }
60: if ($height && preg_match('/[0-9]$/', $height)) {
61: $height .= 'px';
62: }
63: $object->setContentHeight($height);
64: return parent::_beforeSave($object);
65: }
66:
67: 68: 69: 70: 71: 72:
73: protected function _afterSave(Mage_Core_Model_Abstract $object)
74: {
75: $condition = array('agreement_id = ?' => $object->getId());
76: $this->_getWriteAdapter()->delete($this->getTable('checkout/agreement_store'), $condition);
77:
78: foreach ((array)$object->getData('stores') as $store) {
79: $storeArray = array();
80: $storeArray['agreement_id'] = $object->getId();
81: $storeArray['store_id'] = $store;
82: $this->_getWriteAdapter()->insert($this->getTable('checkout/agreement_store'), $storeArray);
83: }
84:
85: return parent::_afterSave($object);
86: }
87:
88: 89: 90: 91: 92: 93:
94: protected function _afterLoad(Mage_Core_Model_Abstract $object)
95: {
96: $select = $this->_getReadAdapter()->select()
97: ->from($this->getTable('checkout/agreement_store'), array('store_id'))
98: ->where('agreement_id = :agreement_id');
99:
100: if ($stores = $this->_getReadAdapter()->fetchCol($select, array(':agreement_id' => $object->getId()))) {
101: $object->setData('store_id', $stores);
102: }
103:
104: return parent::_afterLoad($object);
105: }
106:
107: 108: 109: 110: 111: 112: 113: 114:
115: protected function _getLoadSelect($field, $value, $object)
116: {
117: $select = parent::_getLoadSelect($field, $value, $object);
118: if ($object->getStoreId()) {
119: $select->join(
120: array('cps' => $this->getTable('checkout/agreement_store')),
121: $this->getMainTable() . '.agreement_id = cps.agreement_id'
122: )
123: ->where('is_active=1')
124: ->where('cps.store_id IN (0, ?)', $object->getStoreId())
125: ->order('store_id DESC')
126: ->limit(1);
127: }
128: return $select;
129: }
130: }
131: