0

我有我的自定义模块客户反馈/查询表格,客户可以在其中询问与产品相关的查询,或者他们可以提供与商店相关的反馈。在管理方面,我列出了管理网格中的所有反馈。

现在我想集成邮件功能,比如当我点击特定的反馈编辑部分时,邮件正文会有单独的部分,我将在其中输入回复,点击发送按钮,邮件会发送给特定客户,其中邮件 ID 已经存在那个特定的编辑部分。

这是我的AdminHtml 控制器文件的代码

<?php
class Foo_Bar_Adminhtml_BazController extends Mage_Adminhtml_Controller_Action
  {
public function indexAction()
{
    // Let's call our initAction method which will set some basic params for each action

    $this->_initAction()
    ->renderLayout();
}

public function newAction()
{
    // We just forward the new action to a blank edit form
    $this->_forward('edit');
}

public function editAction()
{
    $this->_initAction();

    // Get id if available
    $id  = $this->getRequest()->getParam('id');
    $model = Mage::getModel('foo_bar/baz');

    if ($id) {
        // Load record
        $model->load($id);

        // Check if record is loaded
        if (!$model->getId()) {
            Mage::getSingleton('adminhtml/session')->addError($this->__('This baz no longer exists.'));
            $this->_redirect('*/*/');

            return;
        }
    }

    $this->_title($model->getId() ? $model->getName() : $this->__('New Baz'));

    $data = Mage::getSingleton('adminhtml/session')->getBazData(true);
    if (!empty($data)) {
        $model->setData($data);
    }

    Mage::register('foo_bar', $model);

    $this->_initAction()
    ->_addBreadcrumb($id ? $this->__('Edit Baz') : $this->__('New Baz'), $id ? $this->__('Edit Baz') : $this->__('New Baz'))
    ->_addContent($this->getLayout()->createBlock('foo_bar/adminhtml_baz_edit')->setData('action', $this->getUrl('*/*/save')))
    ->renderLayout();
}

public function saveAction()
{
    if ($postData = $this->getRequest()->getPost()) {

        $model = Mage::getSingleton('foo_bar/baz');
        $model->setData($postData);

        try {
            $model->save();

            Mage::getSingleton('adminhtml/session')->addSuccess($this->__('The baz has been saved.'));
            $this->_redirect('*/*/');

            return;
        }
        catch (Mage_Core_Exception $e) {
            Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
        }
        catch (Exception $e) {
            Mage::getSingleton('adminhtml/session')->addError($this->__('An error occurred while saving this baz.'));
        }

        Mage::getSingleton('adminhtml/session')->setBazData($postData);
        $this->_redirectReferer();
    }
}
public function deleteAction()
{
    // check if we know what should be deleted
    $itemId = $this->getRequest()->getParam('id');
    if ($itemId) {
        try {
            // init model and delete
            /** @var $model Magentostudy_News_Model_Item */
            $model = Mage::getModel('foo_bar/baz');
            $model->load($itemId);
            if (!$model->getId()) {
                Mage::throwException(Mage::helper('foo_bar')->__('Unable to find a Baz.'));
            }
            $model->delete();

            // display success message
            $this->_getSession()->addSuccess(
                    Mage::helper('foo_bar')->__('The Baz has been deleted.')
            );
        } catch (Mage_Core_Exception $e) {
            $this->_getSession()->addError($e->getMessage());
        } catch (Exception $e) {
            $this->_getSession()->addException($e,
                    Mage::helper('foo_bar')->__('An error occurred while deleting the baz.')
            );
        }
    }

    // go to grid
    $this->_redirect('*/*/');
}
public function messageAction()
{
    $data = Mage::getModel('foo_bar/baz')->load($this->getRequest()->getParam('id'));
    echo $data->getContent();
}

/**
 * Initialize action
 *
 * Here, we set the breadcrumbs and the active menu
 *
 * @return Mage_Adminhtml_Controller_Action
 */
protected function _initAction()
{
    $this->loadLayout()
    // Make the active menu match the menu config nodes (without 'children' inbetween)
    ->_setActiveMenu('sales/foo_bar_baz')
    ->_title($this->__('Sales'))->_title($this->__('Baz'))
    ->_addBreadcrumb($this->__('Sales'), $this->__('Sales'))
    ->_addBreadcrumb($this->__('Baz'), $this->__('Baz'));

    return $this;
}

/**
 * Check currently called action by permissions for current user
 *
 * @return bool
 */
protected function _isAllowed()
{
    return Mage::getSingleton('admin/session')->isAllowed('sales/foo_bar_baz');
}

}

我想要一些挂钩,我可以从中向特定客户发送邮件。这是我的管理网格部分的图像

管理网格图像

4

1 回答 1

0

最简单的方法是创建一个新的事务性邮件并将主题设置为占位符,正文也相同。

这是交易邮件功能:

/**
 * Send transactional email to recipient
 *
 * @param   int $templateId
 * @param   string|array $sender sneder informatio, can be declared as part of config path
 * @param   string $email recipient email
 * @param   string $name recipient name
 * @param   array $vars varianles which can be used in template
 * @param   int|null $storeId
 * @return  Mage_Core_Model_Email_Template
 */
public function sendTransactional($templateId, $sender, $email, $name, $vars=array(), $storeId=null)

所以首先要做的是,在System->Transactional Mails下创建一个新的事务邮件。现在只需用一些随机的东西填充它。然后转到您要发送电子邮件的地方并添加

Mage::getModel('core/email_template')
    ->sendTransactional(
        {the transactional email id we just created}, 
        $sender, 
        $recepientEmail, 
        $recepientName,   
        array(
            'subject' => '{your subject}',
            'body' => '{you body}'
        )
    );

用您输入的字段替换{your subject}和。{your body}

之后,返回您的交易电子邮件模板并用以下内容替换我们的随机内容:在交易邮件{{var subject}}的主题字段和{{var body}}内容字段中输入

我没有尝试过,但它应该可以工作。

希望有帮助

于 2013-10-04T06:48:44.893 回答