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_Customer_GroupController extends Mage_Adminhtml_Controller_Action
35: {
36: protected function _initGroup()
37: {
38: $this->_title($this->__('Customers'))->_title($this->__('Customer Groups'));
39:
40: Mage::register('current_group', Mage::getModel('customer/group'));
41: $groupId = $this->getRequest()->getParam('id');
42: if (!is_null($groupId)) {
43: Mage::registry('current_group')->load($groupId);
44: }
45:
46: }
47: 48: 49:
50: public function indexAction()
51: {
52: $this->_title($this->__('Customers'))->_title($this->__('Customer Groups'));
53:
54: $this->loadLayout();
55: $this->_setActiveMenu('customer/group');
56: $this->_addBreadcrumb(Mage::helper('customer')->__('Customers'), Mage::helper('customer')->__('Customers'));
57: $this->_addBreadcrumb(Mage::helper('customer')->__('Customer Groups'), Mage::helper('customer')->__('Customer Groups'));
58: $this->renderLayout();
59: }
60:
61: 62: 63:
64: public function newAction()
65: {
66: $this->_initGroup();
67: $this->loadLayout();
68: $this->_setActiveMenu('customer/group');
69: $this->_addBreadcrumb(Mage::helper('customer')->__('Customers'), Mage::helper('customer')->__('Customers'));
70: $this->_addBreadcrumb(Mage::helper('customer')->__('Customer Groups'), Mage::helper('customer')->__('Customer Groups'), $this->getUrl('*/customer_group'));
71:
72: $currentGroup = Mage::registry('current_group');
73:
74: if (!is_null($currentGroup->getId())) {
75: $this->_addBreadcrumb(Mage::helper('customer')->__('Edit Group'), Mage::helper('customer')->__('Edit Customer Groups'));
76: } else {
77: $this->_addBreadcrumb(Mage::helper('customer')->__('New Group'), Mage::helper('customer')->__('New Customer Groups'));
78: }
79:
80: $this->_title($currentGroup->getId() ? $currentGroup->getCode() : $this->__('New Group'));
81:
82: $this->getLayout()->getBlock('content')
83: ->append($this->getLayout()->createBlock('adminhtml/customer_group_edit', 'group')
84: ->setEditMode((bool)Mage::registry('current_group')->getId()));
85:
86: $this->renderLayout();
87: }
88:
89: 90: 91:
92: public function editAction()
93: {
94: $this->_forward('new');
95: }
96:
97: 98: 99:
100: public function saveAction()
101: {
102: $customerGroup = Mage::getModel('customer/group');
103: $id = $this->getRequest()->getParam('id');
104: if (!is_null($id)) {
105: $customerGroup->load((int)$id);
106: }
107:
108: $taxClass = (int)$this->getRequest()->getParam('tax_class');
109:
110: if ($taxClass) {
111: try {
112: $customerGroupCode = (string)$this->getRequest()->getParam('code');
113:
114: if (!empty($customerGroupCode)) {
115: $customerGroup->setCode($customerGroupCode);
116: }
117:
118: $customerGroup->setTaxClassId($taxClass)->save();
119: Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('customer')->__('The customer group has been saved.'));
120: $this->getResponse()->setRedirect($this->getUrl('*/customer_group'));
121: return;
122: } catch (Exception $e) {
123: Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
124: Mage::getSingleton('adminhtml/session')->setCustomerGroupData($customerGroup->getData());
125: $this->getResponse()->setRedirect($this->getUrl('*/customer_group/edit', array('id' => $id)));
126: return;
127: }
128: } else {
129: $this->_forward('new');
130: }
131: }
132:
133: 134: 135:
136: public function deleteAction()
137: {
138: $customerGroup = Mage::getModel('customer/group');
139: if ($id = (int)$this->getRequest()->getParam('id')) {
140: try {
141: $customerGroup->load($id);
142: $customerGroup->delete();
143: Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('customer')->__('The customer group has been deleted.'));
144: $this->getResponse()->setRedirect($this->getUrl('*/customer_group'));
145: return;
146: } catch (Exception $e) {
147: Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
148: $this->getResponse()->setRedirect($this->getUrl('*/customer_group/edit', array('id' => $id)));
149: return;
150: }
151: }
152:
153: $this->_redirect('*/customer_group');
154: }
155:
156: protected function _isAllowed()
157: {
158: return Mage::getSingleton('admin/session')->isAllowed('customer/group');
159: }
160: }
161: