2
votes

I created a customer attribute and it works fine. I can see the attribute on backend and can select the values from backend. Unfortunately, the attribute value is not visible on frontend. Please find my code below which is added in sql file.

$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();

How can I make the attribute value visible on Product Detail page on frontend?

1
I am a bit confused you want a customer attribute to show on the product detail page? - dmanners

1 Answers

0
votes

It’s easy enough to add a new template to your PDP, like this:

Layout

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

Then use the template to display your customer attribute from the currently logged-in user with something like this:

Template

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