gpt4 book ai didi

magento-1.9 - 禁用在 Magento 的可配置产品中选择一个选项

转载 作者:行者123 更新时间:2023-12-02 12:55:16 32 4
gpt4 key购买 nike

我想禁用在可配置产品下拉列表中选择一个选项。相反,它应该自动选择默认产品。在哪里编辑以及编辑什么内容?

最佳答案

您可以在以下文件中进行这些更改。

app/design/frontend/YOUR_PACKAGE/YOUR_THEME/template/catalog/product/view/type/options/configurable.phtml

更好地使用从后端启用的“模板路径提示”。您将知道需要定制什么以及在哪里定制。

更新:

打开此文件:

/app/design/frontend/default/your_theme/template/catalog/product/view/type/options/configurable.phtml

正下方

var spConfig = new Product.Config(< ?php echo $this->getJsonConfig() ?>);

添加此 JavaScript 代码:

//we create new function
spConfig.setInitialState = function(dropdown_id)
{
//select dropdown
var dropdown = $(dropdown_id);
//remove empty option from dropdown so it is not selectable after initial selection
dropdown[0].remove();
//change selections in dropdowns
for(index = 0; index < dropdown.length; index++)
{
if(dropdown[index].value != "")
{
dropdown.selectedIndex = index;
var element = dropdown;
var event = 'change';
//fire events
if(document.createEventObject)
{
var evt = document.createEventObject();
return element.fireEvent('on'+event,evt)
}
else
{
var evt = document.createEvent("HTMLEvents");
evt.initEvent(event, true, true );
return !element.dispatchEvent(evt);
}
}
}
};
<?php foreach($_attributes as $_attribute): ?>
spConfig.setInitialState("attribute< ?php echo $_attribute->getAttributeId() ?>")
<?php endforeach; ?>

欲了解更多信息,请参阅Here以及更多Here

完整工作文件

/app/design/frontend/default/your_theme/template/catalog/product/view/type/options/configurable.phtml

<?php
$_product = $this->getProduct();
$_attributes = Mage::helper('core')->decorateArray($this->getAllowAttributes());
?>
<?php if ($_product->isSaleable() && count($_attributes)):?>
<dl>
<?php foreach($_attributes as $_attribute): ?>
<dt><label class="required"><em>*</em><?php echo $_attribute->getLabel() ?></label></dt>
<dd<?php if ($_attribute->decoratedIsLast){?> class="last"<?php }?>>
<div class="input-box">
<select name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]" id="attribute<?php echo $_attribute->getAttributeId() ?>" class="required-entry super-attribute-select">
<option><?php echo $this->__('Choose an Option...') ?></option>
</select>
</div>
</dd>
<?php endforeach; ?>
</dl>
<script type="text/javascript">
var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>);
//we create new function
spConfig.setInitialState = function(dropdown_id)
{
//select dropdown
var dropdown = $(dropdown_id);
//remove empty option from dropdown so it is not selectable after initial selection
dropdown[0].remove();
//change selections in dropdowns
for(index = 0; index < dropdown.length; index++)
{
if(dropdown[index].value != "")
{
dropdown.selectedIndex = index;
var element = dropdown;
var event = 'change';
//fire events
if(document.createEventObject)
{
var evt = document.createEventObject();
return element.fireEvent('on'+event,evt)
}
else
{
var evt = document.createEvent("HTMLEvents");
evt.initEvent(event, true, true );
return !element.dispatchEvent(evt);
}
}
}
};
<?php foreach($_attributes as $_attribute): ?>
spConfig.setInitialState("attribute<?php echo $_attribute->getAttributeId() ?>")
<?php endforeach; ?>
</script>
<?php endif;?>

关于magento-1.9 - 禁用在 Magento 的可配置产品中选择一个选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22005824/

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