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: class Mage_Adminhtml_Checkout_AgreementController extends Mage_Adminhtml_Controller_Action
35: {
36: public function indexAction()
37: {
38: $this->_title($this->__('Sales'))->_title($this->__('Terms and Conditions'));
39:
40: $this->_initAction()
41: ->_addContent($this->getLayout()->createBlock('adminhtml/checkout_agreement'))
42: ->renderLayout();
43: return $this;
44: }
45:
46: public function newAction()
47: {
48: $this->_forward('edit');
49: }
50:
51: public function editAction()
52: {
53: $this->_title($this->__('Sales'))->_title($this->__('Terms and Conditions'));
54:
55: $id = $this->getRequest()->getParam('id');
56: $agreementModel = Mage::getModel('checkout/agreement');
57:
58: if ($id) {
59: $agreementModel->load($id);
60: if (!$agreementModel->getId()) {
61: Mage::getSingleton('adminhtml/session')->addError(
62: Mage::helper('checkout')->__('This condition no longer exists.')
63: );
64: $this->_redirect('*/*/');
65: return;
66: }
67: }
68:
69: $this->_title($agreementModel->getId() ? $agreementModel->getName() : $this->__('New Condition'));
70:
71: $data = Mage::getSingleton('adminhtml/session')->getAgreementData(true);
72: if (!empty($data)) {
73: $agreementModel->setData($data);
74: }
75:
76: Mage::register('checkout_agreement', $agreementModel);
77:
78: $this->_initAction()
79: ->_addBreadcrumb($id ? Mage::helper('checkout')->__('Edit Condition') : Mage::helper('checkout')->__('New Condition'), $id ? Mage::helper('checkout')->__('Edit Condition') : Mage::helper('checkout')->__('New Condition'))
80: ->_addContent($this->getLayout()->createBlock('adminhtml/checkout_agreement_edit')->setData('action', $this->getUrl('*/*/save')))
81: ->renderLayout();
82: }
83:
84: public function saveAction()
85: {
86: if ($postData = $this->getRequest()->getPost()) {
87: $model = Mage::getSingleton('checkout/agreement');
88: $model->setData($postData);
89:
90: try {
91: $model->save();
92:
93: Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('checkout')->__('The condition has been saved.'));
94: $this->_redirect('*/*/');
95:
96: return;
97: }
98: catch (Mage_Core_Exception $e) {
99: Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
100: }
101: catch (Exception $e) {
102: Mage::getSingleton('adminhtml/session')->addError(Mage::helper('checkout')->__('An error occurred while saving this condition.'));
103: }
104:
105: Mage::getSingleton('adminhtml/session')->setAgreementData($postData);
106: $this->_redirectReferer();
107: }
108: }
109:
110: public function deleteAction()
111: {
112: $id = (int)$this->getRequest()->getParam('id');
113: $model = Mage::getSingleton('checkout/agreement')
114: ->load($id);
115: if (!$model->getId()) {
116: Mage::getSingleton('adminhtml/session')->addError(Mage::helper('checkout')->__('This condition no longer exists.'));
117: $this->_redirect('*/*/');
118: return;
119: }
120:
121: try {
122: $model->delete();
123:
124: Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('checkout')->__('The condition has been deleted'));
125: $this->_redirect('*/*/');
126:
127: return;
128: }
129: catch (Mage_Core_Exception $e) {
130: Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
131: }
132: catch (Exception $e) {
133: Mage::getSingleton('adminhtml/session')->addError(Mage::helper('checkout')->__('An error occurred while deleting this condition.'));
134: }
135:
136: $this->_redirectReferer();
137: }
138:
139: 140: 141: 142: 143:
144: protected function _initAction()
145: {
146: $this->loadLayout()
147: ->_setActiveMenu('sales/checkoutagreement')
148: ->_addBreadcrumb(Mage::helper('checkout')->__('Sales'), Mage::helper('checkout')->__('Sales'))
149: ->_addBreadcrumb(Mage::helper('checkout')->__('Checkout Conditions'), Mage::helper('checkout')->__('Checkout Terms and Conditions'))
150: ;
151: return $this;
152: }
153:
154: protected function _isAllowed()
155: {
156: return Mage::getSingleton('admin/session')->isAllowed('sales/checkoutagreement');
157: }
158: }
159: