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

来源:互联网 发布:蓝牙小车单片机程序 编辑:程序博客网 时间:2024/04/30 05:34

商品显示 。。。。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;
    }
  }

 
}


0 0