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
00028
00029
00030
00031
00032
00033
00034 class Mage_Adminhtml_Customer_GroupController extends Mage_Adminhtml_Controller_Action
00035 {
00036 protected function _initGroup()
00037 {
00038 Mage::register('current_group', Mage::getModel('customer/group'));
00039 $groupId = $this->getRequest()->getParam('id');
00040 if (!is_null($groupId)) {
00041 Mage::registry('current_group')->load($groupId);
00042 }
00043
00044 }
00045
00046
00047
00048 public function indexAction()
00049 {
00050 $this->loadLayout();
00051 $this->_setActiveMenu('customer/group');
00052 $this->_addBreadcrumb(Mage::helper('customer')->__('Customers'), Mage::helper('customer')->__('Customers'));
00053 $this->_addBreadcrumb(Mage::helper('customer')->__('Customer Groups'), Mage::helper('customer')->__('Customer Groups'));
00054
00055 $this->_addContent($this->getLayout()->createBlock('adminhtml/customer_group', 'group'));
00056
00057 $this->renderLayout();
00058 }
00059
00060
00061
00062
00063 public function newAction()
00064 {
00065 $this->_initGroup();
00066 $this->loadLayout();
00067 $this->_setActiveMenu('customer/group');
00068 $this->_addBreadcrumb(Mage::helper('customer')->__('Customers'), Mage::helper('customer')->__('Customers'));
00069 $this->_addBreadcrumb(Mage::helper('customer')->__('Customer Groups'), Mage::helper('customer')->__('Customer Groups'), $this->getUrl('*/customer_group'));
00070
00071 if (!is_null(Mage::registry('current_group')->getId())) {
00072 $this->_addBreadcrumb(Mage::helper('customer')->__('Edit Group'), Mage::helper('customer')->__('Edit Customer Groups'));
00073 } else {
00074 $this->_addBreadcrumb(Mage::helper('customer')->__('New Group'), Mage::helper('customer')->__('New Customer Groups'));
00075 }
00076
00077 $this->getLayout()->getBlock('content')
00078 ->append($this->getLayout()->createBlock('adminhtml/customer_group_edit', 'group')
00079 ->setEditMode((bool)Mage::registry('current_group')->getId()));
00080
00081 $this->renderLayout();
00082 }
00083
00084
00085
00086
00087 public function editAction()
00088 {
00089 $this->_forward('new');
00090 }
00091
00092
00093
00094
00095 public function saveAction()
00096 {
00097 $customerGroup = Mage::getModel('customer/group');
00098 $id = $this->getRequest()->getParam('id');
00099 if (!is_null($id)) {
00100 $customerGroup->load($id);
00101 }
00102
00103 if ($taxClass = $this->getRequest()->getParam('tax_class')) {
00104 try {
00105 $customerGroup->setCode($this->getRequest()->getParam('code'))
00106 ->setTaxClassId($taxClass)
00107 ->save();
00108 Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('customer')->__('Customer Group was successfully saved'));
00109 $this->getResponse()->setRedirect($this->getUrl('*/customer_group'));
00110 return;
00111 } catch (Exception $e) {
00112 Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
00113 Mage::getSingleton('adminhtml/session')->setCustomerGroupData($customerGroup->getData());
00114 $this->getResponse()->setRedirect($this->getUrl('*/customer_group/edit', array('id' => $id)));
00115 return;
00116 }
00117 } else {
00118 $this->_forward('new');
00119 }
00120
00121 }
00122
00123
00124
00125
00126 public function deleteAction()
00127 {
00128 $customerGroup = Mage::getModel('customer/group');
00129 if ($id = (int)$this->getRequest()->getParam('id')) {
00130 try {
00131 $customerGroup->load($id);
00132 $customerGroup->delete();
00133 Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('customer')->__('Customer Group was successfully deleted'));
00134 $this->getResponse()->setRedirect($this->getUrl('*/customer_group'));
00135 return;
00136 } catch (Exception $e) {
00137 Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
00138 $this->getResponse()->setRedirect($this->getUrl('*/customer_group/edit', array('id' => $id)));
00139 return;
00140 }
00141 }
00142
00143 $this->_redirect('*/customer_group');
00144 }
00145
00146 protected function _isAllowed()
00147 {
00148 return Mage::getSingleton('admin/session')->isAllowed('customer/group');
00149 }
00150 }