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

作者:admi... 点击数: 0 收藏到会员中心
最后编辑时间: 2019-09-06 12:29

修改

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

修改完成之后如图示

08201905_02.jpg

付费内容限时免费中...

修改以下位置  app\design\frontend\smartwave\porto\template\configurableswatches\catalog\product\view\type\options\configurable\swatches.phtml

08201905_05.jpg

增加了一个$i随输出的时候给一个selected到class则完成

内容说明:
如您需要转载本文请保留以下信息是对作者发文的支持与尊重:

Magento1.x可配置产品页自动默认选择第一个可用项实操方法 来源于 https://www.magentola.com/news-read-14.html
上一篇:没有了
下一篇:magento2迁移后图片在后台均属于隐藏状态
相关内容
产品推荐