如何删除评论字段(昵称,评论摘要和评论)所必需的必填项 [英] How can i remove mandatory required for the review fields (nickname, summary of your review and review)

查看:95
本文介绍了如何删除评论字段(昵称,评论摘要和评论)所必需的必填项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Magento中删除评论字段(昵称,评论摘要和评论)所必需的必填项.我找到了一个答案,但这仅适用于管理面板: Magento管理员添加/编辑审核-> ;删除审核字段摘要"所需的验证 想要在商店视图中将其删除,以便客户只需点击评分并将其发送即可.

how can in Magento remove mandatory required for the review fields (nickname, summary of your review and review). I found one answer but it is just for admin panel: Magento Admin Add/Edit Review -> removing Summary of Review Field required validation Would like to remove it in store view, so that customers can just click on rating and send it.

Thx

推荐答案

(我正在使用Magento2)

(I'm using Magento2)

必须更改两个位置代码:

Two places code must be changed:

/var/www/magento2/app/code/Magento/Review/Model/Review.php
打开此文件后,请节省一些时间,然后按ctrl + F并输入短语validate.应该带你到这里...

/var/www/magento2/app/code/Magento/Review/Model/Review.php
As soon as you open this file, save yourself some time and hit ctrl+F and type the phrase validate. Should take you here...

public function validate()
    {
    $errors = [];

    // if (!\Zend_Validate::is($this->getTitle(), 'NotEmpty')) {
    //     $errors[] = __('Please enter a review summary.');
    // }

    if (!\Zend_Validate::is($this->getNickname(), 'NotEmpty')) {
        $errors[] = __('Please enter a nickname.');
    }

    // if (!\Zend_Validate::is($this->getDetail(), 'NotEmpty')) {
    //     $errors[] = __('Please enter a review.');
    // }

    if (empty($errors)) {
        return true;
    }
    return $errors;
}   

您可能会注意到3条陈述中有2条被注释掉了.我这样做是为了删除仅进行摘要和审阅的要求.我想将昵称"保留为必填字段,以免被注释掉.

You may notice that 2 of the 3 if statements are commented out. I did this in order to remove the requirement for only summary and review. I wanted to keep Nickname as a required field so that isn't commented out.

接下来,您需要将此文件从默认的Magento Review目录复制到本地主题目录...

Next you need to copy this file from the default Magento Review directory into your local theme directory...

/var/www/magento2/app/code/Magento/Review/view/frontend/templates/form.phtml

/var/www/magento2/app/code/Magento/Review/view/frontend/templates/form.phtml

确保从Review模块获取form.phtml.其他模块中还有其他几个form.phtml文件.

Make sure to get the form.phtml from the Review module. There are several other form.phtml files in other modules as well.

将文件复制到的位置的示例:
/var/www/magento2/app/design/frontend/Danny/orange/Magento_Review/templates/form.phtml

An example of where to copy the file to:
/var/www/magento2/app/design/frontend/Danny/orange/Magento_Review/templates/form.phtml

将其复制到自己的本地目录后,即可继续进行更改:

Once you have copied this into your own local directory, you can proceed to make the changes :

<div class="field review-field-nickname required">
        <label for="nickname_field" class="label"><span><?php echo $block->escapeHtml(__('Nickname')) ?></span></label>
        <div class="control">
            <input type="text" name="nickname" id="nickname_field" class="input-text" data-validate="{required:true}" data-bind="value: nickname()" />
        </div>
    </div>
    <div class="field review-field-summary">
        <label for="summary_field" class="label"><span><?php echo $block->escapeHtml(__('Summary')) ?></span></label>
        <div class="control">
            <input type="text" name="title" id="summary_field" class="input-text" data-validate="{required:false}" data-bind="value: review().title" />
        </div>
    </div>
    <div class="field review-field-text">
        <label for="review_field" class="label"><span><?php echo $block->escapeHtml(__('Review')) ?></span></label>
        <div class="control">
            <textarea name="detail" id="review_field" cols="5" rows="3" data-validate="{required:false}" data-bind="value: review().detail"></textarea>
        </div>
    </div>

在上面的代码片段中,您将注意到第一个块"Nickname"保持原样.需求保留在那里.

In the above code snippet you will notice that the first block "Nickname" has been left as-is. The requirement is kept there.

对其他两个框进行了修改,以删除要求.我唯一要做的更改是删除"required"类,并将data-validate ="{required:false}"从true更改为false.

The other two boxes have been modified to remove the requirement. The only changes I had to make were to remove the "required" class and change data-validate="{required:false}" from true to false.

希望这会有所帮助!

这篇关于如何删除评论字段(昵称,评论摘要和评论)所必需的必填项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆