diff --git a/app/config/eccube/packages/eccube.yaml b/app/config/eccube/packages/eccube.yaml
index 202725d6902..14cc3bbe889 100644
--- a/app/config/eccube/packages/eccube.yaml
+++ b/app/config/eccube/packages/eccube.yaml
@@ -64,6 +64,7 @@ parameters:
plugin_temp_realdir: /PATH/TO/WEB_ROOT/src/Eccube/Repository/Master/upload/temp_plugin/ # upload_tmp_dir に任せればよい?
eccube_price_len: 8 # 最大値で制御したい
eccube_search_pmax: 12
+ eccube_sitemap_products_per_page: 1000
eccube_stext_len: 255
eccube_sltext_len: 500
eccube_smtext_len: 100
diff --git a/src/Eccube/Controller/SitemapController.php b/src/Eccube/Controller/SitemapController.php
index 5db3a32546c..b0d6c9ed2c6 100644
--- a/src/Eccube/Controller/SitemapController.php
+++ b/src/Eccube/Controller/SitemapController.php
@@ -15,8 +15,11 @@
use Eccube\Entity\Page;
use Eccube\Repository\CategoryRepository;
+use Eccube\Repository\Master\ProductListOrderByRepository;
use Eccube\Repository\PageRepository;
use Eccube\Repository\ProductRepository;
+use Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination;
+use Knp\Component\Pager\Paginator;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
@@ -25,11 +28,6 @@
class SitemapController extends AbstractController
{
- /**
- * @var ProductRepository
- */
- private $productRepository;
-
/**
* @var CategoryRepository
*/
@@ -41,27 +39,34 @@ class SitemapController extends AbstractController
private $pageRepository;
/**
- * @var RouterInterface
+ * @var ProductListOrderByRepository
*/
- private $router;
+ private $productListOrderByRepository;
/**
- * @var int
+ * @var ProductRepository
*/
- private $item_per_page = 1000;
+ private $productRepository;
+
+ /**
+ * @var RouterInterface
+ */
+ private $router;
/**
* SitemapController constructor.
*/
public function __construct(
- ProductRepository $productRepository,
CategoryRepository $categoryRepository,
PageRepository $pageRepository,
+ ProductListOrderByRepository $productListOrderByRepository,
+ ProductRepository $productRepository,
RouterInterface $router
) {
- $this->productRepository = $productRepository;
$this->categoryRepository = $categoryRepository;
$this->pageRepository = $pageRepository;
+ $this->productListOrderByRepository = $productListOrderByRepository;
+ $this->productRepository = $productRepository;
$this->router = $router;
}
@@ -70,10 +75,10 @@ public function __construct(
*
* @Route("/sitemap.xml", name="sitemap_xml")
*/
- public function index()
+ public function index(Paginator $paginator)
{
- $qb = $this->pageRepository->createQueryBuilder('p');
- $Page = $qb->select('p')
+ $pageQueryBuilder = $this->pageRepository->createQueryBuilder('p');
+ $Page = $pageQueryBuilder->select('p')
->where("((p.meta_robots not like '%noindex%' and p.meta_robots not like '%none%') or p.meta_robots IS NULL)")
->andWhere('p.id <> 0')
->andWhere('p.MasterPage is null')
@@ -83,7 +88,17 @@ public function index()
->getSingleResult();
$Product = $this->productRepository->findOneBy(['Status' => 1], ['update_date' => 'DESC']);
- $ProductCount = $this->productRepository->count(['Status' => 1]);
+
+ // フロントの商品一覧の条件で商品情報を取得
+ $ProductListOrder = $this->productListOrderByRepository->find($this->eccubeConfig['eccube_product_order_newer']);
+ $productQueryBuilder = $this->productRepository->getQueryBuilderBySearchData(['orderby' => $ProductListOrder]);
+ /** @var SlidingPagination $pagination */
+ $pagination = $paginator->paginate(
+ $productQueryBuilder,
+ 1,
+ $this->eccubeConfig['eccube_sitemap_products_per_page']
+ );
+ $paginationData = $pagination->getPaginationData();
$Category = $this->categoryRepository->findOneBy([], ['update_date' => 'DESC']);
@@ -91,7 +106,7 @@ public function index()
[
'Category' => $Category,
'Product' => $Product,
- 'ProductPageCount' => ceil($ProductCount / $this->item_per_page),
+ 'productPageCount' => $paginationData['pageCount'],
'Page' => $Page,
],
'sitemap_index.xml.twig'
@@ -116,25 +131,27 @@ public function category()
* Output sitemap of products as status is 1
*
* @Route("/sitemap_product_{page}.xml", name="sitemap_product_xml", requirements={"page" = "\d+"})
- * @param Request $request
+ *
* @return Response
*/
- public function product(Request $request)
+ public function product(Request $request, Paginator $paginator)
{
- $page = (int)$request->get('page');
-
- $Products = $this->productRepository->findBy(
- ['Status' => 1],
- ['update_date' => 'DESC'],
- $this->item_per_page,
- ($page - 1) * $this->item_per_page
+ // フロントの商品一覧の条件で商品情報を取得
+ $ProductListOrder = $this->productListOrderByRepository->find($this->eccubeConfig['eccube_product_order_newer']);
+ $productQueryBuilder = $this->productRepository->getQueryBuilderBySearchData(['orderby' => $ProductListOrder]);
+ /** @var SlidingPagination $pagination */
+ $pagination = $paginator->paginate(
+ $productQueryBuilder,
+ $request->get('page'),
+ $this->eccubeConfig['eccube_sitemap_products_per_page']
);
+ $paginationData = $pagination->getPaginationData();
- if (!$Products) {
+ if ($paginationData['currentItemCount'] === 0) {
throw new NotFoundHttpException();
}
- return $this->outputXml(['Products' => $Products]);
+ return $this->outputXml(['Products' => $pagination]);
}
/**
@@ -149,7 +166,12 @@ public function page()
$Pages = $this->pageRepository->getPageList("((p.meta_robots not like '%noindex%' and p.meta_robots not like '%none%') or p.meta_robots IS NULL)");
// URL に変数が含まれる場合は URL の生成ができないためここで除外する
- $Pages = array_filter($Pages, function (Page $Page) {
+ $DefaultPages = array_filter($Pages, function (Page $Page) {
+ // 管理画面から作成されたページは除外
+ if ($Page->getEditType() === Page::EDIT_TYPE_USER) {
+ return false;
+ }
+
$route = $this->router->getRouteCollection()->get($Page->getUrl());
if (is_null($route)) {
return false;
@@ -157,13 +179,20 @@ public function page()
return count($route->compile()->getPathVariables()) < 1;
});
- return $this->outputXml(['Pages' => $Pages]);
+ // 管理画面から作成されたページ
+ $UserPages = array_filter($Pages, function (Page $Page) {
+ return $Page->getEditType() === Page::EDIT_TYPE_USER;
+ });
+
+ return $this->outputXml([
+ 'DefaultPages' => $DefaultPages,
+ 'UserPages' => $UserPages,
+ ]);
}
/**
* Output XML response by data.
*
- * @param array $data
* @param string $template_name
*
* @return Response
diff --git a/src/Eccube/Resource/template/default/sitemap.xml.twig b/src/Eccube/Resource/template/default/sitemap.xml.twig
index 55858da3d5a..7fa945ca705 100644
--- a/src/Eccube/Resource/template/default/sitemap.xml.twig
+++ b/src/Eccube/Resource/template/default/sitemap.xml.twig
@@ -1,17 +1,26 @@
{# Pages #}
-{% if Pages is defined %}
-{% for Page in Pages %}
- {% if Page.url != 'product_detail' and Page.url != 'product_list' %}
+{% if DefaultPages is defined %}
+{% for DefaultPage in DefaultPages %}
+ {% if DefaultPage.url != 'product_detail' and DefaultPage.url != 'product_list' %}
- {{url(Page.url)}}
- {{Page.update_date|date_format('','c')}}
+ {{url(DefaultPage.url)}}
+ {{DefaultPage.update_date|date_format('','c')}}
daily
{% endif %}
{% endfor %}
{% endif %}
+{% if UserPages is defined %}
+{% for UserPage in UserPages %}
+
+ {{url('user_data', {route: UserPage.url})}}
+ {{UserPage.update_date|date_format('','c')}}
+ daily
+
+{% endfor %}
+{% endif %}
{# Categories #}
{% if Categories is defined %}
{% for Category in Categories %}
@@ -37,4 +46,4 @@
{% endfor %}
{% endif %}
-
+
diff --git a/src/Eccube/Resource/template/default/sitemap_index.xml.twig b/src/Eccube/Resource/template/default/sitemap_index.xml.twig
index 2ea48ba8409..e342f757372 100644
--- a/src/Eccube/Resource/template/default/sitemap_index.xml.twig
+++ b/src/Eccube/Resource/template/default/sitemap_index.xml.twig
@@ -8,7 +8,7 @@
{{url('sitemap_category_xml')}}
{{Category.update_date|date_format('','c')}}
- {% for p in 1..ProductPageCount %}
+ {% for p in 1..productPageCount %}
{{url('sitemap_product_xml', {page: p})}}
{{Product.update_date|date_format('','c')}}
diff --git a/tests/Eccube/Tests/Web/SitemapControllerTest.php b/tests/Eccube/Tests/Web/SitemapControllerTest.php
index 90104eed057..9114c87641e 100644
--- a/tests/Eccube/Tests/Web/SitemapControllerTest.php
+++ b/tests/Eccube/Tests/Web/SitemapControllerTest.php
@@ -27,6 +27,12 @@ public function testProduct()
$this->assertTrue($this->client->getResponse()->isSuccessful());
}
+ public function testProduct404()
+ {
+ $this->client->request('GET', $this->generateUrl('sitemap_product_xml', ['page' => 9999]));
+ $this->assertEquals(404, $this->client->getResponse()->getStatusCode());
+ }
+
public function testCategory()
{
$this->client->request('GET', $this->generateUrl('sitemap_category_xml'));