item_list class 추가

This commit is contained in:
gnuboard
2013-07-26 10:30:56 +09:00
parent ae652609e0
commit ac653bae67

View File

@ -35,6 +35,240 @@ echo $disp->run();
display_category 나 display_event 로 사용하기 위해서는 $type 값만 넘기지 않으면 됩니다.
*/
class item_list
{
// 상품유형 : 기본적으로 1~5 까지 사용할수 있으며 0 으로 설정하는 경우 상품유형별로 노출하지 않습니다.
// 분류나 이벤트로 노출하는 경우 상품유형을 0 으로 설정하면 됩니다.
protected $type;
protected $list_skin;
protected $list_mod;
protected $list_row;
protected $img_width;
protected $img_height;
// 상품상세보기 경로
protected $href = "";
// select 에 사용되는 필드
protected $fields = "*";
// 분류코드로만 사용하는 경우 상품유형($type)을 0 으로 설정하면 됩니다.
protected $ca_id = "";
protected $ca_id2 = "";
protected $ca_id3 = "";
// 노출순서
protected $order_by = "it_order, it_id desc";
// 상품의 이벤트번호를 저장합니다.
protected $event = "";
// 스킨의 기본 css 를 다른것으로 사용하고자 할 경우에 사용합니다.
protected $css = "";
// 상품의 사용여부를 따져 노출합니다. 0 인 경우 모든 상품을 노출합니다.
protected $use = 1;
// 모바일에서 노출하고자 할 경우에 true 로 설정합니다.
protected $is_mobile = false;
// 기본으로 보여지는 필드들
protected $view_it_id = false; // 상품코드
protected $view_it_img = true; // 상품이미지
protected $view_it_name = true; // 상품명
protected $view_it_price = true; // 판매가격
protected $view_it_cust_price = false; // 소비자가
protected $view_it_icon = false; // 아이콘
protected $view_sns = false; // SNS
protected $count = 1; // 몇번째 class 호출인지를 저장합니다.
// $type : 상품유형 (기본으로 1~5까지 사용)
// $list_skin : 상품리스트를 노출할 스킨을 설정합니다. 스킨위치는 skin/shop/쇼핑몰설정스킨/type??.skin.php
// $list_mod : 1줄에 몇개의 상품을 노출할지를 설정합니다.
// $list_row : 상품을 몇줄에 노출할지를 설정합니다.
// $img_width : 상품이미지의 폭을 설정합니다.
// $img_height : 상품이미지의 높이을 설정합니다. 0 으로 설정하는 경우 썸네일 이미지의 높이는 폭에 비례하여 생성합니다.
//function __construct($type=0, $list_skin='', $list_mod='', $list_row='', $img_width='', $img_height=0, $ca_id='') {
function __construct($list_skin='', $list_mod='', $list_row='', $img_width='', $img_height=0) {
$this->list_skin = $list_skin;
$this->list_mod = $list_mod;
$this->list_row = $list_row;
$this->img_width = $img_width;
$this->img_height = $img_height;
$this->set_href(G4_SHOP_URL.'/item.php?it_id=');
$this->count++;
}
function set_type($type) {
$this->type = $type;
if ($type) {
$this->set_list_skin($list_skin);
$this->set_list_mod($list_mod);
$this->set_list_row($list_row);
$this->set_img_size($img_width);
}
}
// 분류코드로 검색을 하고자 하는 경우 아래와 같이 인수를 넘겨줍니다.
// 1단계 분류는 (분류코드, 1)
// 2단계 분류는 (분류코드, 2)
// 3단계 분류는 (분류코드, 3)
function set_ca_id($ca_id, $level=1) {
if ($level == 2) {
$this->ca_id2 = $ca_id;
} else if ($level == 3) {
$this->ca_id3 = $ca_id;
} else {
$this->ca_id = $ca_id;
}
}
// 이벤트코드를 인수로 넘기게 되면 해당 이벤트에 속한 상품을 노출합니다.
function set_event($ev_id) {
$this->event = $ev_id;
}
// 리스트 스킨을 바꾸고자 하는 경우에 사용합니다.
// 리스트 스킨의 위치는 skin/shop/쇼핑몰설정스킨/type??.skin.php 입니다.
// 특별히 설정하지 않는 경우 상품유형을 사용하는 경우는 쇼핑몰설정 값을 그대로 따릅니다.
function set_list_skin($list_skin) {
global $default;
$this->list_skin = $list_skin ? $list_skin : $default['de_type'.$this->type.'_list_skin'];
}
// 1줄에 몇개를 노출할지를 사용한다.
// 특별히 설정하지 않는 경우 상품유형을 사용하는 경우는 쇼핑몰설정 값을 그대로 따릅니다.
function set_list_mod($list_mod) {
global $default;
$this->list_mod = $list_mod ? $list_mod : $default['de_type'.$this->type.'_list_mod'];
}
// 몇줄을 노출할지를 사용한다.
// 특별히 설정하지 않는 경우 상품유형을 사용하는 경우는 쇼핑몰설정 값을 그대로 따릅니다.
function set_list_row($list_row) {
global $default;
$this->list_row = $list_row ? $list_row : $default['de_type'.$this->type.'_list_row'];
}
// 노출이미지(썸네일생성)의 폭, 높이를 설정합니다. 높이를 0 으로 설정하는 경우 쎰네일 비율에 따릅니다.
// 특별히 설정하지 않는 경우 상품유형을 사용하는 경우는 쇼핑몰설정 값을 그대로 따릅니다.
function set_img_size($img_width, $img_height=0) {
global $default;
$this->img_width = $img_width ? $img_width : $default['de_type'.$this->type.'_img_width'];
$this->img_height = $img_height ? $img_height : $default['de_type'.$this->type.'_img_height'];
}
// 특정 필드만 select 하는 경우에는 필드명을 , 로 구분하여 "field1, field2, field3, ... fieldn" 으로 인수를 넘겨줍니다.
function set_fields($str) {
$this->fields = $str;
}
// 특정 필드로 정렬을 하는 경우 필드와 정렬순서를 , 로 구분하여 "field1 desc, field2 asc, ... fieldn desc " 으로 인수를 넘겨줍니다.
function set_order_by($str) {
$this->order_by = $str;
}
// 사용하는 상품외에 모든 상품을 노출하려면 0 을 인수로 넘겨줍니다.
function set_use($use) {
$this->use = $use;
}
// 모바일로 사용하려는 경우 true 를 인수로 넘겨줍니다.
function set_mobile($mobile=true) {
$this->is_mobile = $mobile;
}
// 스킨에서 특정 필드를 노출하거나 하지 않게 할수 있습니다.
// 가령 소비자가는 처음에 노출되지 않도록 설정되어 있짐나 노출을 하려면
// ("it_cust_price", true) 와 같이 인수를 넘겨줍니다.
// 이때 인수로 넘겨주는 값은 스킨에 정의된 필드만 가능하다는 것입니다.
function set_view($field, $view=true) {
$this->{"view_".$field} = $view;
}
// anchor 태그에 하이퍼링크를 다른 주소로 걸거나 아예 링크를 걸지 않을 수 있습니다.
// 인수를 "" 공백으로 넘기면 링크를 걸지 않습니다.
function set_href($href) {
$this->href = $href;
}
// ul 태그의 css 를 교체할수 있다. "sct sct_abc" 를 인수로 넘기게 되면
// 기존의 ul 태그에 걸린 css 는 무시되며 인수로 넘긴 css 가 사용됩니다.
function set_css($css) {
$this->css = $css;
}
// class 에 설정된 값으로 최종 실행합니다.
function run() {
global $g4, $config, $member, $default, $shop_skin_path, $shop_skin_url;
$where = array();
if ($this->use) {
$where[] = " it_use = '1' ";
}
if ($this->type) {
$where[] = " it_type{$this->type} = '1' ";
}
if ($this->ca_id || $this->ca_id2 || $this->ca_id3) {
$where_ca_id = array();
if ($this->ca_id) {
$where_ca_id[] = " ca_id like '{$this->ca_id}%' ";
}
if ($this->ca_id2) {
$where_ca_id[] = " ca_id2 like '{$this->ca_id2}%' ";
}
if ($this->ca_id3) {
$where_ca_id[] = " ca_id3 like '{$this->ca_id3}%' ";
}
$where[] = implode(" or ", $where_ca_id);
}
if ($this->order_by) {
$sql_order = " order by {$this->order_by} ";
}
if ($this->event) {
//$sql_common = " select {$this->fields} from `{$g4['shop_event_item_table']}` a left join `{$g4['shop_item_table']}` b on (a.it_id = b.it_id and a.ev_id = '{$this->event}') ";
$sql_common = " select {$this->fields} from `{$g4['shop_event_item_table']}` a left join `{$g4['shop_item_table']}` b on (a.it_id = b.it_id) ";
$where[] = " a.ev_id = '{$this->event}' ";
} else {
$sql_common = " select {$this->fields} from `{$g4['shop_item_table']}` ";
}
$sql_where = " where " . implode(" and ", $where);
$sql = $sql_common . $sql_where . " limit " . ($this->list_mod * $this->list_row);
$result = sql_query($sql);
//echo (int)mysql_num_rows($result);
$sns_url = G4_SHOP_URL.'/item.php?it_id='.$row['it_id'];
$sns_title = get_text($row['it_name']).' | '.get_text($config['cf_title']);
if ($this->is_mobile) {
$file = G4_MSHOP_PATH."/{$this->list_skin}";
} else {
$file = "{$shop_skin_path}/{$this->list_skin}";
}
if ($this->list_skin == "") {
return $this->count."번 item_list() 의 스킨파일이 지정되지 않았습니다.";
} else if (!file_exists($file)) {
return "{$shop_skin_url}/{$this->list_skin} 파일을 찾을 수 없습니다.";
} else {
ob_start();
$list_mod = $this->list_mod;
include($file);
$content = ob_get_contents();
ob_end_clean();
return $content;
}
}
}
class display_item
{
// 상품유형 : 기본적으로 1~5 까지 사용할수 있으며 0 으로 설정하는 경우 상품유형별로 노출하지 않습니다.