*/ class Mage_Adminhtml_Sales_Billing_AgreementController extends Mage_Adminhtml_Controller_Action { /** * Billing agreements * */ public function indexAction() { $this->_title($this->__('Sales')) ->_title($this->__('Billing Agreements')); $this->loadLayout() ->_setActiveMenu('sales/billing_agreement') ->renderLayout(); } /** * Ajax action for billing agreements * */ public function gridAction() { $this->loadLayout(false) ->renderLayout(); } /** * View billing agreement action * */ public function viewAction() { $agreementModel = $this->_initBillingAgreement(); if ($agreementModel) { $this->_title($this->__('Sales')) ->_title($this->__('Billing Agreements')) ->_title(sprintf("#%s", $agreementModel->getReferenceId())); $this->loadLayout() ->_setActiveMenu('sales/billing_agreement') ->renderLayout(); return; } $this->_redirect('*/*/'); return; } /** * Related orders ajax action * */ public function ordersGridAction() { $this->_initBillingAgreement(); $this->loadLayout(false) ->renderLayout(); } /** * Cutomer billing agreements ajax action * */ public function customerGridAction() { $this->_initCustomer(); $this->loadLayout(false) ->renderLayout(); } /** * Cancel billing agreement action * */ public function cancelAction() { $agreementModel = $this->_initBillingAgreement(); if ($agreementModel && $agreementModel->canCancel()) { try { $agreementModel->cancel(); $this->_getSession()->addSuccess($this->__('The billing agreement has been canceled.')); $this->_redirect('*/*/view', array('_current' => true)); return; } catch (Mage_Core_Exception $e) { $this->_getSession()->addError($e->getMessage()); } catch (Exception $e) { $this->_getSession()->addError($this->__('Failed to cancel the billing agreement.')); Mage::logException($e); } $this->_redirect('*/*/view', array('_current' => true)); } return $this->_redirect('*/*/'); } /** * Delete billing agreement action */ public function deleteAction() { $agreementModel = $this->_initBillingAgreement(); if ($agreementModel) { try { $agreementModel->delete(); $this->_getSession()->addSuccess($this->__('The billing agreement has been deleted.')); $this->_redirect('*/*/'); return; } catch (Mage_Core_Exception $e) { $this->_getSession()->addError($e->getMessage()); } catch (Exception $e) { $this->_getSession()->addError($this->__('Failed to delete the billing agreement.')); Mage::logException($e); } $this->_redirect('*/*/view', array('_current' => true)); } $this->_redirect('*/*/'); } /** * Initialize billing agreement by ID specified in request * * @return Mage_Sales_Model_Billing_Agreement | false */ protected function _initBillingAgreement() { $agreementId = $this->getRequest()->getParam('agreement'); $agreementModel = Mage::getModel('sales/billing_agreement')->load($agreementId); if (!$agreementModel->getId()) { $this->_getSession()->addError($this->__('Wrong billing agreement ID specified.')); return false; } Mage::register('current_billing_agreement', $agreementModel); return $agreementModel; } /** * Initialize customer by ID specified in request * * @return Mage_Adminhtml_Sales_Billing_AgreementController */ protected function _initCustomer() { $customerId = (int) $this->getRequest()->getParam('id'); $customer = Mage::getModel('customer/customer'); if ($customerId) { $customer->load($customerId); } Mage::register('current_customer', $customer); return $this; } /** * Retrieve adminhtml session * * @return Mage_Adminhtml_Model_Session */ protected function _getSession() { return Mage::getSingleton('adminhtml/session'); } /** * Check currently called action by permissions for current user * * @return bool */ protected function _isAllowed() { $action = strtolower($this->getRequest()->getActionName()); switch ($action) { case 'index': case 'grid' : case 'view' : return Mage::getSingleton('admin/session')->isAllowed('sales/billing_agreement/actions/view'); break; case 'cancel': case 'delete': return Mage::getSingleton('admin/session')->isAllowed('sales/billing_agreement/actions/manage'); break; default: return Mage::getSingleton('admin/session')->isAllowed('sales/billing_agreement'); break; } } }