<?php
/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Customize\Controller;
use Customize\Controller\LM\LmAbstractController;
use Customize\Entity\CacheTrait;
use Customize\Service\CategoryService;
use Customize\Service\GoodsService;
use Customize\Service\LmHelper;
use Customize\Service\PageService;
use Eccube\Common\Constant;
use Lm\Engine\EC\Entity\CategoryWithRelated;
use Customize\Service\MobileDetector as LmMobileDetector;
use Symfony\Component\Cache\CacheItem;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Lm\Service\Db\SqlService;
use Customize\Service\CommonService;
use Customize\Converter\DynamicConverter;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Eccube\Common\EccubeConfig;
class PageController extends LmAbstractController
{
use CacheTrait;
const PREFIX_CACHE = "PAGE_CONTROLLER_";
const MAIN_CATEGORY_GROUPS_UNABLE_SHOW = [7,8];
/**
* @var LmMobileDetector $MobileDetector
*/
protected $MobileDetector;
protected $dynamicConverter;
protected $session;
protected $CategoryService;
protected $GoodsService;
/**
* @var EccubeConfig
*/
protected $eccubeConfig;
private $cacheLifeTime;
public function __construct(CommonService $commonService,
LmHelper $lmHelper,
LmMobileDetector $mobileDetector,
DynamicConverter $dynamicConverter,
SessionInterface $session,
EccubeConfig $eccubeConfig,
CategoryService $categoryService,
GoodsService $goodService
) {
//
parent::__construct($commonService, $lmHelper);
//
$this->MobileDetector = $mobileDetector;
$this->dynamicConverter = $dynamicConverter;
$this->session = $session;
$this->eccubeConfig = $eccubeConfig;
$this->CategoryService = $categoryService;
$this->GoodsService = $goodService;
$this->cacheLifeTime = $this->eccubeConfig->get("eccube_result_cache_lifetime") ?? Constant::ONE_HOUR;
}
/**
* @param Request $request
* #Route("/page/{mc}", requirements={"mc" = "\w+"}, name="page/main-category", methods={"GET"})
* @Template("Page/sub-category.twig")
*/
protected function _mainCategory(Request $request, $mc, $mcMc = null)
{
//
$request->attributes->set('_route', 'page/main-category');
$request->attributes->set('mc', $mc);
$request->attributes->set('mcMc', $mcMc);
//
return $this->newCategory($request, $mc, null, $mcMc, function ($category) use ($request, $mc, $mcMc) {
//
return $this->__mainCategory($request, $category, $mc, $mcMc);
});
}
protected function __mainCategory(Request $request, CategoryWithRelated $category, $mc, $mcMc = null)
{
//
$sql = new SqlService();
//
$data = $sql->Table('landmark01.main_category_table')
->Set('main_category_webname', $mc)
->Find();
// モバイルの判定
$isMobile = $this->MobileDetector->isMobile();
# Author Description Keyword Robots MetaTags
$Metatage = ['Author' => 'ああああ', 'Description' => 'いいい'];
// $this->CommonService->WriteYml(['hoge' => 'piyo'], 'hogehoge.yml');
//
$review = $this->dynamicConverter->getReview(null, false, $data['main_category_id']);
$columnList = [
[
'uri' => '/',
'column_custom_url' => '/custom_url',
'main_category_webname' => 'work',
'column_webname' => 'sagyogi-fashionable',
'column_related_image_filename' => 'kanren.jpg ',
'column_related_image_alt' => 'ユニフォーム通販TOP',
'column_name' => 'ユニフォーム通販TOP',
'column_related_link_text' => 'ユニフォーム通販TOP',
'column_h1_tag' => 'ユニフォーム通販TOP'
],
[
'uri' => '/',
'column_custom_url' => '/custom_url',
'main_category_webname' => 'work',
'column_webname' => 'sagyogi-fashionable',
'column_related_image_filename' => 'kanren.jpg ',
'column_related_image_alt' => 'ユニフォーム通販TOP',
'column_name' => 'ユニフォーム通販TOP',
'column_related_link_text' => 'ユニフォーム通販TOP',
'column_h1_tag' => 'ユニフォーム通販TOP'
]
];
$upperColumnData = $this->dynamicConverter->getByCategoryWebName(1, $mc);
// TODO: canonicalMcDataを取得
$canonicalMcData = null;
$categoryData = $this->dynamicConverter->getMainCategoryName($mc);
$categoryData['main_category'] = $data;
$categoryData = $this->dynamicConverter->getMainCategoryName($mc);
if (!empty($data['main_category_main_category'])) {
$subCategoryList = $this->dynamicConverter->getSubCategoryList($data['main_category_main_category']);
} else if (isset($categoryData) && intval($categoryData['category_group_only_main']) == 1) {
$subCategoryList = [];
} else {
$subCategoryList = $this->dynamicConverter->getSubCategoryList($data['main_category_id']);
}
$BreadCrumbs = [
// [
// 'label' => $data['main_category_main_category_name'],
// 'href' => "/{$data['main_category_main_category_webname']}",
// ],
[
'label' => $data['main_category_name'],
'href' => "{$data['main_category_main_category_webname']}/{$data['main_category_webname']}",
],
// [
// 'label' => $categoryData['category_name'],
// 'href' => "/{$data['main_category_main_category_webname']}/{$data['main_category_webname']}/{$categoryData['category_webname']}",
// ],
];
$mcMcName = $mc;
$mcName = $mc;
$ctName = 'allItem';
$ctId = 'allitem';
$mcId = $data['main_category_id'];
$orderType = $this->session->has('order_type') ? $this->session->get('order_type') : $request->get('type');
$display_item_count_list = $this->CommonService->GetYaml('DisplayItem.yaml');
$displayMax = $this->session->has('display_max') ? intval($this->session->get('display_max')) : intval($request->get('disp'));
if ($displayMax == $display_item_count_list['DISPLAY_ITEM_COUNT']['LOW']) {
$max_display_cnt = $display_item_count_list['DISPLAY_ITEM_COUNT']['LOW'];
} else if ($displayMax == $display_item_count_list['DISPLAY_ITEM_COUNT']['HIGH']) {
$max_display_cnt = $display_item_count_list['DISPLAY_ITEM_COUNT']['HIGH'];
} else if ($displayMax == $display_item_count_list['DISPLAY_ITEM_COUNT_DEFAULT']) {
$max_display_cnt = $display_item_count_list['DISPLAY_ITEM_COUNT_DEFAULT'];
} else {
$max_display_cnt = $display_item_count_list['DISPLAY_ITEM_COUNT_DEFAULT'];
}
$dataItem = "";
$dataItem = $this->_getDataItem($request, $mcId, $ctId, $mcName, $ctName, $max_display_cnt, $item_count); // data['item']
$detailData = array();
$detailData['item_count'] = $item_count;
// $detailData['item_count'] = count($dataItem);
$detailData['item'] = $dataItem;
//var_dump($detailData['item']);
$detailData['pager_pages_current_num'] = 0;
$detailData['col_count'] = $isMobile ? 2 : 3;
$detailData['max_display_cnt'] = $max_display_cnt;
if (!empty($request->get('no')) && intval($request->get('no')) > 0) {
$detailData['min_cnt'] = min((intval($request->get('no')) + 1), $detailData['item_count']);
} else {
$detailData['min_cnt'] = min(1, $detailData['item_count']);
}
$detailData['max_cnt'] = min($detailData['min_cnt'] + $detailData['max_display_cnt'] - 1, $detailData['item_count']);
for ($i = 1; $i <= $detailData['item_count']; $i += $detailData['max_display_cnt']) {
if ($detailData['min_cnt'] >= $i and $detailData['max_cnt'] <= ($i + $detailData['max_display_cnt'])) {
$detailData['pager_pages_current_num'] = intval($i / $detailData['max_display_cnt']) + 1;
}
}
$an_sort = array();
for ($i = 0; $i < $detailData['item_count']; $i++) {
$an_sort["$i"] = $i;
}
$i = 0;
foreach ($an_sort as $k => $v) {
// $an_v[$i] = $k;
$an_v[$i] = $i;
$i++;
}
$detailData['an_v'] = $an_sort;
$main_category_url2_content = $isMobile && $data['main_category_url2_sp_content'] != '' ? $data['main_category_url2_sp_content'] : ($data['main_category_url2_content'] ?? '');
$main_category_url2_content2 = $isMobile && $data['main_category_url2_sp_content2'] != '' ? $data['main_category_url2_sp_content2'] : ($data['main_category_url2_content2'] ?? '');
$main_category_url2_content3 = $isMobile && $data['main_category_url2_sp_content3'] != '' ? $data['main_category_url2_sp_content3'] : ($data['main_category_url2_content3'] ?? '');
$main_category_url2_content4 = $isMobile && $data['main_category_url2_sp_content4'] != '' ? $data['main_category_url2_sp_content4'] : ($data['main_category_url2_content4'] ?? '');
$main_category_url2_content5 = $isMobile && $data['main_category_url2_sp_content5'] != '' ? $data['main_category_url2_sp_content5'] : ($data['main_category_url2_content5'] ?? '');
$main_category_url2_content6 = $isMobile && $data['main_category_url2_sp_content6'] != '' ? $data['main_category_url2_sp_content6'] : ($data['main_category_url2_content6'] ?? '');
$main_category_url2_content7 = $isMobile && $data['main_category_url2_sp_content7'] != '' ? $data['main_category_url2_sp_content7'] : ($data['main_category_url2_content7'] ?? '');
$main_category_url2_content8 = $isMobile && $data['main_category_url2_sp_content8'] != '' ? $data['main_category_url2_sp_content8'] : ($data['main_category_url2_content8'] ?? '');
$main_category_url2_content9 = $isMobile && $data['main_category_url2_sp_content9'] != '' ? $data['main_category_url2_sp_content9'] : ($data['main_category_url2_content9'] ?? '');
$main_category_url2_content10 = $isMobile && $data['main_category_url2_sp_content10'] != '' ? $data['main_category_url2_sp_content10'] : ($data['main_category_url2_content10'] ?? '');
$main_category_url2_content11 = $isMobile && $data['main_category_url2_sp_content11'] != '' ? $data['main_category_url2_sp_content11'] : ($data['main_category_url2_content11'] ?? '');
$main_category_url2_content12 = $isMobile && $data['main_category_url2_sp_content12'] != '' ? $data['main_category_url2_sp_content12'] : ($data['main_category_url2_content12'] ?? '');
// TODO: content2を取得
$content2 = '';
// TODO: content3を取得
$content3 = '';
//TODO: 「関連するページ」リンクの表示
$isItemSeriesCategory = 1;
$isNoDisplayDbCategory = 0;
$detailItemCount = 1;
$categoryGroupNoshowdb = 0;
$breakCountForRankLabel = 1;
$useItemUrlDuplicated = false;
$mainCategoryData = array();
$main_h3 = $data['main_h3_tag'];
$main_breadcrumb = $data['main_breadcrumb'];
// TODO: category_h3を取得
$category_h3 = '';
// TODO: category_h1を取得
$category_h1 = '';
if ($categoryData['category_name'] == "全商品") {
$seoKeyword = $seoKeywordTDK = $categoryData['main_category_name'] . " " . $categoryData['category_name'];
} elseif (in_array($data['main_category_name'], array("メディカルウェア", "エステユニフォーム"))) { // パターンA
$seoKeyword = $categoryData['category_name'];
$seoKeywordTDK = $categoryData['category_name'] . "(" . $data['main_category_name'] . ")";
} elseif (in_array($data['main_category_name'], array("作業服・作業着", "作業服バートル", "医療白衣", "エプロン", "防寒服", "スタッフジャンパー", "シャツ", "ポロシャツ"))) { // パターンB
$seoKeyword = $seoKeywordTDK = $categoryData['category_name'];
} else { // パターンC
$seoKeyword = $seoKeywordTDK = $data['main_category_name'] . " " . $categoryData['category_name'];
}
$useRecommendedItemOrder = $this->dynamicConverter->useUnItemOrder($data['main_category_id']);
if ($mcMc) {
$custom_menu = $this->dynamicConverter->getMainCategoryMenu($mcMc);
} else {
$custom_menu = $this->dynamicConverter->getMainCategoryMenu($mc);
}
$custom_frequently_searched_word = $this->dynamicConverter->getSearchWordGroup($this->eccubeConfig['EditSpMenu']['MENU_NAME_COMMON'], $this->eccubeConfig['EditSpMenu']['BOOL_TRUE']);
$common_header_contents = null;
$recentviews = [];
$isMainCategory = true;
// TODO: ⑧【LM】商品一覧
$is_no_display_db_category = false;
$showItemDb = true;
$useCache = false;
$canonical_category_name = '';
$average = array();
$pager_data = $this->CategoryService->getPagerData(
$category->getCanonicalMainCategoryWebname(),
$ctName,
$detailData['max_display_cnt'],
$detailData['item_count'],
$detailData['min_cnt'],
$detailData['max_cnt'],
$displayMax,
$orderType,
$isMobile
);
// TODO: ⑨【LM】カテゴリ絞り込み(SP)
$isMainOnly = false;
$canonicalSubCategoryList = [];
$leftmenuForCategoryData = [];
$canonicalMcName = $mcName;
$items = array_values(array_map(function($subCategory) {
return [
'category_id' => $subCategory['category_id'] ?? null,
'category_name' => $subCategory['category_name'] ?? null,
'category_main_category' => $subCategory['category_main_category'] ?? null,
'category_category' => $subCategory['category_category'] ?? null,
'category_main' => $subCategory['category_main'] ?? null,
'cnt' => $subCategory['cnt'] ?? null,
'image' => $this->CategoryService->getCategoryImageUrl($subCategory['category_id']),
'goods_image' => $this->CategoryService->getGoodsImageUrlByCatetoryId($subCategory['category_id']),
];
}, $subCategoryList ?? []));
// TODO: ③【LM】共用コンテンツ(SP)のデータ取得
$common_header_contents_all = '<div>
<a style="display: block; width: 100%;" href="/cart/add_catalog">
<picture><source media="(max-width: 320px)" type="image/webp" srcset="https://img0.land-mark.biz/ut_img/public_images_320/smartphone/smp-catalog-2020aw-486x60.webp"><source media="(max-width: 640px)" type="image/webp" srcset="https://img0.land-mark.biz/ut_img/public_images_640/smartphone/smp-catalog-2020aw-486x60.webp"><source type="image/webp" srcset="https://img0.land-mark.biz/ut_img/public_images/smartphone/smp-catalog-2020aw-486x60.webp"><source media="(max-width: 320px)" srcset="https://img0.land-mark.biz/ut_img/public_images_320/smartphone/smp-catalog-2020aw-486x60.jpg"><source media="(max-width: 640px)" srcset="https://img0.land-mark.biz/ut_img/public_images_640/smartphone/smp-catalog-2020aw-486x60.jpg"><img style="width: 100%;" src="https://img0.land-mark.biz/ut_img/public_images/smartphone/smp-catalog-2020aw-486x60.jpg"></picture></a>
</div>
<div>
<a style="display: block; width: 100%;" href="/amazonpay/">
<picture><source media="(max-width: 320px)" type="image/webp" srcset="https://img0.land-mark.biz/ut_img/public_images_320/categorypage/amazonpay/smp-486x60.webp"><source media="(max-width: 640px)" type="image/webp" srcset="https://img0.land-mark.biz/ut_img/public_images_640/categorypage/amazonpay/smp-486x60.webp"><source type="image/webp" srcset="https://img0.land-mark.biz/ut_img/public_images/categorypage/amazonpay/smp-486x60.webp"><source media="(max-width: 320px)" srcset="https://img0.land-mark.biz/ut_img/public_images_320/categorypage/amazonpay/smp-486x60.jpg"><source media="(max-width: 640px)" srcset="https://img0.land-mark.biz/ut_img/public_images_640/categorypage/amazonpay/smp-486x60.jpg"><img style="width: 100%;" src="https://img0.land-mark.biz/ut_img/public_images/categorypage/amazonpay/smp-486x60.jpg"></picture></a>
</div>
<script src="https://ajax.googlevapis.com/ajax/libs/jquery/2.2.4/jquery.2.4.1.min.js"></script>';
$main_category_name = $data['main_category_name'];
$back_to_top_link = !empty($categoryData['main_bottomlink']) ? $categoryData['main_bottomlink'] : $categoryData['main_category_name'];
$category_bottom_text = $categoryData['main_pagebottom'] ?? null;
$mainCategoryGroup = $this->CategoryService->getMainCategoryGroupById($mc);
$mainCategoryData = $this->CategoryService->getMainCategory($mcId);
$isShowCategoryData = false;
if (
!empty($mainCategoryData['category_group_noshowdb']) && !$mainCategoryData['category_group_noshowdb'] &&
(
(!empty($mainCategoryData['main_category_group']) && !in_array($mainCategoryData['main_category_group'], self::MAIN_CATEGORY_GROUPS_UNABLE_SHOW)) ||
$detailData['item_count'] > 0
)
) {
$isShowCategoryData = true;
}
if(!empty($mainCategoryGroup['category_group_only_main']) && $mainCategoryGroup['category_group_only_main']){
$isMainOnly = true;
}
$vendingStatusMap = $this->GoodsService->getGoodsVendingStatusMap();
return [
'data' => $data,
'review' => $review,
'BreadCrumbs' => $BreadCrumbs,
'pager_pages_current_num' => $detailData['pager_pages_current_num'],
'upperColumnData' => $upperColumnData,
'columnList' => $columnList,
'canonicalMcData' => $canonicalMcData,
'categoryData' => $categoryData,
'dataItem' => $dataItem,
'subCategoryList' => $subCategoryList,
'ctName' => $ctName,
'mcName' => $mcName,
'mcMcName' => $mcMcName,
'content2' => $content2,
'content3' => $content3,
'isItemSeriesCategory' => $isItemSeriesCategory,
'isNoDisplayDbCategory' => $isNoDisplayDbCategory,
'detailItemCount' => $detailItemCount,
'categoryGroupNoshowdb' => $categoryGroupNoshowdb,
'detailData' => $detailData,
'main_h3' => $main_h3,
'main_breadcrumb' => $main_breadcrumb,
'seoKeywordTDK' => $seoKeywordTDK,
'category_h3' => $category_h3,
'category_h1' => $category_h1,
'useRecommendedItemOrder' => $useRecommendedItemOrder,
'breakCountForRankLabel' => $breakCountForRankLabel,
'useItemUrlDuplicated' => $useItemUrlDuplicated,
'mainCategoryData' => $mainCategoryData,
'common_header_contents_all' => $common_header_contents_all,
'common_header_contents' => $common_header_contents,
'recentviews' => $recentviews,
'custom_menu' => $custom_menu,
'custom_frequently_searched_word' => $custom_frequently_searched_word,
'isMainCategory' => $isMainCategory,
'is_no_display_db_category' => $is_no_display_db_category,
'showItemDb' => $showItemDb,
'useCache' => $useCache,
'pager_data' => $pager_data,
'max_display_cnt' => $max_display_cnt,
'canonical_category_name' => $canonical_category_name,
'average' => $average,
'isMainOnly' => $isMainOnly,
'isShowCategoryData' => $isShowCategoryData,
'items' => $items,
'canonicalSubCategoryList' => $canonicalSubCategoryList,
'leftmenuForCategoryData' => $leftmenuForCategoryData,
'canonicalMcName' => $canonicalMcName,
'ctId' => $ctId,
'main_category_name' => $main_category_name,
'MetaTags' => ['Category'=> $data ], # 2022/08/03 #kawai
'SubCate' => 0,
'back_to_top_link' => $back_to_top_link,
'category_bottom_text' => $category_bottom_text,
'vendingStatusMap' => $vendingStatusMap,
];
}
/**
* @param Request $request
* @param string $ct
* @param string $mc
* @param string|null $mcMc
* #Route("/page/{mc}/{ct}", requirements={"mc" = "\w+", "ct" = "\w+"}, name="page/sub-category", methods={"GET"})
* @Template("Page/sub-category.twig")
* @return array|\Symfony\Component\HttpFoundation\Response
*/
protected function _subCategory(Request $request, $ct, $mc, $mcMc = null)
{
//
$request->attributes->set('_route', 'page/sub-category');
$request->attributes->set('ct', $ct);
$request->attributes->set('mc', $mc);
$request->attributes->set('mcMc', $mcMc);
//
return $this->newCategory($request, $mc, $ct, $mcMc, function ($category) use ($request, $ct, $mc, $mcMc) {
//
return $this->__subCategory($request, $category, $ct, $mc, $mcMc);
});
}
protected function __subCategory(Request $request, CategoryWithRelated $category, $ct, $mc, $mcMc = null)
{
$data = $this->dynamicConverter->getMainCategoryName($mc);
$data['mcId'] = $data['main_category_id'];
$data['mcName'] = $mc;
if ($ct != 'allitem') {
$subCategoryData = $this->dynamicConverter->getSubCategoryName($data['main_category_id'], $ct);
$data['ctId'] = $subCategoryData['category_id'];
$data['ctName'] = $ct;
} else {
$data['ctId'] = 'allitem';
$data['ctName'] = 'allitem';
}
// モバイルの判定
$isMobile = $this->MobileDetector->isMobile();
# Author Description Keyword Robots MetaTags
$Metatage = ['Author' => 'ああああ', 'Description' => 'いいい'];
$review = isset($data['main_category_id']) ? $this->dynamicConverter->getReview(null, false, $data['main_category_id'], $data['ctId']) : [];
$columnList = [
[
'uri' => '/',
'column_custom_url' => '/custom_url',
'main_category_webname' => 'work',
'column_webname' => 'sagyogi-fashionable',
'column_related_image_filename' => 'kanren.jpg ',
'column_related_image_alt' => 'ユニフォーム通販TOP',
'column_name' => 'ユニフォーム通販TOP',
'column_related_link_text' => 'ユニフォーム通販TOP',
'column_h1_tag' => 'ユニフォーム通販TOP'
],
[
'uri' => '/',
'column_custom_url' => '/custom_url',
'main_category_webname' => 'work',
'column_webname' => 'sagyogi-fashionable',
'column_related_image_filename' => 'kanren.jpg ',
'column_related_image_alt' => 'ユニフォーム通販TOP',
'column_name' => 'ユニフォーム通販TOP',
'column_related_link_text' => 'ユニフォーム通販TOP',
'column_h1_tag' => 'ユニフォーム通販TOP'
]
];
$upperColumnData = $this->dynamicConverter->getByCategoryWebName(1, $mc);
// TODO: canonicalMcDataを取得
$canonicalMcData = null;
$categoryData = $this->dynamicConverter->getCategoryData($data['main_category_id'], $data['category_id']);
$categoryData['main_category'] = $this->dynamicConverter->getMainCategoryData($data['main_category_id']);
$subCategoryList = $this->dynamicConverter->getSubCategoryList($data['main_category_id']);
$canonicalSubCategoryList = $this->dynamicConverter->getSubCategoryList($data['mcId']);
$BreadCrumbs = [
// [
// 'label' => $categoryData['main_category_main_category_name'],
// 'href' => "/{$categoryData['main_category_main_category_webname']}",
// ],
[
'label' => $categoryData['main_category_name'],
'href' => "{$categoryData['main_category_main_category_webname']}/{$categoryData['main_category_webname']}",
],
[
'label' => $categoryData['category_name'],
'href' => "{$categoryData['main_category_main_category_webname']}/{$categoryData['main_category_webname']}/{$categoryData['category_webname']}",
],
];
$mcMcName = $mc;
$mcName = $mc;
$ctName = $data['ctName'];
$ctId = $data['ctId'];
$mcId = $data['main_category_id'];
$orderType = $this->session->has('order_type') ? $this->session->get('order_type') : $request->get('type');
$display_item_count_list = $this->CommonService->GetYaml('DisplayItem.yaml');
$displayMax = $this->session->has('display_max') ? intval($this->session->get('display_max')) : intval($request->get('disp'));
if ($displayMax == $display_item_count_list['DISPLAY_ITEM_COUNT']['LOW']) {
$max_display_cnt = $display_item_count_list['DISPLAY_ITEM_COUNT']['LOW'];
} else if ($displayMax == $display_item_count_list['DISPLAY_ITEM_COUNT']['HIGH']) {
$max_display_cnt = $display_item_count_list['DISPLAY_ITEM_COUNT']['HIGH'];
} else if ($displayMax == $display_item_count_list['DISPLAY_ITEM_COUNT_DEFAULT']) {
$max_display_cnt = $display_item_count_list['DISPLAY_ITEM_COUNT_DEFAULT'];
} else {
$max_display_cnt = $display_item_count_list['DISPLAY_ITEM_COUNT_DEFAULT'];
}
$dataItem = "";
$dataItem = $this->_getDataItem($request, $mcId, $ctId, $mcName, $ctName, $max_display_cnt, $item_count);
$detailData = array();
$detailData['item_count'] = $item_count;
// $detailData['item_count'] = count($dataItem);
$detailData['item'] = $dataItem;
$detailData['pager_pages_current_num'] = 0;
$detailData['col_count'] = $isMobile ? 2 : 3;
$detailData['max_display_cnt'] = $max_display_cnt;
if (!empty($request->get('no')) && intval($request->get('no')) > 0) {
$detailData['min_cnt'] = min((intval($request->get('no')) + 1), $detailData['item_count']);
} else {
$detailData['min_cnt'] = min(1, $detailData['item_count']);
}
$detailData['max_cnt'] = min($detailData['min_cnt'] + $detailData['max_display_cnt'] - 1, $detailData['item_count']);
for ($i = 1; $i <= $detailData['item_count']; $i += $detailData['max_display_cnt']) {
if ($detailData['min_cnt'] >= $i and $detailData['max_cnt'] <= ($i + $detailData['max_display_cnt'])) {
$detailData['pager_pages_current_num'] = intval($i / $detailData['max_display_cnt']) + 1;
}
}
$an_sort = array();
for ($i = 0; $i < $detailData['item_count']; $i++) {
$an_sort["$i"] = $i;
}
$i = 0;
foreach ($an_sort as $k => $v) {
// $an_v[$i] = $k;
$an_v[$i] = $i;
$i++;
}
$detailData['an_v'] = $an_sort;
$main_category_url2_content = $isMobile && $categoryData['main_category']['main_category_url2_sp_content'] != '' ? $categoryData['main_category']['main_category_url2_sp_content'] : ($categoryData['main_category']['main_category_url2_content'] ?? '');
$main_category_url2_content2 = $isMobile && $categoryData['main_category']['main_category_url2_sp_content2'] != '' ? $categoryData['main_category']['main_category_url2_sp_content2'] : ($categoryData['main_category']['main_category_url2_content2'] ?? '');
$main_category_url2_content3 = $isMobile && $categoryData['main_category']['main_category_url2_sp_content3'] != '' ? $categoryData['main_category']['main_category_url2_sp_content3'] : ($categoryData['main_category']['main_category_url2_content3'] ?? '');
$main_category_url2_content4 = $isMobile && $categoryData['main_category']['main_category_url2_sp_content4'] != '' ? $categoryData['main_category']['main_category_url2_sp_content4'] : ($categoryData['main_category']['main_category_url2_content4'] ?? '');
$main_category_url2_content5 = $isMobile && $categoryData['main_category']['main_category_url2_sp_content5'] != '' ? $categoryData['main_category']['main_category_url2_sp_content5'] : ($categoryData['main_category']['main_category_url2_content5'] ?? '');
$main_category_url2_content6 = $isMobile && $categoryData['main_category']['main_category_url2_sp_content6'] != '' ? $categoryData['main_category']['main_category_url2_sp_content6'] : ($categoryData['main_category']['main_category_url2_content6'] ?? '');
$main_category_url2_content7 = $isMobile && $categoryData['main_category']['main_category_url2_sp_content7'] != '' ? $categoryData['main_category']['main_category_url2_sp_content7'] : ($categoryData['main_category']['main_category_url2_content7'] ?? '');
$main_category_url2_content8 = $isMobile && $categoryData['main_category']['main_category_url2_sp_content8'] != '' ? $categoryData['main_category']['main_category_url2_sp_content8'] : ($categoryData['main_category']['main_category_url2_content8'] ?? '');
$main_category_url2_content9 = $isMobile && $categoryData['main_category']['main_category_url2_sp_content9'] != '' ? $categoryData['main_category']['main_category_url2_sp_content9'] : ($categoryData['main_category']['main_category_url2_content9'] ?? '');
$main_category_url2_content10 = $isMobile && $categoryData['main_category']['main_category_url2_sp_content10'] != '' ? $categoryData['main_category']['main_category_url2_sp_content10'] : ($categoryData['main_category']['main_category_url2_content10'] ?? '');
$main_category_url2_content11 = $isMobile && $categoryData['main_category']['main_category_url2_sp_content11'] != '' ? $categoryData['main_category']['main_category_url2_sp_content11'] : ($categoryData['main_category']['main_category_url2_content11'] ?? '');
$main_category_url2_content12 = $isMobile && $categoryData['main_category']['main_category_url2_sp_content12'] != '' ? $categoryData['main_category']['main_category_url2_sp_content12'] : ($categoryData['main_category']['main_category_url2_content12'] ?? '');
// TODO: content2を取得
$content2 = '';
// TODO: content3を取得
$content3 = '';
//TODO: 「関連するページ」リンクの表示
$isItemSeriesCategory = 1;
$isNoDisplayDbCategory = 0;
$detailItemCount = 1;
$categoryGroupNoshowdb = 0;
$breakCountForRankLabel = 1;
$useItemUrlDuplicated = false;
$mainCategoryData = array();
$main_h3 = $categoryData['main_category']['main_h3_tag'];
$main_breadcrumb = $categoryData['main_category']['main_breadcrumb'];
// TODO: category_h3を取得
$category_h3 = '';
// TODO: category_h1を取得
$category_h1 = '';
$seoKeywordTDK = '';
if ($categoryData['category_name'] == "全商品") {
$seoKeyword = $seoKeywordTDK = $categoryData['main_category_name'] . " " . $categoryData['category_name'];
} elseif (in_array($data['main_category_name'], array("メディカルウェア", "エステユニフォーム"))) { // パターンA
$seoKeyword = $categoryData['category_name'];
$seoKeywordTDK = $categoryData['category_name'] . "(" . $data['main_category_name'] . ")";
} elseif (in_array($data['main_category_name'], array("作業服・作業着", "作業服バートル", "医療白衣", "エプロン", "防寒服", "スタッフジャンパー", "シャツ", "ポロシャツ"))) { // パターンB
$seoKeyword = $seoKeywordTDK = $categoryData['category_name'];
} else { // パターンC
$seoKeyword = $seoKeywordTDK = $data['main_category_name'] . " " . $categoryData['category_name'];
}
$useRecommendedItemOrder = $this->dynamicConverter->useUnItemOrder($data['mcId'], $data['ctId']);
if ($mcMc) {
$custom_menu = $this->dynamicConverter->getMainCategoryMenu($mcMc);
} else {
$custom_menu = $this->dynamicConverter->getMainCategoryMenu($mc);
}
$custom_frequently_searched_word = $this->dynamicConverter->getSearchWordGroup($this->eccubeConfig['EditSpMenu']['MENU_NAME_COMMON'], $this->eccubeConfig['EditSpMenu']['BOOL_TRUE']);
$recentviews = [];
$common_header_contents = null;
$isMainCategory = false;
// TODO: ⑧【LM】商品一覧
$category = new CategoryWithRelated($mc, $ct, $mcMc, $isMobile);
$is_no_display_db_category = $category->isNoDisplayDbCategory();
$showItemDb = false;
$useCache = false;
$max_display_cnt = 10;
$canonical_category_name = '';
$average = array();
if ( !$data['category_group_noshowdb'] &&
// array(7, 8) 7:説明別, 8: メーカー別
( !in_array($data['main_category_group'], array(7, 8)) || $detailData['item_count'] > 0) ) {
$showItemDb = true;
}
$pager_data = $this->CategoryService->getPagerData(
$category->getCanonicalMainCategoryWebname(),
$ct,
$detailData['max_display_cnt'],
$detailData['item_count'],
$detailData['min_cnt'],
$detailData['max_cnt'],
$displayMax,
$orderType,
$isMobile
);
// TODO: ⑨【LM】カテゴリ絞り込み(SP)
$isMainOnly = false;
$leftmenuForCategoryData = [];
$canonicalMcName = $mcName;
$items = array_values(array_map(function($subCategory) {
return [
'category_id' => $subCategory['category_id'] ?? null,
'category_name' => $subCategory['category_name'] ?? null,
'category_main_category' => $subCategory['category_main_category'] ?? null,
'category_category' => $subCategory['category_category'] ?? null,
'category_main' => $subCategory['category_main'] ?? null,
'cnt' => $subCategory['cnt'] ?? null,
'image' => $this->CategoryService->getCategoryImageUrl($subCategory['category_id']),
'goods_image' => $this->CategoryService->getGoodsImageUrlByCatetoryId($subCategory['category_id']),
];
}, $subCategoryList ?? []));
// TODO: ③【LM】共用コンテンツ(SP)のデータ取得
$common_header_contents_all = '<div>
<a style="display: block; width: 100%;" href="/cart/add_catalog">
<picture><source media="(max-width: 320px)" type="image/webp" srcset="https://img0.land-mark.biz/ut_img/public_images_320/smartphone/smp-catalog-2020aw-486x60.webp"><source media="(max-width: 640px)" type="image/webp" srcset="https://img0.land-mark.biz/ut_img/public_images_640/smartphone/smp-catalog-2020aw-486x60.webp"><source type="image/webp" srcset="https://img0.land-mark.biz/ut_img/public_images/smartphone/smp-catalog-2020aw-486x60.webp"><source media="(max-width: 320px)" srcset="https://img0.land-mark.biz/ut_img/public_images_320/smartphone/smp-catalog-2020aw-486x60.jpg"><source media="(max-width: 640px)" srcset="https://img0.land-mark.biz/ut_img/public_images_640/smartphone/smp-catalog-2020aw-486x60.jpg"><img style="width: 100%;" src="https://img0.land-mark.biz/ut_img/public_images/smartphone/smp-catalog-2020aw-486x60.jpg"></picture></a>
</div>
<div>
<a style="display: block; width: 100%;" href="/amazonpay/">
<picture><source media="(max-width: 320px)" type="image/webp" srcset="https://img0.land-mark.biz/ut_img/public_images_320/categorypage/amazonpay/smp-486x60.webp"><source media="(max-width: 640px)" type="image/webp" srcset="https://img0.land-mark.biz/ut_img/public_images_640/categorypage/amazonpay/smp-486x60.webp"><source type="image/webp" srcset="https://img0.land-mark.biz/ut_img/public_images/categorypage/amazonpay/smp-486x60.webp"><source media="(max-width: 320px)" srcset="https://img0.land-mark.biz/ut_img/public_images_320/categorypage/amazonpay/smp-486x60.jpg"><source media="(max-width: 640px)" srcset="https://img0.land-mark.biz/ut_img/public_images_640/categorypage/amazonpay/smp-486x60.jpg"><img style="width: 100%;" src="https://img0.land-mark.biz/ut_img/public_images/categorypage/amazonpay/smp-486x60.jpg"></picture></a>
</div>
<script src="https://ajax.googlevapis.com/ajax/libs/jquery/2.2.4/jquery.2.4.1.min.js"></script>';
$main_category_name = $data['category_name'];
$back_to_top_link = !empty($subCategoryList[$ctId]['category_bottomlink']) ? $subCategoryList[$ctId]['category_bottomlink'] : $subCategoryList[$ctId]['category_name'];
$category_bottom_text = $subCategoryList[$ctId]['category_pagebottom'] ?? null;
// TODO: ⑨【LM】カテゴリ(子)_H1タグ
$addToHeadTitle = '';
$mainCategoryGroup = $this->CategoryService->getMainCategoryGroupById($mc);
$mainCategoryData = $this->CategoryService->getMainCategory($mcId);
$isShowCategoryData = false;
if (
!empty($mainCategoryData['category_group_noshowdb']) && !$mainCategoryData['category_group_noshowdb'] &&
(
(!empty($mainCategoryData['main_category_group']) && !in_array($mainCategoryData['main_category_group'], self::MAIN_CATEGORY_GROUPS_UNABLE_SHOW)) ||
$detailData['item_count'] > 0
)
) {
$isShowCategoryData = true;
}
if(!empty($mainCategoryGroup['category_group_only_main']) && $mainCategoryGroup['category_group_only_main']){
$isMainOnly = true;
}
$vendingStatusMap = $this->GoodsService->getGoodsVendingStatusMap();
return [
'data' => $data,
'review' => $review,
'pager_pages_current_num' => $detailData['pager_pages_current_num'],
'upperColumnData' => $upperColumnData,
'columnList' => $columnList,
'canonicalMcData' => $canonicalMcData,
'categoryData' => $categoryData,
'dataItem' => $dataItem,
'subCategoryList' => $subCategoryList,
'ctName' => $ctName,
'mcName' => $mcName,
'mcMcName' => $mcMcName,
'main_category_url2_content' => $main_category_url2_content,
'main_category_url2_content2' => $main_category_url2_content2,
'main_category_url2_content3' => $main_category_url2_content3,
'main_category_url2_content4' => $main_category_url2_content4,
'main_category_url2_content5' => $main_category_url2_content5,
'main_category_url2_content6' => $main_category_url2_content6,
'main_category_url2_content7' => $main_category_url2_content7,
'main_category_url2_content8' => $main_category_url2_content8,
'main_category_url2_content9' => $main_category_url2_content9,
'main_category_url2_content10' => $main_category_url2_content10,
'main_category_url2_content11' => $main_category_url2_content11,
'main_category_url2_content12' => $main_category_url2_content12,
'content2' => $content2,
'content3' => $content3,
'isItemSeriesCategory' => $isItemSeriesCategory,
'isNoDisplayDbCategory' => $isNoDisplayDbCategory,
'detailItemCount' => $detailItemCount,
'categoryGroupNoshowdb' => $categoryGroupNoshowdb,
'detailData' => $detailData,
'main_h3' => $main_h3,
'main_breadcrumb' => $main_breadcrumb,
'category_h3' => $category_h3,
'category_h1' => $category_h1,
'useRecommendedItemOrder' => $useRecommendedItemOrder,
'breakCountForRankLabel' => $breakCountForRankLabel,
'useItemUrlDuplicated' => $useItemUrlDuplicated,
'mainCategoryData' => $mainCategoryData,
'common_header_contents_all' => $common_header_contents_all,
'common_header_contents' => $common_header_contents,
'recentviews' => $recentviews,
'custom_menu' => $custom_menu,
'custom_frequently_searched_word' => $custom_frequently_searched_word,
'isMainCategory' => $isMainCategory,
'is_no_display_db_category' => $is_no_display_db_category,
'showItemDb' => $showItemDb,
'useCache' => $useCache,
'pager_data' => $pager_data,
'max_display_cnt' => $max_display_cnt,
'canonical_category_name' => $canonical_category_name,
'average' => $average,
'isMainOnly' => $isMainOnly,
'isShowCategoryData' => $isShowCategoryData,
'items' => $items,
'canonicalSubCategoryList' => $canonicalSubCategoryList,
'leftmenuForCategoryData' => $leftmenuForCategoryData,
'canonicalMcName' => $canonicalMcName,
'ctId' => $ctId,
'main_category_name' => $main_category_name,
'BreadCrumbs' => $BreadCrumbs,
'seoKeywordTDK' => $seoKeywordTDK,
'addToHeadTitle' => $addToHeadTitle,
'MetaTags' => ['SubCategory'=> $data ], # 2022/08/03 #kawai
'SubCate' => 1,
'back_to_top_link' => $back_to_top_link,
'category_bottom_text' => $category_bottom_text,
'vendingStatusMap' => $vendingStatusMap,
];
}
/**
* @param Request $request
* @param CategoryWithRelated $category
* @param string $mc
* @param string $ct
* @param string $mcMc
* @param array|callable $parameters
* @return mixed|null
* @throws \ErrorException
* @throws \Psr\Cache\InvalidArgumentException
*/
public function newCategory(Request $request, $mc, $ct = null, $mcMc = null, $parameters = [])
{
//
$isMobile = $this->MobileDetector->isMobile();
//
$device = $isMobile ? 'sp' : 'pc';
//
$layoutId = $isMobile ? null : 24; // TODO: マジックナンバー: 24
// レイアウトの指定
$this->CommonService->SetPageLayout('page/sub-category', $isMobile, [], $layoutId);
//
$masterCacheKey = self::getMasterCacheKey($mc, $ct);
// 絞込み対応(SESSION内の検索条件をキャッシュIDのサフィックス生成要素に加える)
$suffix = (function(array $_get, array $_session) {
//
$_params = array_merge(array_intersect_key($_get, array_flip([
'no',
'disp',
'type',
])), array_intersect_key($_session, array_flip([
'display_max',
'order_type',
'price_range_end',
'price_range_start',
'search_base_color_list',
'search_size_list',
'search_type_list',
])));
//
return !empty($_params) ? hash('sha256', base64_encode(serialize($_params))) : '';
})($request->query->all(), $this->session->all());
//
$viewCacheKey = "{$masterCacheKey}__{$device}_view__{$suffix}";
//
$masterCache = $this->handleMasterCache($masterCacheKey, $device, [
$viewCacheKey,
]);
return $this->getCacheByKey($viewCacheKey, function () use ($request, $isMobile, $mc, $ct, $mcMc, $parameters) {
/**
* ページング関連のセッションを設定(表示順など)
*/
$this->setCategoryPagingSession($request);
// レイアウトの指定
try {
// 親・子・祖父
$category = new CategoryWithRelated($mc, $ct, $mcMc, $isMobile);
} catch (\Exception $e) {
// カテゴリデータの取得に失敗した場合「404 Not Found」とする
throw new NotFoundHttpException("指定されたカテゴリのデータが取得出来ませんでした({$e->getMessage()})", $e);
}
return $this->_newCategory($category, $isMobile, $mc, $ct, $mcMc, $parameters);
});
}
/**
* @param bool $isMobile
* @param string $mc
* @param string $ct
* @param string $mcMc
* @param array|callable $parameters
* @return array
*/
public function _newCategory(CategoryWithRelated $category, $isMobile, $mc, $ct = null, $mcMc = null, $parameters = [])
{
//
if (is_callable($parameters)) {
//
$parameters = $parameters($category);
}
//
$BreadCrumbs = $category->getBreadCrumbs();
// TODO: ビューからの呼出しのみに統合
$contents_block_map = $category->getContentsBlockMap();
$metaTags = [
$category->getMetaTags(),
];
//
$main_h1 = null;
$category_h1 = null;
$h1_comment = $category->getH1Content();
//
$this->dataLayer['gdn']['items'] = array_map(function ($id) {
return $this->CommonService->get_google_retargeting_item($id);
}, array_column(array_slice($parameters['detailData']['item'], 0, 3), 'goods_id'));
$this->dataLayer['ydn']['yahoo_retargeting_items'] = array_map(function ($id) {
return $this->CommonService->get_yahoo_retargeting_item($id);
}, array_column(array_slice($parameters['detailData']['item'], 0, 3), 'goods_id'));
$this->dataLayer['criteo']['item'] = array_column(array_slice($parameters['detailData']['item'], 0, 3), 'goods_id');
//
$parameters = array_merge($parameters, [
'mcMcName' => $mcMc,
'mcName' => $mc,
'BreadCrumbs' => $BreadCrumbs,
'breadCrumb' => $BreadCrumbs,
'category' => $category,
'contents_block_map' => $contents_block_map, // TODO: ビューからの呼出しのみに統合
'MetaTags' => $metaTags, // TODO: ビューからの呼出しのみに統合
'sashikomiTitleHtml' => $category->getTitleContent(),
'dataLayer' => $this->dataLayer,
'main_h1' => $main_h1,
'category_h1' => $category_h1,
'h1_comment' => $h1_comment,
'ct' => $ct,
'isMobile' => $isMobile
]);
//
// return $this->render('Page/sub-category.twig', $parameters);
return $parameters;
}
/**
* @param Request $request
* @param null $cd
* @Template("Page/sub-category.twig")
*/
public function mainCategory(Request $request)
{
//
$Uri = $request->server->get('REQUEST_URI');
list($mc) = explode('/', trim(str_replace($request->getBasePath(), '', $Uri), '/'));
//
return $this->_mainCategory($request, $mc);
}
/**
* @param Request $request
* @param null $cd
* @Template("Page/sub-category.twig")
*/
public function mainCategoryMainCategory(Request $request, $mc = null, $mcMc = null)
{
//
$uri = $request->getRequestUri();
$paths = explode('/', trim($uri, '/'));
//
if ($paths[0] !== $mcMc) {
// //
// error_log('[PageController::mainCategoryMainCategory] '.json_encode(compact('uri', 'paths', 'mc', 'mcMc')));
//
$queries = $request->query->all();
$parameters = array_merge($queries, [
]);
//
$route = "ct1_{$mcMc}__ct2_{$mc}";
$route = str_replace('-', '_', $route);
//
return $this->redirectToRoute($route, $parameters, 301);
}
//
return $this->_mainCategory($request, $mc, $mcMc);
}
/**
* @param Request $request
* @param null $cd
* @Template("Page/sub-category.twig")
*/
public function subCategory(Request $request, $ct3 = null)
{
//
$Uri = $request->server->get('REQUEST_URI');
list($mc) = explode('/', trim(str_replace($request->getBasePath(), '', $Uri), '/'));
$ct = $ct3;
//
return $this->_subCategory($request, $ct, $mc);
}
/**
* @param Request $request
* @param null $cd
* @Template("Page/sub-category.twig")
*/
public function mainCategorySubCategory(Request $request, $ct1 = null, $ct2 = null, $ct3 = null)
{
//
$uri = $request->getRequestUri();
$paths = explode('/', trim($uri, '/'));
//
if ($paths[0] !== $ct1) {
// //
// error_log('[PageController::mainCategoryMainCategory] '.json_encode(compact('uri', 'paths', 'mc', 'mcMc')));
//
$queries = $request->query->all();
$parameters = array_merge($queries, [
'ct3' => $ct3,
]);
//
$route = "ct1_{$ct1}__ct2_{$ct2}__ct3_";
$route = str_replace('-', '_', $route);
//
return $this->redirectToRoute($route, $parameters, 301);
}
$mcMc = $ct1;
$mc = $ct2;
$ct = $ct3;
//
return $this->_subCategory($request, $ct, $mc, $mcMc);
}
private function _getDataItem($request, $mcId, $ctId, $mcName, $ctName, $max_display_cnt, &$item_count = null)
{
$an_search_base_color_list = array();
//$FRONT_PATH = $this->eccubeConfig['FRONT_PATH'];
$FRONT_PATH = "";
if ($this->session->has('search_base_color_list') && $this->session->get('search_base_color_list') != '') {
$k = 0;
$basename = $FRONT_PATH . "an_ct/" . $mcName . "/" . $ctName;
}
// サイズで選ぶ
$an_search_size_list = array();
if ($this->session->has('search_size_list') && $this->session->get('search_size_list') != '') {
$k = 0;
$basename = $FRONT_PATH . "an_ct/" . $mcName . "/" . $ctName;
}
// 種類で選ぶ
$an_search_type_list = array();
if ($this->session->has('search_type_list') && $this->session->get('search_type_list') != '') {
$k = 0;
$basename = $FRONT_PATH . "an_ct/" . $mcName . "/" . $ctName;
}
$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 (($this->session->has('price_range_start') && $this->session->get('price_range_start') != '') || ($this->session->has('price_range_end') && $this->session->get('price_range_end') != '')) {
$price_range_start = $this->session->get('price_range_start');
$price_range_end = $this->session->get('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->dynamicConverter->_getOriginalCategory($ctId);
} else {
$search_category = $this->dynamicConverter->_getOriginalCategory_Main($mcId);
}
$mcConditions = '';
$ctConditions = '';
if (!empty($mcId)) {
$mcConditions = " AND main_category_id = {$mcId}";
}
if (!empty($ctId) && $ctId !== 'allitem') {
$ctConditions = " AND category_id IN ({$search_category})";
}
elseif (!empty($search_category)) {
$ctConditions = " AND category_id IN ({$search_category})";
}
// ユニフォームネクストの商品掲載順を使用(おすすめとして扱う)
$use_recommended_order = $this->dynamicConverter->useUnItemOrder($mcId, $ctId);
$join_item_recommended_order = '';
$orderType = $this->session->has('order_type') ? $this->session->get('order_type') : $request->get('type');
if( $use_recommended_order && (int)$orderType === 6 ){
$recommended_order_where_clause = 'main_category_id = %d';
if( !empty($ctId) && strtolower($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_canonical_hinban, 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_canonical_hinban, 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_canonical_hinban, 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 ($orderType == "1" ) {
//安い順
$strSQL .= " order by price, goods_recommend desc ";
} elseif ($orderType == "3" ) {
//高い順
$strSQL .= " order by price desc, goods_recommend desc ";
} elseif ($orderType == "4" ) {
//品名順
// $strSQL .= " order by cast( goods_name as binary ), goods_recommend desc ";
$strSQL .= " order by goods_recommend desc ";
} elseif ($orderType == "2" ) {
//品番順
$strSQL .= " order by kataban, goods_recommend desc ";
} elseif ($orderType == "5" ) {
// 評価順
$strSQL .= " order by average desc, review_count desc,goods_recommend desc ";
} elseif ($orderType == "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 ";
}
// Note. no に意図せずマイナス数値が与えられてしまった場合の保全対応として、limit に与える数値を判定する
$start = intval($request->get('no'));
$start = ($start < 0) ? 0 : $start;
$strSQL .= ' limit ' . $start . ',' . $max_display_cnt;
$tempRow = $this->dynamicConverter->getDataBySql($strSQL);
if (empty($tempRow)) return [];
$tmp_row = 0;
foreach ($tempRow as $row) {
$tmp_row++;
$ret['item'][$tmp_row-1] = $row;
}
/***** 商品数を取得 *****/
$tempRow = $this->dynamicConverter->getDataBySql("SELECT FOUND_ROWS()", "{$mcId}_{$ctId}");
$item_count = $tempRow[0]['FOUND_ROWS()'];
$ret['item_count'] = 0;
$ret['style'] = "columnProduct3";
$ret['search_area'] = "";
$ret['col_count'] = 3;
$ret['max_display_cnt'] = 30;
$ret['item_count'] = $item_count;
$data['item_count'] = $ret['item_count'];
$data['style'] = $ret['style'];
$data['search_area'] = $ret['search_area'];
$data['col_count'] = $ret['col_count'];
$data['item'] = $ret['item'];
$an_search_base_color_list = array();
$an_search_type_list = array();
$an_search_size_list = array();
for ($i = 0; $i < count($data['item']); $i++) {
$item_price_list[] = $data["item"][$i]["price"];
}
$data['max_price'] = max($item_price_list);
$data['min_price'] = min($item_price_list);
$data['style'] = "columnCoordinate0";
$data['search_area'] = " style=\"display:none;\"";
// $data['col_count'] = $sp == 1 ? 2 : 3;
// 表示数チェック
if (isset($_GET['no']) and intval($_GET['no']) > 0) {
$data['min_cnt'] = min((intval($_GET['no']) + 1), $data['item_count']);
} else {
$data['min_cnt'] = min(1, $data['item_count']);
}
$data['max_cnt'] = min($data['min_cnt'] + $max_display_cnt - 1, $data['item_count']);
// クロスサイトスクリプティング対策
if (isset($_GET['type']) and $_GET['type'] != "" and !preg_match("/^[0-9]+$/", $_GET['type'])) $_GET['type'] = "";
if (isset($_GET['disp']) and $_GET['disp'] != "" and !preg_match("/^[0-9]+$/", $_GET['disp'])) $_GET['disp'] = "";
/**
* 「800-541……カテゴリページDB部分を変更したい-PC・スマホ両方」でページャーが刷新されたため、ここでのページャー生成はなくなったが、
*
*/
for ($i = 1; $i <= $data['item_count']; $i += $max_display_cnt) {
if ($data['min_cnt'] >= $i and $data['max_cnt'] <= ($i + $max_display_cnt)) {
$data['pager_pages_current_num'] = intval($i / $max_display_cnt) + 1;
}
}
// ソート用テーブル準備
if (isset($_SESSION['order_type']) and $_SESSION['order_type'] == "1") {
// 安い順
for ($i = 0; $i < $data['item_count']; $i++) {
$an_sort["$i"] = $data['item'][$i]['price'];
}
asort($an_sort, SORT_NUMERIC);
} elseif (isset($_SESSION['order_type']) and $_SESSION['order_type'] == "3") {
// 高い順
for ($i = 0; $i < $data['item_count']; $i++) {
$an_sort["$i"] = $data['item'][$i]['price'];
}
arsort($an_sort, SORT_NUMERIC);
} elseif (isset($_SESSION['order_type']) and $_SESSION['order_type'] == "5") {
// 評価・評価数の高い順
for ($i = 0; $i < $data['item_count']; $i++) {
$an_sort_tmp["$i"]['average'] = $data['item'][$i]['average'];
$an_sort_tmp["$i"]['review_count'] = $data['item'][$i]['review_count'];
$an_sort_tmp["$i"]['count'] = $i;
}
// 列方向の配列を得る
foreach ($an_sort_tmp as $key => $row) {
$average[$key] = $row['average'];
$review_count[$key] = $row['review_count'];
}
array_multisort($average, SORT_DESC, $review_count, SORT_DESC, $an_sort_tmp);
foreach($an_sort_tmp as $average_data){
$an_sort[$average_data['count']] = $average_data['count'];
}
} else {
// 指定なし
for ($i = 0; $i < $data['item_count']; $i++) {
$an_sort["$i"] = $i;
}
}
$i = 0;
foreach ($an_sort as $k => $v) {
$an_v[$i] = $i;
$i++;
}
$goodsIdList = array();
for ($i = 0, $n = count($data['item']); $i < $n; $i++) {
$item = $data['item'][$i];
$goodsIdList[$item['goods_id']] = $item['goods_id'];
}
if (empty($goodsIdList)) {
return array();
}
$goodsIdIn = implode(',', $goodsIdList);
$res = $this->GoodsService->getGoodsListByIds($goodsIdIn, $data, $an_v);
return $res;
}
/**
* @param string $mcName
* @param string $ctName
* @return string
*/
public static function getMasterCacheKey($mcName, $ctName = null)
{
//
if ($ctName === null) {
//
$masterCacheKey = "main_category_index_mc_{$mcName}";
} else {
//
$masterCacheKey = "main_category_sub_mc_{$mcName}_ct_{$ctName}";
}
//
$masterCacheKey = str_replace('-', '_', $masterCacheKey);
//
return $masterCacheKey;
}
/**
* カテゴリページのページングに関する情報をセッションに保存する。
*
* @param Request $request リクエスト
* 補足
* CategoryService への実装を検討したが、getMainCategoryName や useUnItemOrder が
* dynamicConverter に実装されているためここに実装。
*/
private function setCategoryPagingSession(Request $request){
$mc = $request->attributes->get('mc');
$ct = $request->attributes->get('ct');
/**
* カテゴリ取得
* カテゴリが見つからない場合はセッションをクリアして抜ける
*/
$mainCategoryData = $this->dynamicConverter->getMainCategoryName($mc);
$isSubCategory = !is_null($ct) && $ct !== 'allitem';
$subCategoryData = $isSubCategory
? $this->dynamicConverter->getSubCategoryName($mainCategoryData['main_category_id'], $ct)
: null
;
/**
* カテゴリが見つからない場合はセッションをクリアして抜ける
*/
if( empty($mainCategoryData) || ($isSubCategory && empty($subCategoryData)) ){
$this->session->remove('order_type'); // 「表示順」セッション
return;
}
$mcId = (int)$mainCategoryData['main_category_id'];
$ctId = isset($subCategoryData['category_id']) ? (int)$subCategoryData['category_id'] : null;
// 「表示順」セッション
$this->setCategoryOrderTypeSession($request, $mcId, $ctId);
}
/**
* 「表示順」のセッションを設定する。
*
* ウェブスクレイピング(管理画面)でユニフォームネクストの商品掲載順をコピーしたカテゴリでは
* 商品一覧を「オススメ順」として goods_recommended_order_table.display_order 順に並べる。
* この時、フロント「表示順」に「オススメ順」が追加表示されデフォルトの並び順となる。
* 初期表示では order_type パラメータが付かないため、order_type = 6 をセッションに保存しておく必要がある。
*
* ウェブスクレイピングでの掲載順コピーはカテゴリIDと商品掲載順しか管理していない(する必要がない)ため、
* 配下カテゴリを考慮する必要はない。
*
* @param Request $request リクエスト
* @param int $mcId メインカテゴリID
* @param int|null $ctId サブカテゴリID
*/
private function setCategoryOrderTypeSession(Request $request, $mcId, $ctId){
// 「オススメ順」対応カテゴリか
$useRecommendedOrder = $this->dynamicConverter->useUnItemOrder($mcId, $ctId);
// カテゴリが「オススメ順」対応ではない場合
if( !$useRecommendedOrder ){
if( $this->session->has('order_type') ){
$this->session->remove('order_type');
}
}
// カテゴリが「オススメ順」対応の場合
else {
// 「オススメ順」対応カテゴリで type の指定がない場合は「オススメ順」をデフォルトの表示順にする。
if( is_null( $request->get('type') ) ){
$this->session->set('order_type', 6);
}
// type の指定がある場合は type を優先するためセッションをクリアする。
else{
$this->session->remove('order_type');
}
}
}
}