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_Tax_ClassController extends Mage_Adminhtml_Controller_Action
35: {
36: 37: 38: 39:
40: public function saveAction()
41: {
42: if ($postData = $this->getRequest()->getPost()) {
43:
44: $model = Mage::getModel('tax/class')->setData($postData);
45:
46: try {
47: $model->save();
48: $classId = $model->getId();
49: $classType = $model->getClassType();
50: $classUrl = '*/tax_class_' . strtolower($classType);
51:
52: Mage::getSingleton('adminhtml/session')->addSuccess(
53: Mage::helper('tax')->__('The tax class has been saved.')
54: );
55: $this->_redirect($classUrl);
56:
57: return ;
58: } catch (Mage_Core_Exception $e) {
59: Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
60: Mage::getSingleton('adminhtml/session')->setClassData($postData);
61: $this->_redirectReferer();
62: } catch (Exception $e) {
63: Mage::getSingleton('adminhtml/session')->addError(
64: Mage::helper('tax')->__('An error occurred while saving this tax class.')
65: );
66: Mage::getSingleton('adminhtml/session')->setClassData($postData);
67: $this->_redirectReferer();
68: }
69:
70: $this->_redirectReferer();
71: return;
72: }
73: $this->getResponse()->setRedirect($this->getUrl('*/tax_class'));
74: }
75:
76: 77: 78: 79: 80:
81: protected function _initAction()
82: {
83: $classType = strtolower($this->getRequest()->getParam('classType'));
84: $this->loadLayout()
85: ->_setActiveMenu('sales/tax/tax_classes_' . $classType)
86: ->_addBreadcrumb(Mage::helper('tax')->__('Sales'), Mage::helper('tax')->__('Sales'))
87: ->_addBreadcrumb(Mage::helper('tax')->__('Tax'), Mage::helper('tax')->__('Tax'))
88: ;
89:
90: return $this;
91: }
92:
93: 94: 95: 96: 97:
98: protected function _isAllowed()
99: {
100: return Mage::getSingleton('admin/session')->isAllowed('sales/tax/classes_product')
101: || Mage::getSingleton('admin/session')->isAllowed('sales/tax/classes_customer');
102: }
103: }
104: