public function processAction()
 {
     if (!$this->_request->isXmlHttpRequest() || !$this->_request->isPost()) {
         $this->_redirect('/admin/products/');
     }
     $return = array();
     $productGateway = new Products_Model_ProductGateway();
     $form = $productGateway->getForm('DeleteProduct');
     $validForm = $form->isValid($this->_request->getParams());
     // Check the form for validity
     if (!$validForm) {
         $return['formErrors'] = $form->getMessages();
         $return['formResult'] = FALSE;
     } else {
         $form->removeElement('password_confirm');
         $form->removeElement('submit');
         $temp = $form->getValues();
         // Reset product_deleted to 1 since we are "deleting" the product
         $temp['product_deleted'] = 1;
         $page = $productGateway->create($temp);
         $page->save();
         $flashMessenger = $this->_helper->getHelper('FlashMessenger');
         $flashMessenger->setNamespace('notifications')->addMessage('Product Deleted.');
         $return['redirect']['location'] = '/admin/products/';
     }
     $this->_helper->json->sendJson($return);
 }
 /**
  * Set the category Id & company id
  * for the product form and call the correct form
  */
 public function processAction()
 {
     if (!$this->_request->isXmlHttpRequest() || !$this->_request->isPost()) {
         $this->_redirector->gotoRoute(array('controller' => 'index', 'module' => 'products'), 'admin');
     }
     $return = array();
     $productGateway = new Products_Model_ProductGateway();
     $form = $productGateway->getForm('CreateProduct');
     $validForm = $form->isValid($this->_request->getParams());
     // Check the form for validity
     if (!$validForm) {
         $return['formErrors'] = $form->getMessages();
     } else {
         $form->removeElement('product_company_name');
         $form->removeElement('product_category_name');
         $product = $productGateway->create($form->getValues());
         $productId = $product->save();
         $flashMessenger = $this->_helper->getHelper('FlashMessenger');
         $flashMessenger->setNamespace('notifications')->addMessage('Product Created.');
         if ($this->_request->getParam('close') == 1) {
             $return['redirect']['location'] = '/admin/products/';
         } else {
             $return['redirect']['location'] = '/admin/products/modify/' . $productId;
         }
     }
     $this->_helper->json->sendJson($return);
 }
 /**
  * Pull product for a detailed view
  * w/ no edit option
  */
 public function viewAction()
 {
     if ($this->_request->getParam('id', null) === null) {
         $this->_redirect('/admin/products/');
     }
     $identity = Zend_Auth::getInstance()->getIdentity()->toArray();
     $productGateway = new Products_Model_ProductGateway();
     $product = $productGateway->fetchProductWithAllDetailsById($this->_request->getParam('id'));
     if ($product === null) {
         $this->_redirect('/admin/products/');
     }
     $request = Zend_Controller_Front::getInstance()->getRequest();
     $this->view->module = $request->getModuleName();
     $this->view->controller = $request->getControllerName();
     $this->view->product = $product;
 }
 /**
  * Based on the product that has been modified
  * Pull the correct for, test for validity and save
  * or return the appropriate errors
  */
 public function processAction()
 {
     if (!$this->_request->isXmlHttpRequest() || !$this->_request->isPost() || !$this->_request->getParam('product_category_name')) {
         $this->_redirect('/admin/products/');
     }
     $return = array();
     //Identify the correct Product Form
     $productGateway = new Products_Model_ProductGateway();
     switch ($this->_request->getParam('product_category_name')) {
         case "Annuity":
             $form = $productGateway->getForm('ModifyAnnuityProduct');
             $validForm = $form->isValid($this->_request->getParams());
             break;
         case "Disability":
             $form = $productGateway->getForm('ModifyDisabilityProduct');
             $validForm = $form->isValid($this->_request->getParams());
             break;
         case "Health":
             $form = $productGateway->getForm('ModifyHealthProduct');
             $validForm = $form->isValid($this->_request->getParams());
             break;
         case "Life":
             $form = $productGateway->getForm('ModifyLifeProduct');
             $validForm = $form->isValid($this->_request->getParams());
             break;
         default:
             $form = new Zend_Form();
             $form->addErrorMessage('Unable to indentify a Valid Form');
             $validForm = false;
     }
     // Check the form for validity
     if (!$validForm) {
         $return['formErrors'] = $form->getMessages();
         $return['formResult'] = FALSE;
     } else {
         $form->removeElement('product_company_name');
         $form->removeElement('product_category_name');
         $product = $productGateway->create($form->getValues());
         $product->save();
         $productId = $this->_request->getParam('product_id');
         $flashMessenger = $this->_helper->getHelper('FlashMessenger');
         $flashMessenger->setNamespace('notifications')->addMessage($this->_request->getParam('product_name') . ' Product Updated');
         if ($this->_request->getParam('close') == 1) {
             $return['redirect']['location'] = '/admin/products/';
         } else {
             $return['redirect']['location'] = '/admin/products/modify/' . $productId;
         }
     }
     $this->_helper->json->sendJson($return);
 }