【问题标题】:Magento: Custom customer attribute on frontendMagento:前端的自定义客户属性
【发布时间】:2015-06-25 22:30:04
【问题描述】:

我创建了一个客户属性,它工作正常。我可以在后端看到属性,并且可以从后端选择值。不幸的是,属性值在前端不可见。请在下面找到我在 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();

如何使属性值在前端的产品详细信息页面上可见?

【问题讨论】:

  • 我有点困惑,您希望在产品详细信息页面上显示客户属性吗?

标签: magento magento-1.8


【解决方案1】:

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 ?>

【讨论】:

    猜你喜欢
    • 2023-04-01
    • 2023-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多