gpt4 book ai didi

Magento 1.7.0.2 : Display default qty in the drop-down bundled product options

转载 作者:行者123 更新时间:2023-12-02 12:19:51 29 4
gpt4 key购买 nike

这是文件“select.phtml”中的代码:app/design/frontend/base/default/template/bundle/catalog/product/view/type/bundle/option/select。 .phtml

我需要插入什么代码才能在下拉捆绑产品选项中的产品名称旁边显示默认数量

或者至少如何根据产品 ID 获取选项的默认数量?

<?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>

最佳答案

<?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>

使用上面的代码在下拉列表中显示默认数量。我只在 foreach 循环中添加了以下代码

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

关于Magento 1.7.0.2 : Display default qty in the drop-down bundled product options,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17504338/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com