1

I need to display my product's custom options in front end, in specific way. For example, I would like tabulate in two columns, drop down fields of my custom options and add some header text on another columns for front end. I considered combination with static block might work but so far. I couldn't find any related information.

Are there any ideas on how I can do this?

2
  • specify your magento version as well. Commented Feb 13, 2017 at 3:17
  • My Magento version is 1.9.2.4
    – Kirkos
    Commented Feb 13, 2017 at 9:41

2 Answers 2

2

You first build html and then you can use the following code to get custom options:

$ProductId=1;
$product = Mage::getModel('catalog/product')->load($ProductId); 
if ( $product->getData('has_options') && ($product->getTypeID() == 'simple') ) {
           foreach ($product->getOptions() as $o) {
              //$o->getOptionId();
              //$o->getTitle();
              //$o->getType();
              //$o->getIsRequire();
              //$o->getType();
              //$o->getValues();

           }
       }
4
  • It is not clear to me where to use this code (which file to modify?). Can you please specify? Also, what do you mean by saying "first build html"? To build a static block?
    – Kirkos
    Commented Feb 13, 2017 at 9:48
  • in any way you have to create a phtml file and then by using layout you can call that phtml file in your product view block. In the phtml file you can use the above code to get custom options. Commented Feb 13, 2017 at 10:22
  • I use already a generic Page Layout (1 column) for all my products. Is it possible to create the html in the Design->Custom Layout Update in order to be included in this page layout for the specific products? Or it is better to create a modified version of 1column.phtml (lets say 1column_custom.phtml) to use it for these products only?
    – Kirkos
    Commented Feb 13, 2017 at 11:06
  • not page layout , you can call phtml file from your layout handle. You can get lots of reference for "how to call phtml file from layout xml" Commented Feb 13, 2017 at 11:13
0

Finally I did the following: In app/design/frontend/base/default/template/catalog/product/view/options.phtml, I replaced this part of code:

<dl>
<?php foreach($_options as $_option): ?>
    <?php echo $this->getOptionHtml($_option) ?>
<?php endforeach; ?>
</dl>

with this one:

<?php $product = $this->getProduct(); ?>
<?php $attributeSetModel = Mage::getModel("eav/entity_attribute_set"); ?>
<?php $attributeSetModel->load($product->getAttributeSetId()); ?>
<?php $attributeSetName  = $attributeSetModel->getAttributeSetName(); ?>
<?php if($attributeSetName === 'My Attribute Set Name'): ?>
    <?php $optionList = array(); ?>
    <?php $i=0; ?>
    <?php foreach($_options as $_option): ?>
        <?php $optionList[$i] = $this->getOptionHtml($_option); ?>
        <?php $i++; ?>
    <?php endforeach; ?>
    <table width=”100%” cellspacing=”0″ cellpadding=”0″>
        <tr>
            <th>Left</th>
            <th>Right</th>
        <tr>
            <td><?php echo $optionList[0]; ?></td>
            <td><?php echo $optionList[4]; ?></td>
        </tr>
        <tr>
            <td><?php echo $optionList[1]; ?></td>
            <td><?php echo $optionList[5]; ?></td>
        </tr>
        <tr>
            <td><?php echo $optionList[2]; ?></td>
            <td><?php echo $optionList[6]; ?></td>
        </tr>
        <tr>
            <td><?php echo $optionList[3]; ?></td>
            <td><?php echo $optionList[7]; ?></td>
        </tr>

    </table>
<?php else: ?>
<dl>
<?php foreach($_options as $_option): ?>
    <?php echo $this->getOptionHtml($_option) ?>
<?php endforeach; ?>
</dl>

I did this in order to apply some rough customization to the custom options of some products with a specific attribute set. It worked. Thanks for the ideas.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.