Magento 1.7.0.2: display the default value in the drop-down list of products

This is the code from the "select.phtml" file: app / design / frontend / base / default / template / bundle / catalog / product / view / type / bundle / option / select. PHTML

What code do I need to insert so that I can display the default value next to the product name in the product drop-down list

Or at least how can I get the default value for options based on the product identifier?

<?php $_option = $this->getOption(); ?> <?php $_selections = $_option->getSelections(); ?> <?php $_default = $_option->getDefaultSelection(); ?> <?php list($_defaultQty, $_canChangeQty) = $this->_getDefaultValues(); ?> <dt> <label<?php if ($_option->getRequired()) echo ' class="required"' ?>><?php echo $this->htmlEscape($_option->getTitle()) ?><?php if ($_option->getRequired()) echo '<em>*</em>' ?></label> </dt> <dd<?php if ($_option->decoratedIsLast){?> class="last"<?php }?>> <div class="input-box"> <?php if ($this->_showSingle()): ?> <?php echo $this->getSelectionTitlePrice($_selections[0]) ?> <input type="hidden" name="bundle_option[<?php echo $_option->getId() ?>]" value="<?php echo $_selections[0]->getSelectionId() ?>"/> <?php else:?> <select onchange="bundle.changeSelection(this)" id="bundle-option-<?php echo $_option->getId() ?>" name="bundle_option[<?php echo $_option->getId() ?>]" class="bundle-option-<?php echo $_option->getId() ?><?php if ($_option->getRequired()) echo ' required-entry' ?> bundle-option-select change-container-classname"> <option value=""><?php echo $this->__('Choose a selection...') ?></option> <?php foreach ($_selections as $_selection): ?> <option value="<?php echo $_selection->getSelectionId() ?>"<?php if ($this->_isSelected($_selection)) echo ' selected="selected"' ?><?php if (!$_selection->isSaleable()) echo ' disabled="disabled"' ?>><?php echo $this->getSelectionTitlePrice($_selection, false) ?></option> <?php endforeach; ?> </select> <?php endif; ?> <span class="qty-holder" style="display: inline-block; margin-left: 20px;"> <label for="bundle-option-<?php echo $_option->getId() ?>-qty-input"><?php echo $this->__('Qty:') ?>&nbsp;</label><input onkeyup="bundle.changeOptionQty(this, event)" onblur="bundle.changeOptionQty(this, event)" <?php if (!$_canChangeQty) echo ' disabled="disabled"' ?> id="bundle-option-<?php echo $_option->getId() ?>-qty-input" class="input-text qty<?php if (!$_canChangeQty) echo ' qty-disabled' ?>" type="text" name="bundle_option_qty[<?php echo $_option->getId() ?>]" value="<?php echo $_defaultQty ?>" style="background-color: rgb(248, 248, 248);"/> </span> </div> </dd> 
+4
source share
1 answer
 <?php $_option = $this->getOption(); ?> <?php $_selections = $_option->getSelections(); ?> <?php $_default = $_option->getDefaultSelection(); ?> <?php list($_defaultQty, $_canChangeQty) = $this->_getDefaultValues(); ?> <dt> <label<?php if ($_option->getRequired()) echo ' class="required"' ?>><?php echo $this->htmlEscape($_option->getTitle()) ?><?php if ($_option->getRequired()) echo '<em>*</em>' ?></label> </dt> <dd<?php if ($_option->decoratedIsLast){?> class="last"<?php }?>> <div class="input-box"> <?php if ($this->_showSingle()): ?> <?php echo $this->getSelectionTitlePrice($_selections[0]) ?> <input type="hidden" name="bundle_option[<?php echo $_option->getId() ?>]" value="<?php echo $_selections[0]->getSelectionId() ?>"/> <?php else:?> <select onchange="bundle.changeSelection(this)" id="bundle-option-<?php echo $_option->getId() ?>" name="bundle_option[<?php echo $_option->getId() ?>]" class="bundle-option-<?php echo $_option->getId() ?><?php if ($_option->getRequired()) echo ' required-entry' ?> bundle-option-select change-container-classname"> <option value=""><?php echo $this->__('Choose a selection...') ?></option> <?php foreach ($_selections as $_selection): ?> <option value="<?php echo $_selection->getSelectionId() ?>"<?php if ($this->_isSelected($_selection)) echo ' selected="selected"' ?><?php if (!$_selection->isSaleable()) echo ' disabled="disabled"' ?>><?php echo $this->getSelectionTitlePrice($_selection, false) ?> (Default Qty: <?php echo $_selection->getSelectionQty() ?>)</option> <?php endforeach; ?> </select> <?php endif; ?> <span class="qty-holder" style="display: inline-block; margin-left: 20px;"> <label for="bundle-option-<?php echo $_option->getId() ?>-qty-input"><?php echo $this->__('Qty:') ?>&nbsp;</label><input onkeyup="bundle.changeOptionQty(this, event)" onblur="bundle.changeOptionQty(this, event)" <?php if (!$_canChangeQty) echo ' disabled="disabled"' ?> id="bundle-option-<?php echo $_option->getId() ?>-qty-input" class="input-text qty<?php if (!$_canChangeQty) echo ' qty-disabled' ?>" type="text" name="bundle_option_qty[<?php echo $_option->getId() ?>]" value="<?php echo $_defaultQty ?>" style="background-color: rgb(248, 248, 248);"/> </span> </div> </dd> 

Use the code above to display the default value in the drop-down list. I only added code inside the foreach loop

 (Default Qty: <?php echo $_selection->getSelectionQty() ?>) 
+4
source

Source: https://habr.com/ru/post/1490041/


All Articles