Magento - 使该字段成为“公司”必需的

发布于 2024-10-27 09:31:43 字数 81 浏览 1 评论 0原文

对于 B2B Magento 网站,在注册新客户时,我想将“公司”字段设置为必填字段。

我应该编辑哪个文件?

多谢。

for a B2B Magento site, when registering a new client, I want to make the field "company" required.

Which file should I edit?

Thanks a lot.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

余厌 2024-11-03 09:31:43

您还应该将其添加到服务器端的属性中。

如果您使用 Magento 企业版,您只需通过后端编辑公司属性,然后将其设置为“必需”

如果您使用的是社区版,则必须使用 SQL 手动更改此值。它位于eav_attribute表中,attribute_codecompany,您只需将is_required设置为1< /代码>。

You should as well add it in your attribute on the server side.

If you're using Magento Entreprise Edition, you can simply edit the company attribute through back end, and set it to "required".

If you're working with a Community Edition, you'll have to manually change this value with SQL. It's in eav_attribute table, the attribute_code is company and you just need to set is_required to 1.

悟红尘 2024-11-03 09:31:43

除了 Haltabush 答案(这是正确的答案)之外,这里还有针对懒惰开发人员的 SQL:

UPDATE eav_attribute SET is_required = 1 WHERE attribute_code = 'company';

Additionally to haltabush answer (which is the correct one) here is the SQL for lazy developers:

UPDATE eav_attribute SET is_required = 1 WHERE attribute_code = 'company';
阳光的暖冬 2024-11-03 09:31:43

对于客户地址簿部分(注册客户):

/app/design/frontend/base/default/template/customer/address/edit.phtml

对于结帐账单部分:

/app/design/frontend/base/default/template/checkout/onepage/billing.phtml

对于结帐运输部分:

/app/design/frontend/base/default/template/checkout/onepage/shipping.phtml

注册部分:

/app/design/frontend/base/default/template/customer/form/register.phtml

/app/design/frontend/base/default/template/customer/form/address.phtml

对于必填字段,查找类似于以下行:

class="input-text validate-email required-entry"

For Customer Address Book Section (registered customers ) :

/app/design/frontend/base/default/template/customer/address/edit.phtml

For checkout billing section :

/app/design/frontend/base/default/template/checkout/onepage/billing.phtml

For checkout shipping section :

/app/design/frontend/base/default/template/checkout/onepage/shipping.phtml

For registration section :

/app/design/frontend/base/default/template/customer/form/register.phtml

/app/design/frontend/base/default/template/customer/form/address.phtml

Find looks like following line for required fields :

class="input-text validate-email required-entry"
农村范ル 2024-11-03 09:31:43

这是使用安装程序执行此操作的方法。在 magento 中执行此操作的正确方法。这适用于企业版和社区版。但是您必须配置模块才能理解 sql 文件夹下的文件

<?php
    $installer = new Mage_Customer_Model_Entity_Setup('core_setup');;

    $installer->startSetup();


    $installer->run("UPDATE eav_attribute SET is_required = 1 WHERE attribute_code = 'company';");


    $installer->endSetup();

这就是我的模块 xml 文件的样子。

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Package_Customer>
            <version>1.1.0.4</version>
        </Package_Customer>
    </modules>
    <global>
      ....
       <resources>
        <package_customer_setup>
            <setup>
                <module>Package_Customer</module>
            </setup>
        </package_customer_setup>
         </resources>
       ....
     </global>

这就是我对 edit.phtml 所做的使其动态化

    <li class="wide">
        <?php 
            $validation_class = $this->helper('customer/address')->getAttributeValidationClass('company') ;
            $required = strstr($validation_class, 'required-entry');
        ?>
        <label for="company" class=<?php echo $required?"required":""?>><?php echo $this->__('Company') ?> <?php echo $required?"<em>*</em>":""?> </label>
        <div class="input-box">
            <input type="text" name="company" id="company" title="<?php echo $this->__('Company') ?>" value="<?php echo $this->escapeHtml($this->getAddress()->getCompany()) ?>" class="input-text <?php echo $validation_class ?>" />
        </div>
    </li>

This is how to do it using installer. The proper way to do it in magento. This works for enterprise edition and comunity edition. But you will have to have the module configured to understand a file under sql folder

<?php
    $installer = new Mage_Customer_Model_Entity_Setup('core_setup');;

    $installer->startSetup();


    $installer->run("UPDATE eav_attribute SET is_required = 1 WHERE attribute_code = 'company';");


    $installer->endSetup();

This is how is my module xml file looks like.

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Package_Customer>
            <version>1.1.0.4</version>
        </Package_Customer>
    </modules>
    <global>
      ....
       <resources>
        <package_customer_setup>
            <setup>
                <module>Package_Customer</module>
            </setup>
        </package_customer_setup>
         </resources>
       ....
     </global>

This is what I did to edit.phtml to make it dynamic

    <li class="wide">
        <?php 
            $validation_class = $this->helper('customer/address')->getAttributeValidationClass('company') ;
            $required = strstr($validation_class, 'required-entry');
        ?>
        <label for="company" class=<?php echo $required?"required":""?>><?php echo $this->__('Company') ?> <?php echo $required?"<em>*</em>":""?> </label>
        <div class="input-box">
            <input type="text" name="company" id="company" title="<?php echo $this->__('Company') ?>" value="<?php echo $this->escapeHtml($this->getAddress()->getCompany()) ?>" class="input-text <?php echo $validation_class ?>" />
        </div>
    </li>
゛时过境迁 2024-11-03 09:31:43

您可以设置后端设置(版本 2.4.5-p1)。

您可以在 Stores > 中找到它设置>配置,然后在客户>下客户配置您将在“名称和地址选项”选项卡下找到“显示公司”选项。

它看起来像这样:

在此处输入图像描述

将该选项设置为必填将使公司成为所有地址表单中的必填字段。

There is a backend setting you can set (version 2.4.5-p1).

You can find it in Stores > Settings > Configuration, then under Customers > Customer Configuration you will find the option "Show Company" under the tab "Name and Address Options".

It looks like this:

enter image description here

Setting the option to required will make the company a required field in all address forms.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文