diff --git a/src/Eccube/Controller/SitemapController.php b/src/Eccube/Controller/SitemapController.php
index d5f32ff88c5..5db3a32546c 100644
--- a/src/Eccube/Controller/SitemapController.php
+++ b/src/Eccube/Controller/SitemapController.php
@@ -17,7 +17,9 @@
use Eccube\Repository\CategoryRepository;
use Eccube\Repository\PageRepository;
use Eccube\Repository\ProductRepository;
+use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
+use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\RouterInterface;
@@ -43,6 +45,11 @@ class SitemapController extends AbstractController
*/
private $router;
+ /**
+ * @var int
+ */
+ private $item_per_page = 1000;
+
/**
* SitemapController constructor.
*/
@@ -76,12 +83,15 @@ public function index()
->getSingleResult();
$Product = $this->productRepository->findOneBy(['Status' => 1], ['update_date' => 'DESC']);
+ $ProductCount = $this->productRepository->count(['Status' => 1]);
+
$Category = $this->categoryRepository->findOneBy([], ['update_date' => 'DESC']);
return $this->outputXml(
[
'Category' => $Category,
'Product' => $Product,
+ 'ProductPageCount' => ceil($ProductCount / $this->item_per_page),
'Page' => $Page,
],
'sitemap_index.xml.twig'
@@ -105,11 +115,24 @@ public function category()
*
* Output sitemap of products as status is 1
*
- * @Route("/sitemap_product.xml", name="sitemap_product_xml")
+ * @Route("/sitemap_product_{page}.xml", name="sitemap_product_xml", requirements={"page" = "\d+"})
+ * @param Request $request
+ * @return Response
*/
- public function product()
+ public function product(Request $request)
{
- $Products = $this->productRepository->findBy(['Status' => 1], ['update_date' => 'DESC']);
+ $page = (int)$request->get('page');
+
+ $Products = $this->productRepository->findBy(
+ ['Status' => 1],
+ ['update_date' => 'DESC'],
+ $this->item_per_page,
+ ($page - 1) * $this->item_per_page
+ );
+
+ if (!$Products) {
+ throw new NotFoundHttpException();
+ }
return $this->outputXml(['Products' => $Products]);
}
diff --git a/src/Eccube/Resource/template/default/sitemap_index.xml.twig b/src/Eccube/Resource/template/default/sitemap_index.xml.twig
index 1ef9ef6e820..2ea48ba8409 100644
--- a/src/Eccube/Resource/template/default/sitemap_index.xml.twig
+++ b/src/Eccube/Resource/template/default/sitemap_index.xml.twig
@@ -8,8 +8,10 @@
{{url('sitemap_category_xml')}}
{{Category.update_date|date_format('','c')}}
-
- {{url('sitemap_product_xml')}}
- {{Product.update_date|date_format('','c')}}
-
-
\ No newline at end of file
+ {% for p in 1..ProductPageCount %}
+
+ {{url('sitemap_product_xml', {page: p})}}
+ {{Product.update_date|date_format('','c')}}
+
+ {% endfor %}
+
diff --git a/tests/Eccube/Tests/Web/SitemapControllerTest.php b/tests/Eccube/Tests/Web/SitemapControllerTest.php
new file mode 100644
index 00000000000..90104eed057
--- /dev/null
+++ b/tests/Eccube/Tests/Web/SitemapControllerTest.php
@@ -0,0 +1,41 @@
+client->request('GET', $this->generateUrl('sitemap_xml'));
+ $this->assertTrue($this->client->getResponse()->isSuccessful());
+ }
+
+ public function testProduct()
+ {
+ $this->client->request('GET', $this->generateUrl('sitemap_product_xml', ['page' => 1]));
+ $this->assertTrue($this->client->getResponse()->isSuccessful());
+ }
+
+ public function testCategory()
+ {
+ $this->client->request('GET', $this->generateUrl('sitemap_category_xml'));
+ $this->assertTrue($this->client->getResponse()->isSuccessful());
+ }
+
+ public function testPage()
+ {
+ $this->client->request('GET', $this->generateUrl('sitemap_page_xml'));
+ $this->assertTrue($this->client->getResponse()->isSuccessful());
+ }
+}