共计 2627 个字符,预计需要花费 7 分钟才能阅读完成。
1.修改config.xml
<always_for>
<user_create>1</user_create>
<review_create>1</review_create>
<user_forgotpassword>1</user_forgotpassword>
<guest_checkout>1</guest_checkout>
<register_during_checkout>1</register_during_checkout>
</always_for>
<controller_action_predispatch_review_product_post>
<observers>
<captcha>
<class>captcha/observer</class>
<method>checkReviewPost</method>
</captcha>
</observers>
</controller_action_predispatch_review_product_post>
<frontend>
<areas>
<user_create>
<label>Create user</label>
</user_create>
<review_create>
<label>Create review</label>
</review_create>
<user_login>
<label>Login</label>
</user_login>
<user_forgotpassword>
<label>Forgot password</label>
</user_forgotpassword>
<guest_checkout>
<label>Checkout as Guest</label>
</guest_checkout>
<register_during_checkout>
<label>Register during Checkout</label>
</register_during_checkout>
</areas>
</frontend>
2.captcha.xml
<catalog_product_view translate=”label”>
<reference name=”product.review.form”>
<block type=”core/text_list” name=”form.additional.info”>
<block type=”captcha/captcha” name=”captcha”>
<reference name=”head”>
<action method=”addJs”><file>mage/captcha.js</file></action>
</reference>
<action method=”setFormId”><formId>review_create</formId></action>
<action method=”setImgWidth”><width>230</width></action>
<action method=”setImgHeight”><width>50</width></action>
</block>
</block>
</reference>
</catalog_product_view>
3.template/review/form.phtml
<?php echo $this->getChildHtml(‘form.additional.info’); ?>
4./app/code/core/Mage/Captcha/Model/Observer.php
public function checkReviewPost($observer)
{
$formId = ‘review_create’;
$captchaModel = Mage::helper(‘captcha’)->getCaptcha($formId);
if ($captchaModel->isRequired()) {
$controller = $observer->getControllerAction();
if (!$captchaModel->isCorrect($this->_getCaptchaString($controller->getRequest(), $formId))) {
Mage::getSingleton(‘core/session’)->addError(Mage::helper(‘captcha’)->__(‘Incorrect CAPTCHA.’));
$refererUrl = $controller->getRequest()->getServer(‘HTTP_REFERER’);
$controller->setFlag(”, Mage_Core_Controller_Varien_Action::FLAG_NO_DISPATCH, true);
$controller->getResponse()->setRedirect($refererUrl);
}
}
return $this;
}
正文完