ECshop详细页面 颜色 尺码 等规格和库存相连动 和淘宝的格式一样

上一次我发表了改变商品详细页面属性的样式 但是在点击每个属性的时候 库存不根据属性的改变而变化 现在我们

来完善它  实现联动库存

一、先下载test.gif文件  

二、添加css文件 找到style.css

.catt{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} -->
替换为:

<!-- {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或者table的class名称必须是catt,默认的模版是catt,别人定制的模版或许会改掉名称。这是好多人失败的原因。

四、添加js文件:

 <script type="text/javascript">

function changeAtt(t) {

 

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";

changePrice();

}

</script>

五、添加php文件代码 打开goods.php ,大约在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));

}

OK 更新一下缓存 现在我们就实现了 商品样式的改变和库存的联动

作者:沐雪
文章均系作者原创或翻译,如有错误不妥之处,欢迎各位批评指正。本文版权归作者和博客园共有,如需转载恳请注明。
如果您觉得阅读这篇博客让你有所收获,请点击右下方【推荐】
找一找教程网-随时随地学软件编程 http://www.zyiz.net/

原文地址:https://www.cnblogs.com/puzi0315/p/2643295.html