Magento Forum

   
Displaying custom options in the catogory list
 
majacore
Member
 
Avatar
Total Posts:  53
Joined:  2008-12-29
 

Hello,

I am trying to display the user entered custom options from with in catalog/product/list.phtml and just cant seem to get too them.

here is a sample of my code

<?php $_productCollection=$this->getLoadedProductCollection() ?>
<?php 
if(!$_productCollection->count()): ?>
  
<div class="padder"> <div class="note-msg"<?php echo $this->__('There are no products matching the selection.'?> </div> </div>
<?php else: ?>
  <?php $i
=0$_collectionSize $_productCollection->count() ?>
  <?php 
foreach ($_productCollection as $_product): ?>
      <?php
      
if((int)$_product->has_options)
      
{
      var_dump
($_product->getData());
      
}
      ?>
  <?php 
endforeach ?>

<?php 
endif; ?>

I am quite able to access “has_options” and this returns 1 when there are options preset but there is nothing in the object to indicate what the options are or how to access them here is the output for the apropriate sections

["has_options"]=>          string(1"1"
["_customOptions:protected"]=> array(0{        }
[
"_options:protected"]=>     array(0{       }

I have tried accessing other objects that i can think of but to no avail.

please help me i am already bald so i don’t know what to pull out

 
Magento Community Magento Community
Magento Community
Magento Community
 
majacore
Member
 
Avatar
Total Posts:  53
Joined:  2008-12-29
 

an update
I have found all the data i need by accessing this object

Mage::getModel('Catalog/Product_Option')->getProductOptionCollection($_product);
but i can’t get the right bits out :(

 
Magento Community Magento Community
Magento Community
Magento Community
 
majacore
Member
 
Avatar
Total Posts:  53
Joined:  2008-12-29
 

well after much fafing and huffing i got something working, can any one see anything wrong with it ?

<?php
      
if((int)$_product->has_options)
      

        $optionsData 
Mage::getModel('Catalog/Product_Option')->getProductOptionCollection($_product)->getData('_items');
        
/* useful just now echo .$optionsData[0]['product_id'].$optionsData[0]['type'].; */

        
echo $optionsData[0]['title'].'<select id="'.$optionsData[0]['option_id'].'">';
        
$_options =  Mage::getModel('Catalog/Product_Option')->getProductOptionCollection($_product)->load();
        foreach(
$_options as $key => $val)
        

          
foreach($val->getValues() as $k => $v )
          
{
          $optionData 
$v->getData();
          echo 
'<option value="'.$optionData["option_id"].'">'.$optionData["title"].'</option>';

          
}
        }
        
echo ' </select> ';
      
}

 
Magento Community Magento Community
Magento Community
Magento Community
 
majacore
Member
 
Avatar
Total Posts:  53
Joined:  2008-12-29
 

for any one interested this isn’t the way and has created all kind of problems

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