Magento – How to control layout of custom options in Magento

custom-optionstheme

I have a product with two groups of custom options and I want one group to appear in the "product info column" and the other to appear in the "block after info column".

Currently, on the product page > design tab there is only one option for the layout which controls where all product options display. There is no way to control this individually.

Best Answer

This is not a very elegant solution - but if you must use custom options and you have access / ability to modify the theme I suggest the following:

  • Relocate container1 and container2 in your template - these are called via getChildChildHtml('',true,true) in the base theme

-or-

  • Name the options via a naming convention; e.g. "Region 1 - Option 1", "Region 2 - Option 2", etc.

  • In the template, parse the name of all options and store in two separate arrays to be output later.

For the second option - get a list of options from a product:

$product = Mage::getModel('catalog/product')->load($product_id);
$options = $product->getOptions();

Parse through the options and filter by naming convention:

$region1 = array();
$region2 = array();
foreach($options as $option){
    if($option->getType()!='drop_down'){
       if(stripos($option,'Region 1 - ')!==false){
            $region1[] = array_pop(explode('Region 1 - ', $option));
        } elseif(stripos($option,'Region 1 - ')!==false){
            $region2[] = array_pop(explode('Region 2 - ', $option));
        }
    }
}

Now loop over $region1 and $region2, echoing as you go.

foreach($region1 as $option){
    echo $option;
}
Related Topic