官方微博: 腾讯  
首页 > ECSHOP教程 > ECSHOP模板教程 > ECSHOP商品详情页修改 > ECSHOP选择商品属性购买商品数量增加商品总价

ECSHOP选择商品属性购买商品数量增加商品总价

ECSHOP教程 / ecshop 教程网(www.ecshop119.com) 2014-01-17

各位ECSHOP网店系统用户大家好,欢迎来到ECSHOP教程网图文教程,今天为大家详细解说一下怎么给ECSHOP商品选择属性购买商品数量 以后显示商品总价的方法。

<form action="javascript:addToCart({$goods.goods_id})" method="post" name="ECS_FORMBUY" id="ECS_FORMBUY" >
      
      <!-- {* 开始循环所有可选属性 *} -->
      <!-- {foreach from=$specification item=spec key=spec_key} -->
      <li class="padd loop">
      <strong>{$spec.name}:</strong><br />
        <!-- {* 判断属性是复选还是单选 *} -->
                    <!-- {if $spec.attr_type eq 1} -->
                      <!-- {if $cfg.goodsattr_style eq 1} -->
                        <!-- {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} -->
                        <input type="hidden" name="spec_list" value="{$key}" />
                        <!-- {else} -->
                        <select name="spec_{$spec_key}" onchange="changePrice()">
                          <!-- {foreach from=$spec.values item=value key=key} -->
                          <option label="{$value.label}" value="{$value.id}">{$value.label} {if $value.price gt 0}{$lang.plus}{elseif $value.price lt 0}{$lang.minus}{/if}{if $value.price neq 0}{$value.format_price}{/if}</option>
                          <!-- {/foreach} -->
                        </select>
                        <input type="hidden" name="spec_list" value="{$key}" />
                      <!-- {/if} -->
                    <!-- {else} -->
                      <!-- {foreach from=$spec.values item=value key=key} -->
                      <label for="spec_value_{$value.id}">
                      <input type="checkbox" name="spec_{$spec_key}" value="{$value.id}" id="spec_value_{$value.id}" 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} -->
                      <input type="hidden" name="spec_list" value="{$key}" />
                    <!-- {/if} -->
      </li>
      <!-- {/foreach} -->
      <!-- {* 结束循环可选属性 *} -->
     
     
     
 <!-- 商品总价-->

{$lang.amount}:<font id="ECS_GOODS_AMOUNT" class="shop"></font>

 <!-- 商品总价结束--> 

如果要隐藏商品总价写成:<font id="ECS_GOODS_AMOUNT" style="display:none"></font>


 
  <!-- 购买商品数量选择-->    


{$lang.number}:
<input name="number" type="text" id="number" value="1" size="4" onblur="changePrice()" style="border:1px solid #ccc; "/>

    
  <!-- 购买商品数量结束-->   
 
  </form>
 
 
 
 
  </body>后面加上这个 下面JS


<script type="text/javascript">
var goods_id = {$goods_id};
var goodsattr_style = {$cfg.goodsattr_style|default:1};
var gmt_end_time = {$promote_end_time|default:0};
{foreach from=$lang.goods_js item=item key=key}
var {$key} = "{$item}";
{/foreach}
var goodsId = {$goods_id};
var now_time = {$now_time};

<!-- {literal} -->
onload = function(){
  changePrice();
  fixpng();
  try { onload_leftTime(); }
  catch (e) {}
}

/**
 * 点选可选属性或改变数量时修改商品价格的函数
 */
function changePrice()
{
  var attr = getSelectedAttributes(document.forms['ECS_FORMBUY']);
  var qty = document.forms['ECS_FORMBUY'].elements['number'].value;

  Ajax.call('goods.php', 'act=price&id=' + goodsId + '&attr=' + attr + '&number=' + qty, changePriceResponse, 'GET', 'JSON');
}

/**
 * 接收返回的信息
 */
function changePriceResponse(res)
{
  if (res.err_msg.length > 0)
  {
    alert(res.err_msg);
  }
  else
  {
    document.forms['ECS_FORMBUY'].elements['number'].value = res.qty;

    if (document.getElementById('ECS_GOODS_AMOUNT'))
      document.getElementById('ECS_GOODS_AMOUNT').innerHTML = res.result;
  }
}
<!-- {/literal} -->
</script>

转载请注明:ECshop119模板屋-ECshop教程网(全国最专业的ECSHOP插件制作商-专业ECSHOP二次开发)

帮助目录

在线反馈

可以将问题或建议反馈给我们。

提交在线反馈

与网友交流ECSHOP开发修改。

加入QQ群交流