public function saveAction() { $session = Mage::getSingleton('adminhtml/session'); if ($dataRequested = $this->getRequest()->getPost()) { $data = $dataRequested; $id = $this->getRequest()->getParam('id'); try { $data['question_store_ids'] = implode(',', $data['question_store_ids']); $locale = Mage::app()->getLocale(); $model = Mage::getModel('productquestions/productquestions')->setData($data)->setQuestionDate($locale->date($data['question_date'], $locale->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT), null, false)->addTime(substr($data['question_datetime'], 10))->toString(Varien_Date::DATETIME_INTERNAL_FORMAT))->setId($id)->save(); if ($this->getRequest()->getParam('sendEmail')) { $model->setQuestionReplyText(AW_Productquestions_Helper_Data::parseURLsIntoLinks($model->getQuestionReplyText())); $storeId = $model->getQuestionStoreId(); $store = Mage::app()->getStore($storeId); $product = Mage::getModel('catalog/product')->setStoreId($storeId)->load($model->getQuestionProductId()); $mailTemplate = Mage::getModel('core/email_template'); try { $mailTemplate->setReplyTo(Mage::getStoreConfig(AW_Productquestions_Model_Source_Config_Path::EMAIL_SENDER, $storeId)); } catch (Exception $ex) { } $mailTemplate->setDesignConfig(array('area' => 'frontend', 'store' => $store))->sendTransactional(Mage::getStoreConfig(AW_Productquestions_Model_Source_Config_Path::EMAIL_CUSTOMER_TEMPLATE, $storeId), Mage::getStoreConfig(AW_Productquestions_Model_Source_Config_Path::EMAIL_SENDER, $storeId), $model->getQuestionAuthorEmail(), null, array('data' => $model, 'question_text' => $model->getQuestionText(), 'reply_text' => $model->getQuestionReplyText(), 'customer_name' => $model->getQuestionAuthorName(), 'customer_email' => $model->getQuestionAuthorEmail(), 'date_asked' => Mage::app()->getLocale()->date($model->getQuestionDate(), Varien_Date::DATETIME_INTERNAL_FORMAT)->toString(Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM)), 'product' => $product, 'product_name' => $product->getName(), 'product_url' => $product->getProductUrl(), 'store' => $store, 'store_url' => $store->getUrl(), 'customer' => Mage::getModel('customer/customer')->setWebsiteId($store->getWebsiteId())->loadByEmail($model->getQuestionAuthorEmail())), $storeId); if (!$mailTemplate->getSentSuccess()) { throw new Exception('Message was successfull saved, but the email was not sent'); } else { $session->addSuccess($this->__('Email was sent successfully')); } } $session->addSuccess($this->__('Question was successfully saved')); $session->setProductquestionsData(false); if ($this->getRequest()->getParam('back', false)) { $this->_redirectReferer(); } else { $this->_redirect('*/*/'); } return; } catch (Exception $e) { $session->addError($e->getMessage()); Mage::logException($e); $session->setProductquestionsData($dataRequested); $this->_redirectReferer(); return; } } $session->addError($this->__('Unable to find a data to save')); $this->_redirect('*/*/'); }