diff --git a/src/Eccube/Resource/template/default/Product/detail.twig b/src/Eccube/Resource/template/default/Product/detail.twig index 72533ccb38f..e3c9e26de1a 100755 --- a/src/Eccube/Resource/template/default/Product/detail.twig +++ b/src/Eccube/Resource/template/default/Product/detail.twig @@ -214,6 +214,30 @@ file that was distributed with this source code. $('.ec-modal').hide() }); + {% endblock %} {% block main %} diff --git a/tests/Eccube/Tests/Web/ProductControllerTest.php b/tests/Eccube/Tests/Web/ProductControllerTest.php index eafe8f22979..e40e4831c6a 100644 --- a/tests/Eccube/Tests/Web/ProductControllerTest.php +++ b/tests/Eccube/Tests/Web/ProductControllerTest.php @@ -258,6 +258,33 @@ public function testProductFavoriteAddThroughLogin() $this->assertContains('お気に入りに追加済です', $html); } + /** + * 商品詳細ページの構造化データ + */ + public function testProductStructureData() + { + $crawler = $this->client->request('GET', $this->generateUrl('product_detail', ['id' => 2])); + $json = json_decode(html_entity_decode($crawler->filter('script[type="application/ld+json"]')->html())); + $this->assertEquals('Product', $json->{'@type'}); + $this->assertEquals('チェリーアイスサンド', $json->name); + $this->assertEquals(3080, $json->offers->price); + $this->assertEquals('InStock', $json->offers->availability); + + // 在庫なし商品のテスト + $Product = $this->createProduct('Product no stock', 1); + $ProductClass = $Product->getProductClasses()->first(); + $ProductClass->setStockUnlimited(false); + $ProductClass->setStock(0); + $ProductStock = $ProductClass->getProductStock(); + $ProductStock->setStock(0); + $this->entityManager->flush(); + + $crawler = $this->client->request('GET', $this->generateUrl('product_detail', ['id' => $Product->getId()])); + $json = json_decode(html_entity_decode($crawler->filter('script[type="application/ld+json"]')->html())); + $this->assertEquals('Product no stock', $json->name); + $this->assertEquals('OutOfStock', $json->offers->availability); + } + /** * 一覧ページ metaタグのテスト */