从技术上讲,这是发送给发件人的 magento 联系表单电子邮件的更改“发件人”字段的副本,但我在这里给出了完整而彻底的答案。一个简单的核心破解是那里提供的一个答案。
我决心不破解核心文件,所以我通过制作自定义控制器解决了这个问题。我读了一遍,这似乎很容易......而且市场上没有任何扩展可以提供我设定要实现的目标:1)在发件人上有客户电子邮件和姓名;2) 用于反垃圾邮件的简单人工输入;3) 几个自定义字段,其中 3 个实际上是产品属性。
完成此操作的文件是:
$ find -type f
./Cycleworks/Cycleworks_ContactExtended.xml
./Cycleworks/ContactExtended/controllers/IndexController.php
./Cycleworks/ContactExtended/Helper/Data.php
./Cycleworks/ContactExtended/etc/config.xml
现在对于文件本身... 第一个 XML 文件告诉 Magento 您的自定义覆盖。
// copy this to app/etc/modules/
./Cycleworks/Cycleworks_ContactExtended.xml
<?xml version="1.0"?>
<config>
<modules>
<Cycleworks_ContactExtended>
<active>true</active>
<codePool>local</codePool>
</Cycleworks_ContactExtended>
</modules>
</config>
其余文件进入app/code/local/
. 下面,我从原始控制器中复制了该postAction()
功能,然后在顶部添加了我的代码,然后在->sendTransactional()
./Cycleworks/ContactExtended/controllers/IndexController.php
<?php
require_once 'Mage/Contacts/controllers/IndexController.php';
class Cycleworks_ContactExtended_IndexController extends Mage_Contacts_IndexController
{
public function postAction()
{
$post = $this->getRequest()->getPost();
if ( $post ) {
if( stripos( $post["people"],"tires") ===FALSE ){
Mage::getSingleton('customer/session')->addError("Please correctly answer the question to confirm you are human.<br>\"".$this->getRequest()->getPost("people")."\" is not correct.");
$this->_redirect('*/*/');
return;
}
$extras=Array( "bike_year","bike_make","bike_model","bike_model_ext" );
foreach($extras as $field) {
if( $post[$field] == "empty" )
$post[$field]= "----";
}
$comment = $post['comment']."\nMage::getStoreConfig(self::XML_PATH_EMAIL_SENDER)=\n'".Mage::getStoreConfig(self::XML_PATH_EMAIL_SENDER)."'";
$post['comment']= nl2br($comment);
$translate = Mage::getSingleton('core/translate');
/* @var $translate Mage_Core_Model_Translate */
$translate->setTranslateInline(false);
try {
...
...
...
$mailTemplate->setDesignConfig(array('area' => 'frontend'))
->setReplyTo($post['email'])
->sendTransactional(
Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE),
array( 'name'=>$post['name'],'email'=> $post['email'] ), // Mage::getStoreConfig(self::XML_PATH_EMAIL_SENDER), //
Mage::getStoreConfig(self::XML_PATH_EMAIL_RECIPIENT),
null,
array('data' => $postObject)
);
...
...
...
}
}
漂亮的空壳。是的,这些都有开始<?php
标签但没有结束标签?
./Cycleworks/ContactExtended/Helper/Data.php
<?php
class Cycleworks_ContactExtended_Helper_Data extends Mage_Core_Helper_Abstract
{
}
以及自定义模块中的 XML:
./Cycleworks/ContactExtended/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Cycleworks_ContactExtended>
<version>0.0.01</version>
</Cycleworks_ContactExtended>
</modules>
<frontend>
<routers>
<contacts>
<args>
<modules>
<Cycleworks_ContactExtended before="Mage_Contacts">Cycleworks_ContactExtended</Cycleworks_ContactExtended>
</modules>
</args>
</contacts>
</routers>
</frontend>
<global>
<helpers>
<contactextended>
<class>Cycleworks_ContactExtended_Helper</class>
</contactextended>
</helpers>
</global>
</config>
这就是所有的后端。至于表单本身,我将此代码添加到 form.phtml 的注释块下方和结束</ul>
标记上方。对于大多数人来说,此文件位于app/code/design/frontend/default/default/template/contacts
. 因为我有一个购买的 TM 模板,所以我的在default/a034/template/contacts
<?php
$confirm_people_question="Motorcycles have two of these and rhymes with plires"; // CKCK form anti-spam
?>
<li>
<label for="people" class="required"><em>*</em><?php echo $confirm_people_question ?></label>
<div class="input-box">
<input name="people" id="people" title="Please confirm you are people" value="" class="required-entry input-text" type="text" />
</div>
</li>
<?php
// from http://www.sharpdotinc.com/mdost/2009/04/06/magento-getting-product-attributes-values-and-labels/
$wanted=Array("make","model","engine_size"); // note that each attribute needs to be searchable
$attributes = Mage::getModel('catalogsearch/advanced')->getAttributes(); // $productAttrs = Mage::getResourceModel('catalog/product_attribute_collection');
$attributeArray=array();
foreach($attributes as $a){
if( in_array( $a->getAttributeCode(), $wanted) ){
foreach($a->getSource()->getAllOptions(false) as $option){
$attributeArray[$a->getAttributeCode()][$option['value']] = $option['label'];
}
}
}
?>
<li>
<div class="ymm">
<label for="bike_year">Year</label><br>
<select id="year" name="bike_year">
<option value="empty"></option>
<? for( $idx=date("Y"); $idx >= 1985; $idx-- )
echo " <option value=\"$idx\">$idx</option>\n";
?>
</select>
</div>
<div class="ymm">
<label for="bike_make">Make</label><br>
<select id="make" name="bike_make">
<option value="empty"></option>
<? foreach( $attributeArray['make'] as $id => $brand )
echo " <option value=\"$brand\">$brand</option>\n";
?>
</select>
</div>
<div class="ymm">
<label for="bike_model">Model</label><br>
<select id="model" name="bike_model">
<option value="empty"></option>
<? foreach( $attributeArray['model'] as $id => $model )
echo " <option value=\"$model\">$model</option>\n";
?>
</select>
</div>
<div class="ymm">
<label for="bike_model_ext">More</label>
<div class="input-box">
<input type="text" size="15" value="" id="model_ext" name="bike_model_ext" class="input-text">
</div>
</div>
</li>
我差点忘了,最后一个解谜的关键是管理区的邮件模板:System - Transactional Emails
. 找到您的 HTML 联系人模板(或创建一个新模板,不要将其转换为纯文本),这就是我所拥有的:
<body style="background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;">
<div style="background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;">
<table>
<tr><td>Name</td><td>{{var data.name}}</td></tr>
<tr><td>E-mail</td><td>{{var data.email}}</td></tr>
<tr><td>Telephone</td><td>{{var data.telephone}}</td></tr>
</table>
<P>
<fieldset><legend>Subject: {{var data.subject}}</legend>
{{var data.comment}}
</fieldset>
Bike info: {{var data.bike_year}} {{var data.bike_make}} {{var data.bike_model}} {{var data.bike_model_ext}}
</div>
</body>
我从没想过我会制作自己的自定义模块,但我按照我在这里和其他地方找到的食谱把它放在一起。当验证码失败时,它也会正确运行。我确实尝试研究如何通过他们自己的联系人向客户提供 CC 选项,但我找不到任何东西。
后来,我尝试制作一个自定义模块,以允许新订单的备用管理员通知电子邮件模板,但我从上面学到的知识还不够。:P 所以我对 Magento 的了解和舒适度可能高于“危险黑客”,但我还有很长的路要走。