首頁的推薦商品包括熱銷推薦和促銷三個文件
以熱銷商品為例:
第一步:打開根目錄/includes/lib_goods.php文件。在文件末尾添加方法
1 2 3 4 5 6 7 8 9 10 11 12 13 | function selled_count( $goods_id ) { $sql = "select sum(goods_number) as count from " . $GLOBALS [ 'ecs' ]->table( 'order_goods' ). "where goods_id ='" . $goods_id . "'" ; $res = $GLOBALS [ 'db' ]->getOne( $sql ); if ( $res >0) { return $res ; } else { return ( '0' ); } } |
第二步:搜索get_recommend_goods方法
在這個方法中找到這句話
1 | $goods [ $idx ][ 'url' ] = build_uri( 'goods' , array ( 'gid' => $row [ 'goods_id' ]), $row [ 'goods_name' ]); |
在這句話下添加:
1 | $goods [ $idx ][ 'count' ] = selled_count( $row [ 'goods_id' ]); |
第三步:在模版的library/recommend_hot.lbi中在需要的地方添加:
1 | <div class = "index_hotbg" >售出 <strong>{ $goods . count }</strong> 瓶</div> |
首頁分類下的商品,實現“已售出”。
第一步:分類下商品也需要修改lib_goods.php。找到分類下的商品
assign_cat_goods方法。在
1 | $goods [ $idx ][ 'url' ] = build_uri( 'goods' , array ( 'gid' => $row [ 'goods_id' ]), $row [ 'goods_name' ]); |
這行代碼下面添加以下代碼:
1 | $goods [ $idx ][ 'count' ] = selled_count( $row [ 'goods_id' ]); |
第二步:需要修改模版文件/library/cat_goods.lbi。在需要的地方添加
銷售量:{$goods.count}
在商品分類頁面調用已售出
第一步:修改根目錄下category.php
找到category_get_goods方法
函數中foreach循環添加
1 | $arr [ $row [ 'goods_id' ]][ 'count' ] = selled_count( $row [ 'goods_id' ]); |
第二步:文件的最后部分添加函數:
1 2 3 4 5 6 7 8 9 10 11 12 13 | function selled_count( $goods_id ) { $sql = "select sum(goods_number) as count from " . $GLOBALS [ 'ecs' ]->table( 'order_goods' ). "where goods_id ='" . $goods_id . "'" ; $res = $GLOBALS [ 'db' ]->getOne( $sql ); if ( $res >0) { return $res ; } else { return ( '0' ); } } |
第三步:
在模版文件goods_list.lbi中需要的地方添加
銷售量:{$goods.count}
說明:搜索頁面需要修改search.php
在搜索頁面調用已售出多少件
第一步:打開根目錄/search.php
在最后加上
1 2 3 4 5 6 7 8 9 10 11 12 13 | function selled_count( $goods_id ) { $sql = "select sum(goods_number) as count from " . $GLOBALS [ 'ecs' ]->table( 'order_goods' ). "where goods_id ='" . $goods_id . "'" ; $res = $GLOBALS [ 'db' ]->getOne( $sql ); if ( $res >0) { return $res ; } else { return ( '0' ); } } |
方法
第二步:在頁面搜索
1 | $arr [ $row [ 'goods_id' ]][ 'url' ] = build_uri( 'goods' , array ( 'gid' => $row [ 'goods_id' ]), $row [ 'goods_name' ]); |
在下面添加:
1 | $arr [ $row [ 'goods_id' ]][ 'count' ] = selled_count( $row [ 'goods_id' ]); |
第三步:打開模版文件/search.dwt在需要的地方調用。
銷售量:{$goods.count}
新聞熱點
疑難解答