diff --git a/codeception/acceptance/EF02ProductCest.php b/codeception/acceptance/EF02ProductCest.php index 9acde108b5c..2109ec75ae4 100644 --- a/codeception/acceptance/EF02ProductCest.php +++ b/codeception/acceptance/EF02ProductCest.php @@ -183,19 +183,6 @@ public function product_商品詳細サムネイル(\AcceptanceTester $I) $I->assertRegExp('/\/upload\/save_image\/sand-2\.png$/', $img, $img.' が見つかりません'); } - /** - * @group EF0202-UC01-T04 - */ - public function product_商品詳細構造化データ(\AcceptanceTester $I) - { - $I->wantTo('EF0202-UC01-T04 商品詳細 構造化データ'); // todo - - ProductDetailPage::go($I, 1); - $html = $I->grabAttributeFrom('script[type="application/ld+json"]', 'innerHTML'); - $json_ld = json_decode((string)$html); - $I->assertEquals($json_ld->name, '彩のジェラートCUBE'); - } - public function product_商品詳細カート1(\AcceptanceTester $I) { $I->wantTo('EF0202-UC02-T01 商品詳細 カート 注文数<販売制限数<在庫数の注文'); diff --git a/src/Eccube/Resource/template/default/Product/detail.twig b/src/Eccube/Resource/template/default/Product/detail.twig index a50cf1c0dd0..e3c9e26de1a 100755 --- a/src/Eccube/Resource/template/default/Product/detail.twig +++ b/src/Eccube/Resource/template/default/Product/detail.twig @@ -227,12 +227,12 @@ file that was distributed with this source code. "{{ url('homepage') }}{{ asset(no_image_product, 'save_image') }}" {% endfor %} ], - "description": "{{ Product.description_list | default(Product.description_detail) | striptags | replace({"\n": '', "\r": ''}, '') }}", + "description": "{{ Product.description_list | default(Product.description_detail) | striptags | replace({'\n': '', '\r': ''}) }}", "sku": "{{ Product.code_min }}", "offers": { "@type": "Offer", "url": "{{ url('product_detail', {'id': Product.id}) }}", - "priceCurrency": "JPY", + "priceCurrency": "{{ eccube_config.currency }}", "price": {{ Product.getPrice02IncTaxMin }}, "availability": "{{ Product.stock_find ? "InStock" : "OutOfStock" }}" } 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); + } }