Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Value from Multiple Select on Frontend
 
theallgreenstore
Member
 
Total Posts:  33
Joined:  2009-01-08
 

I need to be able to select a specific value of a multiple select attribute and display it.  Right now I display all of the selected values, but I need each individual value to link to a tooltip.  Does anyone know how to call each value of a multiple select individually?

 
Magento Community Magento Community
Magento Community
Magento Community
 
cclohman
Sr. Member
 
Avatar
Total Posts:  82
Joined:  2008-06-16
Los Angeles
 

I don’t know how you would call each item individually, but I don’t think that you need to do that to accomplish your goal.  I had a similar issue using a “features” multi-select attribute on my products.  Selecting features from the multi-select in the admin would turn on/off icons to display on the product view page. 

Here’s what I did in app/design/frontend/default/dxg(my theme)/template/catalog/product/view.phtml:

$icons = array(
    
'13'=>'video_cam_icon.jpg',
    
'9'=>'voice_recorder_icon.jpg',
    
'12'=>'pc_camera_icon.jpg',
    
'15'=>'mass_storage_icon.jpg',
    
'8'=>'hdmi_icon.jpg',
    
'11'=>'hd_video_camera_icon.jpg',
    
'16'=>'direct_print_icon.jpg',
    
'10'=>'digital_still_camera_icon.jpg',
    
'19'=>'5mp_icon.jpg',
    
'17'=>'3.0_tft_icon.jpg',
    
'14'=>'2.5_tft_icon.jpg',
    
'18'=>'2.4_tft_icon.jpg'
);

$feature_ids explode(','$this->getProduct()->getFeatures()); 
if(
count($feature_ids))
{
    $_product 
$this->getProduct();
    
$feature_names explode(','$_product->getResource()->getAttribute('features')->getFrontend()->getValue($_product));
    
$features array_combine($feature_ids$feature_names);
?>
<div class="icon-container">
<?php foreach($feature_ids as $id): ?>
        
<div class="icon-item"><img src="<?php echo $this->getSkinUrl('images/dxg/'.$icons[$id]) ?>" alt="<?php echo htmlentities(trim($features[$id]))?>" title="<?php echo htmlentities(trim($features[$id]))?>"></div>
<?php endforeach; ?>
</div>
<?php
}
// endif count
?>

The first call to $this->getProduct()->getFeatures() returns a comma separated list of numbers that are the value ids in the db of the selected items in my admin multi select.  The call to $_product->getResource()->getAttribute("features")->getFrontend()->getValue($_product) returns a comma separated list of the corresponding names of those value ids.  Using explode and then array combine will give you an array of ids and values that you can loop through and apply your display logic.

The alt and title tags give my icons the tooltips when you mouse over.  Hope that helps you out.

Cheers,
Chris

 
Magento Community Magento Community
Magento Community
Magento Community
 
CT Schubert
Sr. Member
 
Avatar
Total Posts:  197
Joined:  2008-10-08
Southern California
 

Oh wow!! That worked BEAUTIFULLY for me.

Now I can display eco-friendly icons and explanations for each in it’s own tab on each product page. Saved me a lot of trouble, thanks!

I basically followed the instructions on this thread:
http://www.magentocommerce.com/boards/viewthread/19498/

And instead of using the code for the new tab .phtml page on that thread I used the code above, swapping out for my attribute code and it works like a charm.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Jbyun76
Jr. Member
 
Total Posts:  1
Joined:  2009-08-28
 

asdf

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top