From 4b65f084d71ec594627fae0d1be39a5ae0340c2c Mon Sep 17 00:00:00 2001 From: "h.matsuo" Date: Wed, 24 Mar 2021 12:31:07 +0900 Subject: [PATCH 1/2] =?UTF-8?q?SEO=20=E5=95=86=E5=93=81=E3=81=AE=E6=A7=8B?= =?UTF-8?q?=E9=80=A0=E5=8C=96=E3=83=87=E3=83=BC=E3=82=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- codeception/acceptance/EF02ProductCest.php | 13 ++++++++++ .../template/default/Product/detail.twig | 24 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/codeception/acceptance/EF02ProductCest.php b/codeception/acceptance/EF02ProductCest.php index 2109ec75ae4..9acde108b5c 100644 --- a/codeception/acceptance/EF02ProductCest.php +++ b/codeception/acceptance/EF02ProductCest.php @@ -183,6 +183,19 @@ 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 72533ccb38f..a50cf1c0dd0 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 %} From 7d60e98dc10fda0e90762e8497d2ed8a2b4704d3 Mon Sep 17 00:00:00 2001 From: "h.matsuo" Date: Wed, 24 Mar 2021 17:01:57 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=E6=A7=8B=E9=80=A0=E5=8C=96=E3=83=87?= =?UTF-8?q?=E3=83=BC=E3=82=BF=20=E3=83=86=E3=82=B9=E3=83=88=E3=82=B3?= =?UTF-8?q?=E3=83=BC=E3=83=89=E3=81=AE=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- codeception/acceptance/EF02ProductCest.php | 13 --------- .../template/default/Product/detail.twig | 4 +-- .../Tests/Web/ProductControllerTest.php | 27 +++++++++++++++++++ 3 files changed, 29 insertions(+), 15 deletions(-) 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); + } }