欢迎光临景诺科技软件开发淘宝店

进店请收藏,谢谢

ecshop小技巧

ecshop调用评论数:
在includes目录下修改lib_insert.php最后面新增一个数据库查询函数。

function insert_comments_count($arr)    {    $count=$GLOBALS['db']->getOne('SELECT COUNT(*) FROM '.    $GLOBALS['ecs']->table('comment')."WHERE id_value='$arr[id]'".    "AND comment_type='$arr[type]' AND status = 1 AND parent_id = 0");    return $count;    }

模板内:

{insert name=comments_count type=$type id=$id}

ecshop详情页必不可少的js:如加入购物车,动态修改价格,加入收藏夹。由于我是套模板,别人已经写好了放大镜js再套入这些js就会冲突了。于是我自己改了下,不引入comm.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(){
	$(".spxqnr h3 a").click(function(){
		var index = $(this).index();
		$(".spxqnr h3 a").removeClass("xuand3").eq(index).addClass("xuand3");
		$(".xqbox").hide().eq(index).show();

	});
})

/**
 * 点选可选属性或改变数量时修改商品价格的函数
 */
function changePrice()
{

  var attr = getSelectedAttributes(document.forms['ECS_FORMBUY']);
  var qty = document.forms['ECS_FORMBUY'].elements['number'].value;
  $.get('goods.php?act=price&id=' + goodsId + '&attr=' + attr + '&number=' + qty,function(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;
  }
  },'json');
  return false;

  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} -->

function getSelectedAttributes(formBuy)
{
  var spec_arr = new Array();
  var j = 0;

  for (i = 0; i < formBuy.elements.length; i ++ )
  {
    var prefix = formBuy.elements[i].name.substr(0, 5);

    if (prefix == 'spec_' && (
      ((formBuy.elements[i].type == 'radio' || formBuy.elements[i].type == 'checkbox') && formBuy.elements[i].checked) ||
      formBuy.elements[i].tagName == 'SELECT'))
    {
      spec_arr[j] = formBuy.elements[i].value;
      j++ ;
    }
  }

  return spec_arr;
}

function addToCart(goodsId, parentId)
{
  var goods        = new Object();
  var spec_arr     = new Array();
  var fittings_arr = new Array();
  var number       = 1;
  var formBuy      = document.forms['ECS_FORMBUY'];
  var quick		   = 0;

  // 妫€鏌ユ槸鍚︽湁鍟嗗搧瑙勬牸
  if (formBuy)
  {
    spec_arr = getSelectedAttributes(formBuy);

    if (formBuy.elements['number'])
    {
      number = formBuy.elements['number'].value;
    }

	quick = 1;
  }

  goods.quick    = quick;
  goods.spec     = spec_arr;
  goods.goods_id = goodsId;
  goods.number   = number;
  var parent1   = (typeof(parentId) == "undefined") ? 0 : parseInt(parentId);
  var gjson = '{"quick":'+quick+',"spec":['+spec_arr+'],"goods_id":'+goodsId+',"number":'+number+',"parent":'+parent1+'}';
$.post('flow.php?step=add_to_cart',{goods:gjson},function(data){
	addToCartResponse(data);
},'json');
return false;
  Ajax.call('flow.php?step=add_to_cart', 'goods=' + goods.toJSONString(), addToCartResponse, 'POST', 'JSON');
}

function addToCartResponse(result)
{
  if (result.error > 0)
  {
    // 濡傛灉闇€瑕佺己璐х櫥璁帮紝璺宠浆
    if (result.error == 2)
    {
      if (confirm(result.message))
      {
        location.href = 'user.php?act=add_booking&id=' + result.goods_id + '&spec=' + result.product_spec;
      }
    }
    // 娌¢€夎鏍硷紝寮瑰嚭灞炴€ч€夋嫨妗�
    else if (result.error == 6)
    {
      openSpeDiv(result.message, result.goods_id, result.parent);
    }
    else
    {
      alert(result.message);
    }
  }
  else
  {
    var cartInfo = document.getElementById('ECS_CARTINFO');
    var cart_url = 'flow.php?step=cart';
    if (cartInfo)
    {
      cartInfo.innerHTML = result.content;
    }

    if (result.one_step_buy == '1')
    {
      location.href = cart_url;
    }
    else
    {
      switch(result.confirm_type)
      {
        case '1' :
          if (confirm(result.message)) location.href = cart_url;
          break;
        case '2' :
          if (!confirm(result.message)) location.href = cart_url;
          break;
        case '3' :
          location.href = cart_url;
          break;
        default :
          break;
      }
    }
  }
}

function collect(goodsId)
{
	$.get('user.php?act=collect&id=' + goodsId,function(data){
		alert(data.message);
	},'json');
 // Ajax.call('user.php?act=collect', 'id=' + goodsId, collectResponse, 'GET', 'JSON');
}
</script>

广告位调用:

{insert name='ads' id=3 num=5}

id为广告位ID num为调用广告数

订单获取 商品信息和品牌信息 :

SELECT g.brand_id,g.goods_name,g.goods_thumb,b.brand_logo,b.brand_name,oinfo.order_id FROM `ecshopt1`.`ecs_order_info` as oinfo left join `ecshopt1`.`ecs_order_goods` as og on oinfo.order_id = og.order_id left join `ecshopt1`.`ecs_goods` as g on og.goods_id = g.goods_id left join `ecshopt1`.`ecs_brand` as b on g.brand_id=b.brand_id where user_id = ’6′ limit 100

查询购物车内的信息写入订单:

INSERT INTO `ecshop5test`.`ecs_order_goods`( order_id, goods_id, goods_name, goods_sn, product_id, goods_number, market_price, goods_price, goods_attr, is_real, extension_code, parent_id, is_gift, goods_attr_id) SELECT ’33′, goods_id, goods_name, goods_sn, product_id, goods_number, market_price, goods_price, goods_attr, is_real, extension_code, parent_id, is_gift, goods_attr_id FROM `ecshop5test`.`ecs_cart` WHERE session_id = ‘eceb0670c4e3b35d8d05acc53c5556f2′ AND rec_type = ’0′

字符串拼接(concat):

$sqls = “UPDATE “. $ecs->table(‘order_goods’) .” SET pdwhere=concat(brandid,pdwhere) WHERE order_id=”.$new_order_id;

每行一个strint改数组array。
$attr_values = str_replace(“\r”, ”, $attr_values);
$attr_values1 = explode(“\n”, $attr_values);

更多

本文固定链接: http://shanmao.me/web-system/ecshop-web-system/ecshop-xiao-ji-qiao | 山猫的博客

该日志由 admin 于2014年11月16日发表在 ECSHOP二次开发 分类下,
原创文章转载请注明: ecshop小技巧 | 山猫的博客