<?php
namespace Lm\Engine\EC\Entity;
use Lm\Service\Cache\CacheService;
use Lm\Service\Db\SqlService;
class CategoryWithRelated extends CategoryExtended
{
const ITEMS_PER_PAGE = 50;
const no_display_db_category_list = [
'work',
// 'hakui',
// 'food-uniform',
// 'esthe-uniform',
// 'care-wear'
];
/**
* @var string[]
*/
protected $metaTags;
/**
* @var string
*/
protected $title;
/**
* @var string
*/
protected $titleForItemList;
/**
* @var string
*/
protected $titleContent;
/**
* @var string
*/
protected $h1Content;
/**
* @var string
*/
protected $mainH1Content;
/**
* @var string
*/
protected $categoryH1Content;
/**
* @var string
*/
protected $h2Content;
/**
* @var string
*/
protected $mainH2Content;
/**
* @var string
*/
protected $categoryH2Content;
/**
* @var string[]
*/
protected $contentsBlockMap;
/**
* @var string[]
*/
protected $topContentsList;
/**
* @var string[]
*/
protected $bottomContentsList;
/**
* @var array
*/
protected $breadcrumbs;
/**
* @var array
*/
protected $columnList;
/**
* @var string
*/
protected $upperColumn;
/**
* @var string
*/
protected $comment;
/**
* @var string
*/
protected $smallFooterContent;
/**
* @var string
*/
protected $largeFooterContent;
/**
* @var array
*/
protected $categoryTopInfo;
/**
* @var array
*/
protected $itemList;
/**
* @var int
*/
protected $itemListCount;
/**
* @var CategoryWithRelated
*/
protected $canonicalMainCategory;
/**
* @var array
*/
protected $canonicalSubCategoryList;
/**
* @var array
*/
protected $subCategoryList;
public function getMetaTags()
{
return self::compute($this->metaTags, function () {
//
return [
'title' => $this->getTitleTag(),
'description' => $this->getMetaDescription(),
'keywords' => $this->getMetaKeywords(),
];
});
}
public function getTitleTag()
{
$title = "";
if ($this->isMainCategory()) {
if ($title = $this->getMainTitleTag()) {
return $title;
} else if ($title = $this->getMainCategoryName()) {
return "{$title}の通販|ユニフォームタウン";
}
} else if ($this->isSubCategory()) {
if ($title = $this->getCategoryTitleTag()) {
return $title;
} else if (($title = $this->getCategoryName()) === '全商品') {
return "{$this->getMainCategoryname()}({$title})の通販|ユニフォームタウン";
} else if ($title = $this->getCategoryname()) {
return "{$title}の通販|ユニフォームタウン";
}
}
return $title;
}
public function getMetaDescription()
{
$description = "";
if ($this->isMainCategory()) {
if ($description = $this->getMainDescriptionTag()) {
return $description;
} else if ($description = $this->getMainCategoryName()) {
// TODO: マジックナンバー: 9900
return "{$description}について。ユニフォームタウン【公式サイト】は、1ヶ月貸出サンプルや自動見積りが可能な総合ユニフォームの通販専門ショップです。商品代金9900円(税込)以上で送料・代引手数料0円キャンペーン実施中!";
}
} else if ($this->isSubCategory()) {
if ($description = $this->getCategoryDescriptionTag()) {
return $description;
} else if ($description = $this->getMainCategoryname()) {
return "{$description}の商品一覧。ユニフォームタウン【公式サイト】は、1ヶ月貸出サンプルや自動見積りが可能な総合ユニフォームの通販専門ショップです。商品代金9900円(税込)以上で送料・代引手数料0円キャンペーン実施中!";
}
}
return $description;
}
public function getMetaKeywords()
{
$keywords = "";
if ($this->isMainCategory()) {
if ($keywords = $this->getMainKeywordTag()) {
return $keywords;
}
} else if ($this->isSubCategory()) {
if ($keywords = $this->getCategoryKeywordTag()) {
return $keywords;
}
}
return $keywords;
}
public function getTitle()
{
return self::compute($this->title, function () {
//
return $this->isMainCategory() ? $this->getMainCategoryName() : $this->getCategoryName();
});
}
public function getTitleForItemList()
{
return self::compute($this->titleForItemList, function () {
//
return $this->getH2Content();
});
}
public function getTitleContent()
{
return self::compute($this->titleContent, function () {
//
if ($this->isMainCategory()) {
if ($this->isMobile()) {
$content = $this->getMainTitleSpText();
}
if (empty($content)) {
$content = $this->getMainTitleText();
}
} else {
if ($this->isMobile()) {
$content = $this->getCategoryTitleSpText();
}
if (empty($content)) {
$content = $this->getCategoryTitleText();
}
}
//
return $content;
});
}
public function getH1Content()
{
return self::compute($this->h1Content, function () {
//
return $this->isMainCategory() ? $this->getmainH1Content() : $this->getCategoryH1Content();
});
}
public function getMainH1Content()
{
return self::compute($this->mainH1Content, function () {
//
return $this->getMainH2Tag() ?: $this->getMainCategoryName();
});
}
public function getCategoryH1Content()
{
return self::compute($this->categoryH1Content, function () {
//
return $this->getCategoryH2Tag() ?: $this->getCategoryName();
});
}
public function getH2Content()
{
return self::compute($this->h2Content, function () {
//
return $this->isMainCategory() ? $this->getmainH2Content() : $this->getCategoryH2Content();
});
}
public function getMainH2Content()
{
return self::compute($this->mainH2Content, function () {
//
return $this->getMainH3Tag() ?: $this->getMainCategoryName();
});
}
public function getCategoryH2Content()
{
return self::compute($this->categoryH2Content, function () {
//
return $this->getCategoryH3Tag() ?: $this->getCategoryName();
});
}
public function getTopContentsList()
{
return self::compute($this->topContentsList, function () {
//
$indexList = [
'' => 1,
2 => 2,
3 => 3,
4 => 4,
5 => 5,
6 => 6,
7 => 7,
8 => 8,
9 => 9,
10 => 10,
11 => 11,
12 => 12
];
$number = 2;
//
return $this->_getContentsList($number, $indexList);
});
}
/**
* @var string
*/
public function getBottomContentsList()
{
return self::compute($this->bottomContentsList, function () {
//
$indexList = [''];
$number = 3;
//
return $this->_getContentsList($number, $indexList);
});
}
public function getUrl2Content($number)
{
return $this->getCached(function () use ($number) {
//
$content = null;
//
$indexList = [
1 => '',
2 => 2,
3 => 3,
4 => 4,
5 => 5,
6 => 6,
7 => 7,
8 => 8,
9 => 9,
10 => 10,
11 => 11,
12 => 12,
];
//
$prefix = $this->isMainCategory() ? 'main_category' : 'category';
$index = $indexList[$number];
//
if ($this->isMobile()) {
$content = $this->data["{$prefix}_url2_sp_content{$index}"];
}
//
if (empty($content)) {
$content = $this->data["{$prefix}_url2_content{$index}"];
}
//
return $content;
}, null, CacheService::CACHE_INSTANCE);
}
protected function _getContentsList($number, $indexList, $withContentBlock = true)
{
//
$contentsList = [];
$prefix = $this->isMainCategory() ? 'main_category' : 'category';
$device = $this->isMobile() ? '_sp' : '';
// $number: 2 = 上部差込
if ($number === 2 && $withContentBlock) {
//
$contentsBlockMap = $this->getContentsBlockMap();
}
//
foreach ($indexList as $key => $index) {
// コンテンツブロック
if ((isset($contentsBlockMap[$key]) && $contents = $contentsBlockMap[$key])
|| (isset($contentsBlockMap[$index]) && $contents = $contentsBlockMap[$index])) {
//
$contentsList = array_merge($contentsList, $contents);
}
// 差込
if ((isset($this->data["{$prefix}_url{$number}{$device}_content{$key}"]) && $contents = $this->data["{$prefix}_url{$number}{$device}_content{$key}"])
|| (isset($this->data["{$prefix}_url{$number}{$device}_content{$index}"]) && $contents = $this->data["{$prefix}_url{$number}{$device}_content{$index}"])) {
$contentsList[] = $contents;
}
}
//
return $contentsList;
}
public function getContentsBlockMap()
{
return self::compute($this->contentsBlockMap, function () {
//
return $this->getContentsBlockMapById($this->getMainCategoryId(), $this->getCategoryId());
});
}
public static function getContentsBlockMapById($main_category_id, $category_id = null)
{
return (new CategoryContentsBlockMapModel())
->getContentsBlockMapById($main_category_id, $category_id)
;
}
/**
* @return CategoryWithRelated
* @throws \Exception
*/
public function getCanonicalMainCategory()
{
//
return self::compute($this->canonicalMainCategory, function () {
//
if ($this->hasMainCategoryMainCategory()) {
//
return new CategoryWithRelated($this->getMainCategorymainCategoryWebname());
} else {
//
return $this;
}
});
}
public function getCanonicalMainCategoryWebname()
{
//
return $this->getCached(function () {
//
$webnames = [];
//
if ($webname = $this->getMainCategoryMainCategoryWebname()) {
$webnames[] = $webname;
}
//
if ($webname = $this->getMainCategoryWebname()) {
$webnames[] = $webname;
}
//
$result = $webnames;
$result = implode('/', $result);
//
return $result;
}, null, CacheService::CACHE_INSTANCE);
}
public function getCanonicalWebname()
{
//
return $this->getCached(function () {
//
$webnames = [];
//
if ($webname = $this->getCanonicalMainCategoryWebname()) {
$webnames[] = $webname;
}
//
if ($this->isSubCategory() && $webname = $this->getCategoryWebname()) {
$webnames[] = $webname;
}
//
$result = $webnames;
$result = implode('/', $result);
//
return $result;
});
}
public function getCanonicalSubCategoryList()
{
//
return self::compute($this->canonicalSubCategoryList, function () {
//
$mainCategoryId = $this->getCanonicalMainCategory()->getMainCategoryId();
//
return self::getSubCategoryListByMainCategoryId($mainCategoryId);
});
}
public function getSubCategoryList()
{
//
return self::compute($this->subCategoryList, function () {
//
$mainCategoryId = $this->getMainCategoryId();
//
return self::getSubCategoryListByMainCategoryId($mainCategoryId);
});
}
public static function getSubCategoryListByMainCategoryId($mainCategoryId)
{
$strSql = "SELECT ct.*, ru.*
FROM (
SELECT category_id, category_name, category_display, category_main_category, category_status, 0 AS leftmenu_flg, category_cdate, category_udate, null AS leftmenu_category_id, null AS leftmenu_category_bgcolor,
category_url, category_50on, category_50on_display, category_comment, category_url2, category_url2_content, category_url3_content, category_category, category_main,
category_title_tag, category_description_tag, category_keyword_tag, category_h1_tag, category_webname, category_menuname, category_pagebottom, category_bottomlink,
category_breadcrumb, category_footer_link_name, category_footer_link_url, category_header_text, category_title_text, category_pageviews, category_is_hinban_link, category_hinban_link_bgcolor,
COUNT(DISTINCT goods_id) AS `cnt`
FROM category_table
LEFT JOIN goods_category_table ON category_id = gc_category
LEFT JOIN goods_table ON goods_id = gc_goods AND goods_ddate IS NULL AND goods_status = 1
WHERE category_main_category = :main_category_id AND category_status = 1
GROUP BY category_id
UNION SELECT null, leftmenu_category_name, leftmenu_category_display, leftmenu_category_main_category, leftmenu_category_status, 1 AS leftmenu_flg, leftmenu_category_cdate, leftmenu_category_udate, leftmenu_category_id, leftmenu_category_bgcolor,
null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null,
null AS `cnt`
FROM leftmenu_category_table
WHERE leftmenu_category_main_category = :main_category_id AND leftmenu_category_status = 1
) AS ct
INNER JOIN main_category_table AS mc ON main_category_id = category_main_category
LEFT JOIN (
SELECT ru_uri_before, ru_uri_after
FROM redirect_url_table
WHERE ru_type = '0'
GROUP BY ru_uri_before
) AS ru ON ru_uri_before = CONCAT('/', main_category_webname, '/', category_webname, '/')
order by isnull( category_display ), category_display, isnull( category_50on_display ), cast( category_50on as binary ), category_id desc";
$rs = (new SqlService())
->Sql($strSql)
->Param('main_category_id', $mainCategoryId)
->FetchAll()
;
$subCategoryList = array();
if (isset($rs)) {
foreach ($rs AS $row) {
if ($row['category_id'] == '') {
$subCategoryList['leftmenu' . $row['leftmenu_category_id']] = $row;
} else {
$subCategoryList[$row['category_id']] = $row;
}
}
}
return $subCategoryList;
}
/**
* @param $ct
* @param $mc
* @param $mcMc
* @return array
*/
public function getBreadCrumbs()
{
return self::compute($this->breadcrumbs, function () {
//
$breadCrumbs = [];
//
$category = $this->data;
//
$conf = [];
if ($webname = $this->getCategoryWebname()) {
$conf[] = [
'f' => $webname,
'fn' => $this->getCategoryBreadcrumb() ?: $this->getCategoryName(),
];
}
if ($webname = $this->getMainCategoryWebname()) {
$conf[] = [
'f' => $webname,
'fn' => $this->getMainBreadcrumb() ?: $this->getMainCategoryName(),
];
}
if ($webname = $this->getMainCategoryMainCategoryWebname()) {
$conf[] = [
'f' => $webname,
'fn' => $this->getCanonicalMainCategory()->getMainBreadcrumb() ?: $this->getCanonicalMainCategory()->getMainCategoryName(),
];
}
//
foreach ($conf as $i => $obj) {
for ($j = 0; $j <= $i; $j++) {
if (!empty($obj['f'])) {
if (!isset($breadCrumbs[$i]['label'])) {
$breadCrumbs[$i]['label'] = $obj['fn'];
}
if (!isset($breadCrumbs[$j]['href'])) {
$breadCrumbs[$j]['href'] = "/{$obj['f']}";
} else {
$breadCrumbs[$j]['href'] = "/{$obj['f']}{$breadCrumbs[$j]['href']}";
}
}
}
//
if (!empty($breadCrumbs[$i]['href'])) {
$breadCrumbs[$i]['href'] = "{$breadCrumbs[$i]['href']}/";
}
}
//
$breadCrumbs = array_reverse($breadCrumbs);
//
return $breadCrumbs;
});
}
public function getRelatedColumnList()
{
return self::compute($this->columnList, function () {
//
$mainCategoryId = $this->getMainCategoryId();
$categoryId = $this->getCategoryId();
//
return self::getColumnListById($mainCategoryId, $categoryId);
});
}
/**
* @param int $mainCategoryId
* @param int|null $categoryId
* @return array|null
*/
public static function getColumnListById($mainCategoryId, $categoryId = null)
{
$query = (new SqlService())
->Select('T.main_category_webname, T2.category_webname, T1.*')
->Table('main_category_table')
->Join('column_table', 'T.main_category_id = T1.column_main_category', 'INNER')
->Set('T.main_category_id', $mainCategoryId)
->Where('T.main_category_status = 1')
->Where('T1.column_status = 1')
->Where("T1.column_related_image_filename != ''")
->OrderBy('isnull(T1.column_display), T1.column_display, T1.column_id desc')
;
//
if ($categoryId === null) {
// 親カテゴリの場合
$query
->Join('category_table', 'T2.category_id = :category_id', 'LEFT') // 擬似的に空のカテゴリ一覧を結合
->Param('category_id', $categoryId)
->Where("T1.no_display_in_main_category = 0")
;
} else {
// 子カテゴリの場合
$query
->Join('category_table', 'T.main_category_id = T2.category_main_category', 'LEFT')
->Join('category_relation_to_display_column_table', 'T1.column_id = T3.column_id AND T2.category_id = T3.category_id', 'LEFT')
->Set("T2.category_id", $categoryId)
->Where("T2.category_status = 1")
;
}
//
$result = (array)$query->FindAll();
//
foreach($result as &$row){
// 管理画面上「URL」と表記のある入力
if( is_null($row['column_target_category']) ){
$row['uri'] = '/'.$row['main_category_webname'].'/column/'.$row['column_webname'].'/';
}
else{
$row['uri'] = '/'.$row['main_category_webname'].'/'.$row['category_webname'].'/column/'.$row['column_webname'].'/';
}
}
//
return $result;
}
public function getUpperColumn()
{
return self::compute($this->upperColumn, function () {
//
$query = (new SqlService())
->Select('upper_one_column_content')
->Table('upper_column_table')
->Join('main_category_table', "T.target_category_id = T1.main_category_id AND site_type = :site_type", 'LEFT')
->Set('T1.main_category_id', $this->geTMainCategoryId())
->Param('site_type', $this->getSiteType())
;
//
if ($result = $query->Find()) {
//
$result = $result['upper_one_column_content'];
}
//
return $result;
});
}
/**
* @return string
*/
public function getComment()
{
return self::compute($this->comment, function () {
//
return $this->isMainCategory() ? $this->getMainCategoryComment() : $this->getCategoryComment();
});
}
/**
* @return string
*/
public function getSmallFooterContent()
{
return self::compute($this->smallFooterContent, function () {
//
if ($this->isShowSmallFooter()) {
return $this->getMainCategorySmallFooterContent();
} else {
return null;
}
});
}
/**
* @return string
*/
public function getLargeFooterContent()
{
return self::compute($this->largeFooterContent, function () {
//
return $this->getMainCategoryLargeFooterContent();
});
}
/**
* @return array
*/
public function getCategoryTopInfo()
{
return self::compute($this->categoryTopInfo, function () {
//
$categoryTopInfo = [];
//
if ($this->hasMainCategoryMainCategory()) {
// 配下親カテゴリ有り
$categoryTopInfo['webname'] = $this->getMainCategoryMainCategoryWebname();
$categoryTopInfo['name'] = $this->getMainCategoryMainCategoryName();
} else if ($this->hasMainCategories()) {
// 配下親カテゴリ自身
$categoryTopInfo['webname'] = $this->getMainCategoryWebname();
$categoryTopInfo['name'] = $this->getMainCategoryName();
} else {
// それ以外
return null;
}
//
return $categoryTopInfo;
});
}
public function getItemList($page = null, $itemsPerPage = null, $params = null)
{
//
return self::compute($this->itemList, function () use ($page, $itemsPerPage, $params) {
//
$mcId = $this->getMainCategoryId();
$ctId = $this->getCategoryId() ?: 'allitem';
//
return $this->_getItemList($mcId, $ctId, $page, $itemsPerPage, $params, $this->itemListCount);
});
}
public function getItemListCount()
{
//
return self::compute($this->itemListCount, function () {
//
$this->getItemList();
//
return $this->itemListCount;
});
}
public function _getItemList($mcId, $ctId, $page, $itemsPerPage, $params, &$count = null)
{
//
if (empty($page)) {
$page = 1;
}
//
if (empty($itemsPerPage)) {
$itemsPerPage = self::ITEMS_PER_PAGE;
}
//
if (empty($params)) {
$params = [];
}
//
$an_search_base_color_list = array();
if (!empty($params['search_base_color_list'])) {
}
// サイズで選ぶ
$an_search_size_list = array();
if (!empty($params['search_size_list'])) {
}
// 種類で選ぶ
$an_search_type_list = array();
if (!empty($params['search_type_list'])) {
}
$strSQLWhere = '';
$search_goods_id = array_unique($an_search_base_color_list + $an_search_size_list + $an_search_type_list);
if (is_array($search_goods_id) && $search_goods_id) {
$strSQLWhere .= ' AND goods_id in (' . implode(',', $search_goods_id) . ')';
}
$strSQLGroup = " group by goods_id";
// 金額で選ぶ
$strSQLHaving = '';
if (!empty($params['price_range_start']) || !empty($params['price_range_end'])) {
$price_range_start = $params['price_range_start'];
$price_range_end = $params['price_range_end'];
$strSQLHaving = ' HAVING ';
// 「範囲」検索
if ($price_range_start != "" && $price_range_end != "") {
$strSQLHaving .= ' price >= ' . $price_range_start . ' AND price <= ' . $price_range_end;
} else if ($price_range_start != "") {
$strSQLHaving .= ' price >= ' . $price_range_start;
} else if ($price_range_end != "") {
$strSQLHaving .= ' price <= ' . $price_range_end;
}
}
if ($ctId != "allitem") {
$search_category = $this->_getOriginalCategory($ctId);
} else {
$search_category = $this->_getOriginalCategory_Main($mcId);
}
$mcConditions = '';
$ctConditions = '';
$sqlParams = [];
if (!empty($mcId)) {
$mcConditions = " AND main_category_id = :main_category_id";
$sqlParams['main_category_id'] = $mcId;
}
if (!empty($search_category)) {
$placeholders = [];
foreach (explode(',', $search_category) as $k => $v) {
$key = "category_id_{$k}";
$placeholders[] = ":{$key}";
$sqlParams[$key] = $v;
}
$ctConditions = " AND category_id IN (".implode(',', $placeholders).")";
}
// ユニフォームネクストの商品掲載順を使用(おすすめとして扱う)
$use_recommended_order = $this->useUnItemOrder($mcId, $ctId);
$join_item_recommended_order = '';
if($use_recommended_order && !empty($params['order_type']) && $params['order_type'] == "6") {
$recommended_order_where_clause = 'main_category_id = %d';
if( !empty($this->ctId) && strtolower($this->ctId) !== 'allitem' ){
$recommended_order_where_clause .= ' AND category_id = %d';
}
else{
$recommended_order_where_clause .= ' AND category_id IS NULL';
}
$join_item_recommended_order = sprintf("
LEFT JOIN(
SELECT
goods_id,
is_un_order,
display_order
FROM
goods_recommended_order_table
WHERE
{$recommended_order_where_clause}
) AS recommended_order
USING(goods_id)
",
$mcId,
$ctId
);
}
/***** 商品情報取得(メイン) *****/
$strSQL = "select SQL_CALC_FOUND_ROWS goods_id, goods_recommend, goods_name, goods_sub_name, goods_caption, goods_display, goods_cdate, goods_udate, price2_min as price, kataban, NULL AS category_id, COALESCE(cra_average_points, 0) AS average, cra_target_count as review_count, goods_target_gender, goods_category_list_icon_id
from (
select goods_id, goods_recommend, goods_name, goods_sub_name, goods_caption, goods_display, goods_cdate, goods_udate, goods_target_gender, goods_category_list_icon_id,
main_category_id, category_id
from main_category_table
inner join category_table on main_category_id = category_main_category
inner join goods_category_table on category_id = gc_category
inner join goods_table on goods_id = gc_goods
where 1 = 1{$mcConditions}{$ctConditions} AND goods_ddate is null and goods_status = 1
union
select goods_id, goods_recommend, goods_name, goods_sub_name, goods_caption, goods_display, goods_cdate, goods_udate, goods_target_gender, goods_category_list_icon_id,
main_category_id, null as category_id
from main_category_table
inner join goods_main_category_table on main_category_id = gmc_main_category
inner join goods_table on goods_id = gmc_goods
where 1 = 1{$mcConditions} AND goods_ddate is null and goods_status = 1
) AS goods
inner join goods_price_summary USING( goods_id )
left join sales_volume_rank_table USING( goods_id )
left join customer_review_average_table on cra_goods_id = goods_id
{$join_item_recommended_order}
WHERE 1 = 1{$mcConditions}";
if( strtolower($ctId) !== 'allitem' ) $strSQL .= $ctConditions;
$strSQL .= $strSQLWhere . $strSQLGroup . $strSQLHaving;
if ( !empty($params['order_type']) and $params['order_type'] == "1" ) {
//安い順
$strSQL .= " order by price, goods_recommend desc ";
} elseif ( !empty($params['order_type']) and $params['order_type'] == "3" ) {
//高い順
$strSQL .= " order by price desc, goods_recommend desc ";
} elseif ( !empty($params['order_type']) and $params['order_type'] == "4" ) {
//品名順
// $strSQL .= " order by cast( goods_name as binary ), goods_recommend desc ";
$strSQL .= " order by goods_recommend desc ";
} elseif ( !empty($params['order_type']) and $params['order_type'] == "2" ) {
//品番順
$strSQL .= " order by kataban, goods_recommend desc ";
} elseif ( !empty($params['order_type']) and $params['order_type'] == "5" ) {
// 評価順
$strSQL .= " order by average desc, review_count desc,goods_recommend desc ";
} elseif ( !empty($params['order_type']) and $params['order_type'] == "6" and $use_recommended_order) {
// おすすめ順(ユニフォームネクストの商品掲載順)
// ユニフォームネクストと紐付きのない商品は、「ウェブスクレイピング画面で設定した順 > goods_id順’で表示
$strSQL .= " order by is_un_order DESC, display_order IS NULL ASC, display_order ASC, goods_id";
} else {
$strSQL .= " order by isnull( quantities ), quantities DESC, goods_recommend desc, price, isnull( goods_display ), goods_display, goods_udate desc, goods_cdate desc ";
}
$result = (array)((new SqlService())
->Sql($strSQL)
->Limit($itemsPerPage, ($page - 1) * $itemsPerPage)
->Params($sqlParams)
->FetchAll())
;
$count = (int)call_user_func(function ($result) {
return $result['count'];
}, (new SqlService())
->Sql('SELECT FOUND_ROWS() AS `count`')
->Fetch());
return $result;
}
public function _getOriginalCategory_Main($id)
{
$rs = (new SqlService())
->Table('category_table')
->Set('category_main_category', $id)
->Select("category_id, category_category, category_main")
->FindAll() ?: [];
$all_category = "";
foreach ($rs as $row) {
if ( $all_category != "" ) $all_category .= ",";
$all_category .= $this->_getOriginalCategory($row['category_id'], $row);
}
return $all_category;
}
public function _getOriginalCategory($id, $tmpRow = null)
{
if($tmpRow === null) {
$row = (new SqlService())
->Table('category_table')
->Set('category_id', $id)
->Select("category_id, category_category, category_main")
->Find();
} else {
$row = $tmpRow;
}
if ($row) {
//カテゴリが共有されている場合の処理
if ( $row['category_category'] != "" ) {
$all_category = $row['category_category'];
} elseif ( $row['category_main'] != "" ) {
$strSQL = "select coalesce( category_category, category_id ) as cid, category_main
from category_table
where category_main_category = " . $row['category_main'] . " and category_main is null";
$tempRow = (new SqlService())->Sql($strSQL)->FetchAll();
foreach ($tempRow as $row) {
if ( $all_category != "" ) $all_category .= ",";
$all_category .= $row['cid'];
}
} else {
$all_category = $id;
}
} else {
$all_category = $id;
}
return $all_category;
}
public function useUnItemOrder($mcId = null, $ctId = null)
{
if( empty($mcId) ) return false;
$category_id = $mcId;
$is_parent = 1;
// 子カテの指定がある場合
if( !empty($ctId) && strtolower($ctId) !== 'allitem' ){
$category_id = $ctId;
$is_parent = 0;
}
$rows = (new SqlService())
->Table('uniform_next_category_map_table')
->Set('lm_category_id', $category_id)
->Set('is_parent', $is_parent)
->Set('use_un_order', 1)
->FetchAll();
return !empty($rows);
}
public function getDataBySql($sql)
{
return (new SqlService())->Sql($sql)->FetchAll();
}
/**
* @return bool
*/
public function isNoDisplayDbCategory(){
// SEO対策 特定の親カテは商品DBを表示しない
return in_array($this->getMainCategoryWebname(), self::no_display_db_category_list);
}
}