본 글은 마켓플레이스 모듈에서 상위 카테고리의 선택 여부를 구분하고자 할 때 사용하는 팁입니다.
조금 더 설명하자면 2차 메뉴가 여성의류이고, 3차 메뉴가 상의, 하의 등일 경우 3차를 선택했을 경우 2차 메뉴가 seleted 된 상태인지 여부를 구분하고자 할 때 사용 할 수 있습니다.
제가 삽질한 코드는 다음과 같습니다. -_-; 새벽 내내 수백번 고쳐적은 듯;;
<pre>
{print_r($cate_list)}
</pre>
<pre>
category : {$category} <br>
val->category_srl : {$val->category_srl} <br>
category_list[$category]->parent_srl : {$category_list[$category]->parent_srl} <br>
category=val->category_srl : {$category==$val->category_srl} <br>
[text:{$category_list[$category]->text}]
[expand:{$category_list[$category]->expand}<!--@if($category_list[$category='5918']->expand=='1')-->O<!--@else-->X<!--@end-->]
[child_count:{$category_list[$category]->child_count}]
[childs:{var_dump($category_list[$category]->childs)}]
</pre>
$cate_list
카테고리 정보를 출력하는 변수입니다.
{var_dump($cate_list)} 혹은 {print_r($cate_list)} 라고 적으면 이 변수에 담긴 값들이 출력됩니다.
좀 더 예쁘게 보기 위해서는 <pre>...</pre> 태그로 감싸주세요.
[ex]
<pre>{print_r($cate_list)}<pre>
※ var_dump와 print_r의 차이점
http://chongmoa.com/php/5130
[위 코드에 대한 결과값 스크린샷]
{print_r($cate_list)} 라고 입력하면 위와 같은 화면이 출력됩니다.
마켓플레이스에서 설정한 카테고리는 다음과 같습니다.
전체를 다 가져와보면 아래와 같습니다.
Array
(
[5918] => stdClass Object
(
[mid] => mp1
[module_srl] => 5305
[category_srl] => 5918
[parent_srl] => 0
[text] => 여성의루
[title] => 여성의루
[description] =>
[expand] => 1
[color] =>
[document_count] => 0
[depth] => 0
[child_count] => 2
[childs] => Array
(
[0] => 5919
[1] => 5920
)
[grant] => 1
[selected] =>
[first] => 1
[children] => Array
(
[0] => stdClass Object
(
[mid] => mp1
[module_srl] => 5305
[category_srl] => 5919
[parent_srl] => 5918
[text] => 2차
[title] => 2차
[description] =>
[expand] => 1
[color] =>
[document_count] => 0
[depth] => 1
[child_count] => 1
[childs] => Array
(
[0] => 5920
)
[grant] => 1
[selected] =>
[first] => 1
[last] => 1
)
[1] => stdClass Object
(
[mid] => mp1
[module_srl] => 5305
[category_srl] => 5920
[parent_srl] => 5919
[text] => 3차
[title] => 3차
[description] =>
[expand] =>
[color] =>
[document_count] => 0
[depth] => 2
[child_count] => 0
[childs] => Array
(
)
[grant] => 1
[selected] => 1
[first] => 1
[last] => 1
)
)
)
[5923] => stdClass Object
(
[mid] => mp1
[module_srl] => 5305
[category_srl] => 5923
[parent_srl] => 0
[text] => 남성의류
[title] => 남성의류
[description] =>
[expand] =>
[color] =>
[document_count] => 0
[depth] => 0
[child_count] => 0
[childs] => Array
(
)
[grant] => 1
[selected] =>
[last] => 1
[children] => Array
(
)
)
)
자, 이제 본격적으로...
'2차' 카테고리를 선택한 경우
상위 카테고리인 '여성의류'가 선택된 상태로 표시되어야 한다면 어떻게 해야할까요?!
$category_list[$category_srl='5918']->expand=='1'
<!--@if($category_list[$category_srl='5918']->expand=='1')-->O<!--@else-->X<!--@end-->
일단 상위 카테고리인 '여성의류'의 category_srl 값이 필요합니다.
위에서 찾아보니 상위카테고리인 여성의류의 category_srl은 5918 입니다.
{var_dump($cate_list)}로 출력해보면 해당 category_srl의 expand 가 bool(true) bool(false)로 표시되는데,
확장된 상태(expand)가 '1'일 경우를 참이라고 합니다. ($category_list[$category_srl='5918']->expand=='1')
{$category_list[$category]->parent_srl}
5918이란 건 부모 카테고리를 의미하므로,
부모 카테고리값을 출력하는 코드를 넣어줍니다.
<!--@if($category_list[$category_srl=$category_list[$category]->parent_srl]->expand=='1')-->O<!--@else-->X<!--@end-->
'5918'이라는 숫자 대신 $category_list[$category]->parent_srl 을 넣어줍니다. if 함수 안에 있는 코드이므로 따로 '..' (작은따옴표)나 {..} (XE에서 변수를 출력하는 부분)을 지워주세요.
자, 이제 본격적으로 이걸 잘 쓰기 위해서는...
처음 마켓플레이스에 여성의류를 선택하면 이렇게 남성의류까지 다 같이 나옵니다.
이걸 여성의류만 선택하면 여성의류 포함 하위 카테고리만 나타나고, 다시 하위 카테고리를 선택하면 그 하위 카테고리가 출력되는 작업을 해보겠습니다.
갈 길이 머네요..
그럼 이제 코드를 작성하러 다녀오겠습니다. 다음 기회에 또 봐요.
P.S. PHP에 대한 지식이 얕아 잘못된 정보가 있을 수 있습니다.
잘못된 정보는 댓글 또는 메일(eond@eond.com)로 본 URL과 잘못된 내용을 알려주시면 감사하겠습니다.
참조글
http://www.xeschool.com/xe/xenote_useful_variable_logged_info
http://php.net/manual/kr/language.types.boolean.php
XE DEBUG - 디버깅을 위한 기초함수
http://www.xeschool.com/xe/index.php?mid=documents_for_debug&entry=%EB%94%94%EB%B2%84%EA%B9%85%EC%9D%84+%EC%9C%84%ED%95%9C+%EA%B8%B0%EC%B4%88%ED%95%A8%EC%88%98
본 글은 마켓플레이스 모듈에서 상위 카테고리의 선택 여부를 구분하고자 할 때 사용하는 팁입니다. 조금 더 설명하자면 2차 메뉴가 여성의류이고, 3차 메뉴가 상의, 하의 등일 경우 3차를 선택했을 경우 2차 메뉴가 seleted 된 상태인지 여부를 구분하고자 할 때 사용 할 수 있습니다. 제가 삽질한 코드는 다음과 같습니다. -_-; 새벽 내내 수백번 고쳐적은 듯;; <pre> {print_...