您现在的位置是:首页 > cms教程 > Ecshop商城教程Ecshop商城教程

ecshop商品属性库存仿淘宝属性库存联动显示的方法

碧彤2024-01-16Ecshop商城教程已有人查阅

导读ECSHOP有个货品功能,就是可以单独给商品的尺码、颜 设置库存。但是商品详情页却只能显示部库存。如果有个属 无货了,也不知道。本ECSHOP教程即可实现

ECSHOP有个货品功能,就是可以单独给商品的尺码、颜 设置库存。但是商品详情页却只能显示部库存。如果有个属 无货了,也不知道。本ECSHOP教程即可实现直接显示属 库存。是目前最完整最 的。
网上流传的免费教程有两个问题。
1、网上提供的教程无出现库存显示无效的情况,这是因为与jquery不兼容。
2、打开商品页面时,默认是选 中 个颜 的,但却显示总库存,造成误以为是 个颜 的库存。如果能打开页面就显示 个颜 库存就好了。
代码号提供本ECSHOP教程 解决这两个问题。
步:
下载选中小图标 test.gif ,保存路径:themes/default/images/test.gif    本教程最后面有下载。
第二步:
在模板样式中添加如下代码:如 themes/default/style.css
catt{width: ;height:auto;overflow:hidden;padding-bottom:5px;} .catt a{border: #7E7E7E 1px solid;  text-align: center; background-color: #fff; margin-left:5px;margin-top:6px;padding-left: 10px;padding-right: 10px;display: block; white-space: nowrap;color:#000; text-decoration:none; float:left;} .catt a:hover {border:#ED0036 2px solid; margin: -1px; margin-left:4px;margin-top:5px;} .catt a:focus {outline-style:none;} .catt .cattsel {border:#ED0036 2px solid; margin: -1px;background: url("images/test.gif") no-repeat bottom right; margin-left:4px;margin-top:5px;} .catt .cattsel a:hover {border: #ED0036 2px solid;margin:-1px;background: url("images/test.gif") no-repeat bottom right;}
第三步:
打开goods.dwt文件 替换循环文件
查找:
<!-- {foreach from=$spec.values item=value key=key} --> <label for="spec_value_{$value.id}"> <input type="radio" name="spec_{$spec_key}" value="{$value.id}" id="spec_value_{$value.id}" {if $key eq 0}checked{/if} onclick="changePrice()" /> {$value.label} [{if $value.price gt 0}{$lang.plus}{elseif $value.price lt 0} {$lang.minus}{/if} {$value.format_price|abs}] </label><br /> <!-- {/foreach} -->
替换为:
<!-- {foreach from=$spec.values item=value key=key} --> <a {if $key eq 0}class="cattsel"{/if} onclick="changeAtt(this,{$value.id},{$goods.goods_id})" href="javascript:;" name="{$value.id}" title="[{if $value.price gt 0}{$lang.plus}{elseif $value.price lt 0}{$lang.minus}{/if} {$value.format_price|abs}]">{$value.label}<input style="display:none" id="spec_value_{$value.id}" type="radio" name="spec_{$spec_key}" value="{$value.id}" {if $key eq 0} checked{/if} /></a> <!-- {/foreach} -->
第四步:
同样在本文件中 head区添加以下JS代码:
<script type="text/javascript"> function changeAtt(t,a,goods_id) {     t.lastChild.checked='checked';     for (var i = 0; i<t.parentNode.childNodes.length;i++) {         if (t.parentNode.childNodes[i].className == 'cattsel') {             t.parentNode.childNodes[i].className = '';         }     }     t.className = "cattsel";     var formBuy = document.forms['ECS_FORMBUY'];     spec_arr = getSelectedAttributes(formBuy);     Ajax.call('goods.php?act=get_products_info', 'id=' + spec_arr+ '&goods_id=' + goods_id, shows_number,'GET', 'JSON'); changePrice(); } function shows_number(result){     if(result.product_number !=undefined){     //这里我把$换成了document.getElementById,因为ecshop有时候不兼容jquery     //$('shows_number').innerHTML = result.product_number+'件';     document.getElementById('shows_number').innerHTML = result.product_number+'件';     }else{     document.getElementById('shows_number').innerHTML = '未设置';     //$('shows_number').innerHTML = '未设置';     } } </script>
第五步:
打开goods.php ,大约在70行下添加一下代码:
if (!empty($_REQUEST['act']) && $_REQUEST['act'] == 'get_products_info'){     include('includes/cls_json.php');     $json = new JSON;     // $res = array('err_msg' => '', 'result' => '', 'qty' => 1);     $spce_id = $_GET['id'];     $goods_id = $_GET['goods_id'];     $row = get_products_info($goods_id,explode(",",$spce_id));     //$res = array('err_msg'=>$goods_id,'id'=>$spce_id);     die($json->encode($row)); }
至此,已经可以显示属 库存了,下面解决打开页面默认显示总库存的问题。
仍然在 goods.dwt 文件中查找:
onload = function(){   changePrice();   fixpng();   try { onload_leftTime(); }   catch (e) {} }
修改为:
onload = function(){   changePrice();
changeKucun();//这里是添加的
fixpng();
try { onload_leftTime(); }
catch (e) {} } //默认就显示个属性库存
function changeKucun() { var frm=document.forms['ECS_FORMBUY']; spec_arr = getSelectedAttributes(frm);     Ajax.call('goods.php?act=get_products_info', 'id=' + spec_arr+ '&goods_id=' + goods_id, shows_number, 'GET', 'JSON'); }
OK了。
选中小图标下载:

本文标签:

很赞哦! ()

相关源码

  • 深蓝色风景摄影机构网站(自适应多端)pbootcms模板该模板基于PbootCMS内核开发,专为风景摄影机构、户外摄影企业设计,采用深蓝色主题传递专业与艺术感,全栈响应式架构确保PC、平板、手机端无缝适配PHP程序结合轻量级SQLite数据库也可以更换MySQL数据库查看源码
  • (PC+WAP)智能机器人人工智能物联网自动化设备源码下载本模板基于PbootCMS内核开发,为智能机器人及传感器科技企业精心设计。采用现代化设计风格,突出科技感与专业性,多方位展示企业技术实力与产品优势。查看源码
  • (自适应)科技产品设备技术作品pbootcms网站模板带下载和招聘基于PbootCMS内核开发的高端科技企业模板,采用响应式布局技术,适配各类移动终端设备。模板设计聚焦科技行业特性,通过模块化结构实现企业形象展示、技术成果发布与人才招募等核心需求查看源码
  • (自适应)帝国cms7.5文章新闻博客整站源码( 带会员中心)本模板基于帝国CMS内核开发,为新闻资讯、个人博客及作品展示类网站设计。采用响应式布局技术,确保在手机、平板和电脑等不同设备上都能获得良好的浏览体验。查看源码
  • 自适应极简风个人博客文章自媒体网站模板基于PbootCMS开源内核开发的极简个人博客模板,采用移动优先设计原则,通过Media Query技术实现320px至1920px六级分辨率适配,确保在手机、平板及PC设备上均呈现良好的视觉体验。查看源码
  • (自适应html5)重工业钢铁机械设备网站pbootcms响应式模板下载为重工业领域打造的响应式网站模板,助力企业高效展示产品与服务,基于PbootCMS开发的工业级网站模板,特别适合钢铁制造、机械设备生产等重工业企业使用。查看源码
分享笔记 (共有 篇笔记)
验证码:

本栏推荐