Magento Expert Forum - Improve your Magento experience

Results 1 to 2 of 2

multi-select product attribute issue

  1. #1
    New member
    Join Date
    Sep 2015
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default multi-select product attribute issue

    Hi,

    I have some problem with multi-select list, I just want to get ONLY selected values from admin panel ( product attributes multi-select list ), the example output is on this URL -> http://frakta.he-hosting.de/silence-4-nm-60.html

    This is Product attribute multi-select code from Magento admin panel:

    HTML Code:
    <select>
    <option selected="selected" value="17">230V</option>
    <option selected="selected" value="18">24VAC</option>
    <option value="20">24VAC/DC</option>
    <option value="19">24VDC</option>
    </select>
    Here is also my code from view.phtml file (product view):

    Code:
    function getSelectAttributeValues($attrCode)  {
    $attributeCode = $attrCode;
    
      
    // build and filter the product collection
    $products = Mage::getResourceModel('catalog/product_collection') 
    ->addAttributeToFilter($attributeCode, array('notnull' => true))
    ->addAttributeToFilter($attributeCode, array('neq' => ''))
    ->addAttributeToSelect($attributeCode);
    
    // ### it returns all values from multi-select list, but it should return only selected
    $usedAttributeValues = array_unique($products->getColumnValues($attributeCode));
    
    // fetch the attribute model
    $attributeModel = Mage::getSingleton('eav/config')->getAttribute('catalog_product', $attributeCode);
    
    // map the option id's to option labels
    $usedAttributeValues = $attributeModel->getSource()->getOptionText(
    implode(',', $usedAttributeValues)
    								);     
    
    
    if (is_array($usedAttributeValues)) {
    return implode(', ', $usedAttributeValues);
    } else { 
    return $usedAttributeValues;
    }						
    }
    Please help me, I'll be gratefull for any advice Smiley Happy

    View more threads in the same category:


  2. #2
    Junior Member
    Join Date
    Sep 2018
    Location
    United Kingdom
    Posts
    143
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Magento 2: Multiple Select Product Attribute issue by removing all values Alternative would be to create "Select" as Option & assign.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •