Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying custom product attributes based on customer group (Magento)

I have wholesale attributes for certain products under one store in Magento. I would like to set it so those particular attributes only appear on the product page IF the customer is logged in and they are in the Wholesale customer group.

Is this possible?

like image 277
f8xmulder Avatar asked Feb 09 '10 22:02

f8xmulder


2 Answers

Something like this should work, although I have not tested this together. It's assuming your wholesale groupid = 2 and that you want to show the product attribute 'productvideos'

app/design/frontend/default//template/catalog/product/view.phtml
    if($_isLoggedIn === true){
      $_myGroupId = Mage::getSingleton('customer/session')->getCustomerGroupId();          
      if($_myGroupId == 2){
        print $_helper->productAttribute($_product, $_product->getProductvideos(), 'productvideos');
      }
    }

Credit: http://www.magentocommerce.com/boards/viewthread/22597/#t74992

like image 56
Shane Stillwell Avatar answered Sep 30 '22 16:09

Shane Stillwell


Okay, here's the solution.

In template/catalog/product/view> attributes.phtml use the following:

<?php       
    $_isLoggedIn = $this->helper('customer')->isLoggedIn();
    if($_isLoggedIn == true){
      $_myGroupId = Mage::getSingleton('customer/session')->getCustomerGroupId();          
      if($_myGroupId == 2){
        echo '<td class="label">Attribute Name/Label</td>';
        echo '<td class="label">';
        if ($_product->getResource()->getAttribute('attribute_id')->getFrontend()->getValue($_product)):
          echo $_product->getResource()->getAttribute('attribute_id')->getFrontend()->getValue($_product);
        endif;
        echo '</td>';
      }
    }
?>

Thanks to @nvoyageur for the initial pointer in the right direction!

like image 44
f8xmulder Avatar answered Sep 30 '22 18:09

f8xmulder