Add custom fields in review form

那年仲夏 提交于 2019-12-09 01:45:39

问题


I am looking forward to create a custom fields 'Email Id' & One drop-down in Review form .

I have tried this one but not saving the data, its hows the fields only

app\code\core\Mage\Review\Model\Mysql4\Review.php

protected function _afterSave(Mage_Core_Model_Abstract $object)
{
$detail = array(
'title' => $object->getTitle(),
'detail' => $object->getDetail(),
'nickname' => $object->getNickname(),
'email' => $object->getEmail(), // New field 1
'fname' => $object->getFname(), // New field 2
);

Now add email,fname in the review_detail table in the database also go to app\code\core\Mage\Adminhtml\Block\Review\Edit\Form.php also add :

$fieldset->addField('fname', 'text', array( // New field 2
'label' => Mage::helper('review')->__('First Name'),
'required' => true,
'name' => 'fname'
));

$fieldset->addField('email', 'text', array( // New field 1
'label' => Mage::helper('review')->__('Email'),
'required' => true,
'name' => 'email'
));

before to

$fieldset->addField('nickname', 'text', array(
'label' => Mage::helper('review')->__('Nickname'),
'required' => true,
'name' => 'nickname'
));

回答1:


Modify the Mage core class is a bit scary, which will be difficult to upgrade magento core class in the future. You can override the specific class by your own custom module (See module creator if you want to setup one)

Module's config.xml, add the models rewrite in as below:

<global>
    <models>
        <review_mysql4>
            <rewrite>
                <review>[[Your Company]]_[[Your Module]]_Model_Review</review>
            </rewrite>
        </review_mysql4>
    </models>
    ...
</global>

And the specified class will extend from the Magento core class you want to override:

class [[Your Company]]_[[Your Module]]_Model_Review
    extends Mage_Review_Model_Mysql4_Review
{
    protected function _afterSave(Mage_Core_Model_Abstract $object)
    {
     .... 
    }
}

Ps. to add the new field in magento review_detail table:

$installer = $this;
$installer->startSetup();
$installer->run("ALTER TABLE review_detail ADD COLUMN email VARCHAR(255) NULL");
$installer->endSetup();



回答2:


Finally i have solved it... Open app\code\core\Mage\Review\Model\Resource\Review.php

you will find this code in line about 150

protected function _afterSave(Mage_Core_Model_Abstract $object)
{
$detail = array(
'title' => $object->getTitle(),
'detail' => $object->getDetail(),
'nickname' => $object->getNickname(),
);

Add the new two fields you want to add.

protected function _afterSave(Mage_Core_Model_Abstract $object)
{
$detail = array(
'title' => $object->getTitle(),
'detail' => $object->getDetail(),
'nickname' => $object->getNickname(),
'email' => $object->getEmail(), // New field 1
'fname' => $object->getFname(), // New field 2
);

Thats it no more.... :) Happy coding



来源:https://stackoverflow.com/questions/10084144/add-custom-fields-in-review-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!