网站首页 / 资讯 / Magento教程

Magento1.x可配置产品页自动默认选择第一个可用项实操方法

作者:admin

修改

app\design\frontend\**\template\catalog\product\view\type\options\configurable.phtml

内容

   <script type="text/javascript">
        var spConfig = new Product.Config(<?php echo $_jsonConfig ?>);
    </script>
    <?php echo $this->getChildHtml('after') ?>
<?php endif;?>

<script type="text/javascript">
        var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>);
 
function fireEvent(element,event){
if (document.createEventObject){
// dispatch for IE
var evt = document.createEventObject();
return element.fireEvent('on'+event,evt)
}
else{
// dispatch for firefox + others
var evt = document.createEvent("HTMLEvents");
evt.initEvent(event, true, true ); // event type,bubbling,cancelable
return !element.dispatchEvent(evt);
}
}
Event.observe(window, 'load', function() {
spConfig.settings[0].selectedIndex = 1;
obj = spConfig.settings[0]; // this grabs the first select item
Event.observe(obj,'change',function(){});
fireEvent(obj,'change'); // this simulates selecting the first option, which triggers
spConfig.settings[1].selectedIndex = 1; // this selects the first option of the second attribute drop menu
});
    </script>
 
 
   
    <?php echo $this->getChildHtml('after') ?>
<?php endif;?>

以porto主题为例.修改完以上代码后则可实现添加到购物车不会有提示,但是在页面外观并没有展现,需要修改

修改完成之后如图示

标签: 可配置产品自动选择 可配置产品默认可用选项 magento可配置产品项修改
上一篇:没有了
下一篇:magento2迁移后图片在后台均属于隐藏状态

相关内容

最近更新
相关产品
综合服务邮箱: magento2#foxmail.com