Magento:前端的自定义客户属性

时间:2015-04-19 07:06:46

标签: magento magento-1.8

我创建了一个客户属性,它运行正常。我可以在后端看到属性,并可以从后端选择值。不幸的是,属性值在前端不可见。请在下面找到我在sql文件中添加的代码。

$installer = $this;
$installer->startSetup();
$setup = Mage::getModel('customer/entity_setup', 'core_setup');


$setup->addAttribute('customer', 'customer_type', array(
    'label' => 'Customer Type',
    'input' => 'select',
    'type'  => 'int',
    'required' => 0,
    'user_defined' => 1,
    'visible'  => true,

    'source'=> 'mymodule/entity_customertype'
));



    Mage::getSingleton('eav/config')
    ->getAttribute('customer', 'customer_type')
    ->setData('used_in_forms', array('adminhtml_customer','customer_account_create','customer_account_edit','checkout_register'))

    ->save();



$installer->endSetup();

如何在前端的“产品详情”页面上显示属性值?

1 个答案:

答案 0 :(得分:0)

add a new template to your PDP很容易,就像这样:

布局

<catalog_product_view>
    <reference name="content">
        <reference name="product.info">
            <block type="core/template" name="other" template="catalog/product/customer_type.phtml"/>
        </reference>
    </reference>
</catalog_product_view>

然后使用模板从the currently logged-in user显示您的客户属性,如下所示:

模板

<?php if (Mage::getSingleton('customer/session')->isLoggedIn()): ?>
    <?php $_customer = Mage::getSingleton('customer/session')->getCustomer() ?>
    <?php if ($_type = $_customer->getCustomerType()): ?>
    <dl class="customer-type">
        <dt><?php echo $this->__('Customer Type') ?></dt>
        <dd><?php echo $_type ?></dd>
    </dl>
    <?php endif ?>
<?php endif ?>