在Mage_Customer中,<fieldsets>有什么作用?</fieldsets>

时间:2014-10-17 14:52:24

标签: magento

我很好奇<customer_account>中的<fieldsets>标记是否有任何角色,或者是否在旧版本的Magento中使用过。我可以看到,在创建客户时,使用customer_form_attribute$customerData = $customerForm->extractData($this->getRequest());

$customerForm->compactData($customerData);表格将属性添加到客户模型中

我知道在使用其他模块时,但对于客户我无法发现它的实用性。

1 个答案:

答案 0 :(得分:0)

通常<fieldsets>是非常有用的copyFieldset函数的一部分。我发现自己几乎每天都和他们一起工作。

具体来说,在Mage_Customer_Model_Resource_Customer_Collection中有这个功能:

/**
 * Add Name to select
 *
 * @return Mage_Customer_Model_Resource_Customer_Collection
 */
public function addNameToSelect()
{
    $fields = array();
    $customerAccount = Mage::getConfig()->getFieldset('customer_account');
    foreach ($customerAccount as $code => $node) {
        if ($node->is('name')) {
            $fields[$code] = $code;
        }
    }

    $adapter = $this->getConnection();
    $concatenate = array();
    if (isset($fields['prefix'])) {
        $concatenate[] = $adapter->getCheckSql(
            '{{prefix}} IS NOT NULL AND {{prefix}} != \'\'',
            $adapter->getConcatSql(array('LTRIM(RTRIM({{prefix}}))', '\' \'')),
            '\'\'');
    }
    $concatenate[] = 'LTRIM(RTRIM({{firstname}}))';
    $concatenate[] = '\' \'';
    if (isset($fields['middlename'])) {
        $concatenate[] = $adapter->getCheckSql(
            '{{middlename}} IS NOT NULL AND {{middlename}} != \'\'',
            $adapter->getConcatSql(array('LTRIM(RTRIM({{middlename}}))', '\' \'')),
            '\'\'');
    }
    $concatenate[] = 'LTRIM(RTRIM({{lastname}}))';
    if (isset($fields['suffix'])) {
        $concatenate[] = $adapter
                ->getCheckSql('{{suffix}} IS NOT NULL AND {{suffix}} != \'\'',
            $adapter->getConcatSql(array('\' \'', 'LTRIM(RTRIM({{suffix}}))')),
            '\'\'');
    }

    $nameExpr = $adapter->getConcatSql($concatenate);

    $this->addExpressionAttributeToSelect('name', $nameExpr, $fields);

    return $this;
}

其第一部分基本上与此XML匹配:

<global>
    <fieldsets>
        <customer_account>
            <prefix>
                <create>1</create>
                <update>1</update>
                <name>1</name>
            </prefix>
            <firstname>
                <create>1</create>
                <update>1</update>
                <name>1</name>
            </firstname>
            <middlename>
                <create>1</create>
                <update>1</update>
                <name>1</name>
            </middlename>
            <lastname>
                <create>1</create>
                <update>1</update>
                <name>1</name>
            </lastname>
            <suffix>
                <create>1</create>
                <update>1</update>
                <name>1</name>
            </suffix>
        </customer_account>
    </fieldsets>
</global>

...所以<customer_account>标记的确切作用是指定连接客户名时要加载的属性。