ECSHOP商品库存随商品属性变化修改方法
添加css文件 找到你的模版文件夹的style.css(只更改属性库存这个可以不添加),在ecshop模板文件最后面加上一下代码:
.catt{width:100%;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} -->
替换为:
<div>
<!-- {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} -->
</div>
有些模板做过修改,可直接查找<!-- {foreach from=$spec.values item=value key=key} -->
在a标签内添加onclick="changeAtt(this,{$value.id},{$goods.goods_id})"
继续在goods.dwt搜索function changePrice()在其上方添加以下代码:
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('shows_number').innerHTML = result.product_number+'件';
}
else
{
document.getElementById('shows_number').innerHTML = '0件';
}
}
继续查找{$goods.goods_number} {$goods.measure_unit}
为其添加id="shows_number"
添加php文件代码 打开/goods.php ,查找if (!empty($_REQUEST['act']) && $_REQUEST['act'] == 'price')在改判断语句结束后添加一下代码(大概在71行)
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));
}
简洁版效果图:
新京东模板效果: