[ecshop 资料]商品显示 选择属性名称然后标题也加上属性的名称

本文介绍了一种通过JavaScript实现的商品属性选择与价格更新的方法。该方法能够在用户选择不同的商品属性时,动态调整商品的价格,并将所选属性的名称加入到商品标题中,以便清晰展示给用户。此外,还实现了库存检查功能,确保所选数量不超过现有库存。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

商品显示 。。。。js 选择属性名称


然后标题也加上属性的名称



if (!empty($_REQUEST['act']) && $_REQUEST['act'] == 'price')
{
    include('includes/cls_json.php');

    $json   = new JSON;
    $res    = array('err_msg' => '', 'result' => '', 'qty' => 1);

    //$attr_id    = isset($_REQUEST['attr']) ? explode(',', $_REQUEST['attr']) : array();
    $attr_id    = isset($_REQUEST['attr']) ? $_REQUEST['attr'] : array();
    $number     = (isset($_REQUEST['number'])) ? intval($_REQUEST['number']) : 1;
    //$number		= 1;

    if ($goods_id == 0)
    {
        $res['err_msg'] = $_LANG['err_change_attr'];
        $res['err_no']  = 1;
    }
    else
    {
        if ($number == 0)
        {
            $res['qty'] = $number = 1;
        }
        else
        {
            $res['qty'] = $number;
        }
        if(empty($attr_id)){
        	$attr_id = 0;
        }
        $res['attr_num'] = get_product_attr_num($goods_id,$attr_id);
        //$res['attr_num'] = $ret[$attr_id];
        
		// 		$number = 1;

		//echo "goods_id : $goods_id ;number: $number ;   attr_id: $attr_id   \r\n";
		
        $shop_price  = get_final_price($goods_id, $number, true, $attr_id);
		
		//echo  "shop_price : $shop_price \r\n";
		
		//exit();
		
        $mark_price = get_mark_price($goods_id);

		$shop_price = ($shop_price>=0) ? $shop_price : 0;

        $res['result'] = price_format($shop_price * $number);
        $res['result1'] = price_format($mark_price);
		$res['result_jf'] = floor($shop_price * $number);

		//add by yanggg 2015/11/28 增加了 属性名称的返回 js 到时候控制商品的名称
		$sql = "SELECT goods_attr_id, attr_value FROM " . $GLOBALS['ecs']->table('goods_attr') . " WHERE goods_id = '$goods_id' and goods_attr_id='$attr_id'";
		$results_www_ecshop68_com = $GLOBALS['db']->getAll($sql);
		$res['attr_value'] = $results_www_ecshop68_com[0]['attr_value'];
		
		
		//预售,检查库存是否足够
		$current_number = $res['attr_num'];
		if($number > $current_number)
		{
			$res['err_msg'] = sprintf($_LANG['err_shortage_little'], $current_number);
			$res['qty'] = $current_number;
			$res['err_no']  = 1;
		}
		
		
    }

    die($json->encode($res));
}

//商品属性的显示 2015/11/28 注释 by yanggg
function show_attr_status(theid, goods_id, attr_id_www_ecshop68_com)
{
    if(theid.className=='wuxiao'){
        return;
    }
    
    var selected_first=new Array();
    selected_first[0] = theid.id.replace('xuan_a_','');
    var spec_attr_type = document.getElementsByName('spec_attr_type');
    var www_ecshop68_com= theid.parentNode.id.replace('catt_', '');
    document.getElementById('spec_attr_type_'+www_ecshop68_com).value=selected_first[0];

    //if(attr_selected()){
    //    return true;
    //}
    if(change_classname(theid,www_ecshop68_com)){
        //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');
        changePriceAll();
        return true;
    }


    var mylist = theid.parentNode.getElementsByTagName("a");
    for(zzz=0; zzz<mylist.length; zzz++)
    {
        if(mylist[zzz].className!='wuxiao')
        {
                mylist[zzz].onclick=function(){
                    show_attr_status(this, goods_id, attr_id_www_ecshop68_com);
                }
        }
        var my_input_id = mylist[zzz].id.replace('xuan_a_', 'spec_value_');
        document.getElementById(my_input_id).checked=false;
    }
    var the_input_id = theid.id.replace('xuan_a_', 'spec_value_');
    //theid.onclick=function(){}
    document.getElementById(the_input_id).checked="checked";

    
     for (iii=0;iii<spec_attr_type.length;iii++ )
     {
         selid_www_ecshop68_com=0;
         if (spec_attr_type[iii].value != www_ecshop68_com)
         {
        var s1=document.getElementById('xuan_'+spec_attr_type[iii].value);
        var s1_list = s1.getElementsByTagName("a");
        for(jjj=0;jjj<s1_list.length;jjj++)
        {    
            s1_a_id = s1_list[jjj].id.replace('xuan_a_','');
            if (is_exist_prod(selected_first, s1_a_id, myString) )
            {                    
                if (selid_www_ecshop68_com)
                {
                    if (s1_list[jjj].className == 'cattsel')
                    {
                        selid_www_ecshop68_com = s1_a_id;
                    }
                }
                else
                {
                    selid_www_ecshop68_com =  s1_a_id;
                }
                s1_list[jjj].className = '';
                s1_list[jjj].onclick=function(){
                    show_attr_status(this, goods_id, attr_id_www_ecshop68_com);
                }
            }
            else
            {
                s1_list[jjj].className = 'wuxiao';
                //s1_list[jjj].onclick=function(){}                
            }
            document.getElementById('spec_value_' + s1_a_id).checked = false;
        }
        document.getElementById('spec_value_' + selid_www_ecshop68_com).checked = "checked";
        selected_first.push(selid_www_ecshop68_com);
        document.getElementById('xuan_a_'+selid_www_ecshop68_com).className='cattsel';
        //document.getElementById('xuan_a_'+selid_www_ecshop68_com).onclick=function(){}        
         }
    }
    changeAtt(theid, goods_id);
    if (theid.parentNode.id.replace('catt_','')==attr_id_www_ecshop68_com)
    {
        get_gallery_attr(goods_id, selected_first[0]);
    }
    
    //changePrice();
 }



/**
* 获取商品范围价格
*/
function changePriceAll()
{
    var attr = getSelectedAttributes(document.forms['ECS_FORMBUY']);
    var qty = document.forms['ECS_FORMBUY'].elements['number'].value;
    Ajax.call('goods.php', 'act=allprice&id=' + goodsId + '&attr=' + attr + '&number=1', changePriceResponse, 'GET', 'JSON');
}


/**
 * 接收返回的信息
 */
function changePriceResponse(res)
{
  if (res.err_msg.length > 0 && res.qty ==0)
  {
    document.getElementById('choose-btns').style.display = 'none';
    document.getElementById('choose-btns1').style.display = 'block';
    alert(res.err_msg);
    document.forms['ECS_FORMBUY'].elements['number'].value = res.qty;
 }
  else
  {
      document.getElementById('choose-btns').style.display = 'block';
     document.getElementById('choose-btns1').style.display = 'none';
    document.forms['ECS_FORMBUY'].elements['number'].value = res.qty;

    if (document.getElementById('ECS_GOODS_AMOUNT')){
      document.getElementById('ECS_GOODS_AMOUNT').innerHTML = res.result;
      if (res.result_jf){
        document.getElementById('ECS_GOODS_AMOUNT_jf').innerHTML = res.result_jf;
      }
    }
    //add by yanggg 商品标题也加入

    if (document.getElementById('name') && document.getElementById('name_realname') ){
      document.getElementById('name').innerHTML = document.getElementById('name_realname').innerHTML + ' ' + res.attr_value ;
    }

    if(document.getElementById('shows_number')){
    document.getElementById('shows_number').innerHTML = res.attr_num;
    }
    if(document.getElementById('mark_price')){
    document.getElementById('mark_price').innerHTML = res.result1;
    }
  }

 
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值