diff --git a/src/Eccube/Resource/template/default/Product/detail.twig b/src/Eccube/Resource/template/default/Product/detail.twig index 72533ccb38f..5c27c358cc2 100755 --- a/src/Eccube/Resource/template/default/Product/detail.twig +++ b/src/Eccube/Resource/template/default/Product/detail.twig @@ -214,6 +214,32 @@ 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 65a756040a3..df6597108f9 100644 --- a/tests/Eccube/Tests/Web/ProductControllerTest.php +++ b/tests/Eccube/Tests/Web/ProductControllerTest.php @@ -250,4 +250,31 @@ public function testProductFavoriteAddThroughLogin() $html = $crawler->filter('div.ec-productRole__profile')->html(); $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); + } }