00001 <?php 00002 /** 00003 * Magento 00004 * 00005 * NOTICE OF LICENSE 00006 * 00007 * This source file is subject to the Open Software License (OSL 3.0) 00008 * that is bundled with this package in the file LICENSE.txt. 00009 * It is also available through the world-wide-web at this URL: 00010 * http://opensource.org/licenses/osl-3.0.php 00011 * If you did not receive a copy of the license and are unable to 00012 * obtain it through the world-wide-web, please send an email 00013 * to license@magentocommerce.com so we can send you a copy immediately. 00014 * 00015 * DISCLAIMER 00016 * 00017 * Do not edit or add to this file if you wish to upgrade Magento to newer 00018 * versions in the future. If you wish to customize Magento for your 00019 * needs please refer to http://www.magentocommerce.com for more information. 00020 * 00021 * @category Mage 00022 * @package Mage_Adminhtml 00023 * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com) 00024 * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) 00025 */ 00026 00027 /** 00028 * Tax rule controller 00029 * 00030 * @category Mage 00031 * @package Mage_Adminhtml 00032 * @author Magento Core Team <core@magentocommerce.com> 00033 */ 00034 class Mage_Adminhtml_Tax_RuleController extends Mage_Adminhtml_Controller_Action 00035 { 00036 public function indexAction() 00037 { 00038 $this->_initAction() 00039 ->_addContent($this->getLayout()->createBlock('adminhtml/tax_rule')) 00040 ->renderLayout(); 00041 return $this; 00042 } 00043 00044 public function newAction() 00045 { 00046 $this->_forward('edit'); 00047 } 00048 00049 public function editAction() 00050 { 00051 $taxRuleId = $this->getRequest()->getParam('rule'); 00052 $ruleModel = Mage::getModel('tax/calculation_rule'); 00053 if ($taxRuleId) { 00054 $ruleModel->load($taxRuleId); 00055 if (!$ruleModel->getId()) { 00056 Mage::getSingleton('adminhtml/session')->addError(Mage::helper('tax')->__('This rule no longer exists')); 00057 $this->_redirect('*/*/'); 00058 return; 00059 } 00060 } 00061 00062 $data = Mage::getSingleton('adminhtml/session')->getRuleData(true); 00063 if (!empty($data)) { 00064 $ruleModel->setData($data); 00065 } 00066 00067 Mage::register('tax_rule', $ruleModel); 00068 00069 $this->_initAction() 00070 ->_addBreadcrumb($taxRuleId ? Mage::helper('tax')->__('Edit Rule') : Mage::helper('tax')->__('New Rule'), $taxRuleId ? Mage::helper('tax')->__('Edit Rule') : Mage::helper('tax')->__('New Rule')) 00071 ->_addContent($this->getLayout()->createBlock('adminhtml/tax_rule_edit')->setData('action', $this->getUrl('*/tax_rule/save'))) 00072 ->renderLayout(); 00073 } 00074 00075 public function saveAction() 00076 { 00077 if ($postData = $this->getRequest()->getPost()) { 00078 $ruleModel = Mage::getSingleton('tax/calculation_rule'); 00079 $ruleModel->setData($postData); 00080 00081 try { 00082 $ruleModel->save(); 00083 00084 Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('tax')->__('Tax rule was successfully saved')); 00085 $this->_redirect('*/*/'); 00086 00087 return; 00088 } 00089 catch (Mage_Core_Exception $e) { 00090 Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); 00091 } 00092 catch (Exception $e) { 00093 Mage::getSingleton('adminhtml/session')->addError(Mage::helper('tax')->__('Error while saving this tax rule. Please try again later.')); 00094 } 00095 00096 Mage::getSingleton('adminhtml/session')->setRuleData($postData); 00097 $this->_redirectReferer(); 00098 } 00099 } 00100 00101 public function deleteAction() 00102 { 00103 $ruleId = (int)$this->getRequest()->getParam('rule'); 00104 $ruleModel = Mage::getSingleton('tax/calculation_rule') 00105 ->load($ruleId); 00106 if (!$ruleModel->getId()) { 00107 Mage::getSingleton('adminhtml/session')->addError(Mage::helper('tax')->__('This rule no longer exists')); 00108 $this->_redirect('*/*/'); 00109 return; 00110 } 00111 00112 try { 00113 $ruleModel->delete(); 00114 00115 Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('tax')->__('Tax rule was successfully deleted')); 00116 $this->_redirect('*/*/'); 00117 00118 return; 00119 } 00120 catch (Mage_Core_Exception $e) { 00121 Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); 00122 } 00123 catch (Exception $e) { 00124 Mage::getSingleton('adminhtml/session')->addError(Mage::helper('tax')->__('Error while deleting this tax rule. Please try again later.')); 00125 } 00126 00127 $this->_redirectReferer(); 00128 } 00129 00130 /** 00131 * Initialize action 00132 * 00133 * @return Mage_Adminhtml_Controller_Action 00134 */ 00135 protected function _initAction() 00136 { 00137 $this->loadLayout() 00138 ->_setActiveMenu('sales/tax/rule') 00139 ->_addBreadcrumb(Mage::helper('tax')->__('Tax'), Mage::helper('tax')->__('Tax')) 00140 ->_addBreadcrumb(Mage::helper('tax')->__('Tax Rules'), Mage::helper('tax')->__('Tax Rules')) 00141 ; 00142 return $this; 00143 } 00144 00145 protected function _isAllowed() 00146 { 00147 return Mage::getSingleton('admin/session')->isAllowed('sales/tax/rules'); 00148 } 00149 }