Reputation: 1123
all Im trying to add an ID to my inputs in custom options of some of my magento products, currently its generated as follows:
<input type="text" onchange="opConfig.reloadPrice()" id="options_35_text" class="input-text validate-length maximum-length-20 product-custom-option" name="options[35]" value="">
the ID is generated via magento and ideally I want the option to give it my own ID rather then having generated one,
The idea is simple, when someone selects Yes to the Personalised option it will show the Name & Number boxes, ive got it to work on one product but the input IDs are different per products so Im just confused how to do this, Ive search the internet and there all telling me how to add a custom input rather then adding another column as I can use my own ID:
Any help would be appreciated.
Upvotes: 0
Views: 850
Reputation: 5174
Currently there is no way (without your own customization) to add/define individual IDs for new attributes.
Depending on the type of attribute (date, file, select, text/input) you can find the template for those in app/design/frontend/base/default/template/catalog/product/view/options/type/
. As you can see in those files, the ID is dynamically generated.
Example for inputs/textareas, file app/design/frontend/base/default/template/catalog/product/view/options/type/text.phtml
<?php $_option = $this->getOption(); ?>
<dt><label<?php if ($_option->getIsRequire()) echo ' class="required"' ?>><?php if ($_option->getIsRequire()) echo '<em>*</em>' ?><?php echo $this->escapeHtml($_option->getTitle()) ?></label>
<?php echo $this->getFormatedPrice() ?></dt>
<dd<?php if ($_option->decoratedIsLast){?> class="last"<?php }?>>
<div class="input-box">
<?php if ($_option->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_FIELD): ?>
<input type="text" onchange="opConfig.reloadPrice()" id="options_<?php echo $_option->getId() ?>_text" class="input-text<?php echo $_option->getIsRequire() ? ' required-entry' : '' ?> <?php echo $_option->getMaxCharacters() ? ' validate-length maximum-length-'.$_option->getMaxCharacters() : '' ?> product-custom-option" name="options[<?php echo $_option->getId() ?>]" value="<?php echo $this->escapeHtml($this->getDefaultValue()) ?>" />
<?php elseif ($_option->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_AREA): ?>
<textarea id="options_<?php echo $_option->getId() ?>_text" onchange="opConfig.reloadPrice()" class="<?php echo $_option->getIsRequire() ? ' required-entry' : '' ?> <?php echo $_option->getMaxCharacters() ? ' validate-length maximum-length-'.$_option->getMaxCharacters() : '' ?> product-custom-option" name="options[<?php echo $_option->getId() ?>]" rows="5" cols="25"><?php echo $this->escapeHtml($this->getDefaultValue()) ?></textarea>
<?php endif; ?>
<?php if ($_option->getMaxCharacters()): ?>
<p class="note"><?php echo Mage::helper('catalog')->__('Maximum number of characters:')?> <strong><?php echo $_option->getMaxCharacters() ?></strong></p>
<?php endif; ?>
</div>
</dd>
Of course you can customize this template by overwriting it. For that you copy this file to the path where your custom design is, i. e. app/design/frontend/default/<YOUR NEW THEME NAME>/template/catalog/product/view/options/type/text.phtml
. You can then adjust the template but you need to make sure that the other fields still work with the customizations you did.
Upvotes: 1