ecshop商品详情页面显示关联属性库存
使用ecshop模板搭建网站的时候,绝大多数网站都是需要使用商品属性这个功能的,比如服装商城,肯定需要使用到颜色、尺寸等属性,而ecshop商品详情页面默认展示的库存是商品的总库存,那我们想让这个库存显示为当前选中的属性的库存,并且当选择其他属性时,库存变为对应属性的库存,仿淘宝,这个怎么来实现呢?按照下面修改对应的文件,就可以轻松实现这个效果.
goods.dwt页面修改:
- <!-- {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} -->
在显示详细信息合适的地方加:
<font style=" color:#CCCCCC;">(库存:<font id="shows_number">{$goods.goods_number} {$goods.measure_unit}</font>)</font>
在goods.dwt加js代码:
- 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)
- {
- $('shows_number').innerHTML = result.product_number+'件';
- }
- else
- {
- $('shows_number').innerHTML = '未设置'
- }
- }
打开goods.php添加70行左右吧
- if (!emptyempty($_REQUEST['act']) && $_REQUEST['act'] == 'get_products_info')
- {
- include('includes/cls_json.php');
-
- $json = new JSON;
-
-
- $spce_id = $_GET['id'];
- $goods_id = $_GET['goods_id'];
- $row = get_products_info($goods_id,explode(",",$spce_id));
-
- die($json->encode($row));
-
- }