Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

商品詳細ページに構造化データを追加 #4986

Merged

Conversation

matsuoshi
Copy link
Contributor

@matsuoshi matsuoshi commented Mar 24, 2021

概要(Overview・Refs Issue)

4.1 feature 向けのPRです。

商品詳細ページに、構造化データ (JSON-LD形式) を埋め込みます

方針(Policy)

SEO的な観点で、商品詳細ページに構造化データの JSON を追加します。

構造化データに関するドキュメント
https://developers.google.com/search/docs/data-types/product?hl=ja

関連issue
#4807

実装に関する補足(Appendix)

テスト(Test)

商品詳細ページにおいて、JSON+LDの内容を確認するWebテストを追加しました。

また、構造化データテストツールにて、設定したJSON-LD形式にエラーのないことを確認しています。
(一部警告あり → 推奨フィールドに設定できる値がないため)
https://search.google.com/structured-data/testing-tool

相談(Discussion)

マイナーバージョン互換性保持のための制限事項チェックリスト

  • 既存機能の仕様変更
  • フックポイントの呼び出しタイミングの変更
  • フックポイントのパラメータの削除・データ型の変更
  • twigファイルに渡しているパラメータの削除・データ型の変更
  • Serviceクラスの公開関数の、引数の削除・データ型の変更
  • 入出力ファイル(CSVなど)のフォーマット変更

レビュワー確認項目

  • 動作確認
  • コードレビュー
  • E2E/Unit テスト確認(テストの追加・変更が必要かどうか)
  • 互換性が保持されているか
  • セキュリティ上の問題がないか

新機能追加に伴う競合確認

  • プラグインとの競合がないか
  • プラグインからのマイグレーションが必要か

@matsuoshi matsuoshi added the affected:template フロントテンプレートの変更 label Mar 24, 2021
@okazy okazy added the enhancement 機能追加 label Mar 24, 2021
@okazy okazy added this to the 4.1 milestone Mar 24, 2021
@codecov-io
Copy link

codecov-io commented Mar 24, 2021

Codecov Report

Merging #4986 (c011049) into 4.1-feature (c46e77c) will increase coverage by 0.20%.
The diff coverage is n/a.

Impacted file tree graph

@@                Coverage Diff                @@
##             4.1-feature    #4986      +/-   ##
=================================================
+ Coverage          76.18%   76.38%   +0.20%     
- Complexity          6124     6190      +66     
=================================================
  Files                437      445       +8     
  Lines              20736    20963     +227     
=================================================
+ Hits               15798    16013     +215     
- Misses              4938     4950      +12     
Flag Coverage Δ Complexity Δ
tests 76.38% <ø> (+0.20%) 0.00 <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ Complexity Δ
.../Eccube/Controller/Admin/Order/OrderController.php 83.66% <0.00%> (-0.49%) 68.00% <0.00%> (ø%)
src/Eccube/Service/CartService.php 93.75% <0.00%> (-0.03%) 69.00% <0.00%> (ø%)
src/Eccube/Repository/MemberRepository.php 100.00% <0.00%> (ø) 8.00% <0.00%> (ø%)
...roller/Admin/Setting/System/SecurityController.php 0.00% <0.00%> (ø) 11.00% <0.00%> (+1.00%)
...er/Admin/Setting/System/LoginHistoryController.php 88.88% <0.00%> (ø) 13.00% <0.00%> (?%)
...Eccube/Form/Type/Master/LoginHistoryStatusType.php 100.00% <0.00%> (ø) 3.00% <0.00%> (?%)
src/Eccube/Repository/LoginHistoryRepository.php 100.00% <0.00%> (ø) 18.00% <0.00%> (?%)
.../Eccube/Form/Type/Admin/SearchLoginHistoryType.php 100.00% <0.00%> (ø) 3.00% <0.00%> (?%)
...Repository/Master/LoginHistoryStatusRepository.php 100.00% <0.00%> (ø) 1.00% <0.00%> (?%)
src/Eccube/EventListener/LoginHistoryListener.php 95.23% <0.00%> (ø) 9.00% <0.00%> (?%)
... and 8 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c46e77c...c011049. Read the comment docs.

@matsuoshi matsuoshi force-pushed the feature/seo-structured-data branch 2 times, most recently from 607e5c5 to 8de52bb Compare March 25, 2021 05:19
@matsuoshi matsuoshi changed the title [WIP] 商品詳細ページに構造化データを追加 商品詳細ページに構造化データを追加 Mar 25, 2021
@matsuoshi matsuoshi marked this pull request as ready for review March 25, 2021 07:48
"{{ app.request.schemeAndHttpHost }}{{ asset(img, 'save_image') }}"{% if not loop.last %},{% endif %}

{% else %}
"{{ app.request.schemeAndHttpHost }}{{ asset(no_image_product, 'save_image') }}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

画像のURLが以下のように出力されてました。
http://127.0.0.1:8080/html/upload/save_image/

no_image_productはtwigフィルタなので、以下のように渡してください
{{ asset(''|no_image_product, 'save_image') }}

"{{ app.request.schemeAndHttpHost }}{{ asset(no_image_product, 'save_image') }}"
{% endfor %}
],
"description": "{{ Product.description_list | default(Product.description_detail) | striptags | replace({'\n': '', '\r': ''}) }}",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

descriptionは文字長の制限はありますか?
制限あれば文字長内に丸めるなどしたほうがよいかもしれません。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

descriptionは文字長の制限はありますか?

仕様上の上限が見当たりませんでしたが、確かに全文出す必要はないと思いますので metaタグのdescription などで一般的な 300文字に丸めます

{% endfor %}
],
"description": "{{ Product.description_list | default(Product.description_detail) | striptags | replace({'\n': '', '\r': ''}) }}",
"sku": "{{ Product.code_min }}",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

商品コードは未設定の場合がありますが、skuは空でも問題ないですか?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sku は構造化データの仕様では「任意」でしたので、未設定の場合は出力しないよう変更しました

"{{ app.request.schemeAndHttpHost }}{{ asset(no_image_product, 'save_image') }}"
{% endfor %}
],
"description": "{{ Product.description_list | default(Product.description_detail) | striptags | replace({'\n': '', '\r': ''}) }}",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

いくつかの文字種が期待通りに出力されないかもです。

'あああ' -> &#039;あああ&#039;
"あああ" -> &quot;あああ&quot;
<今ならお買い得!> ->

そこまで厳密にする必要はないかもしれませんがいちおう。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

' " については、テストツールで検証したところ正しく解析されていたようのですので、このままにします。
https://search.google.com/test/rich-results
<> について、striptags は副作用ありそうなので削除しました。(description内の不等号はエスケープされて出力される形)

@codecov-commenter
Copy link

Codecov Report

Merging #4986 (b46b162) into 4.1-feature (c46e77c) will increase coverage by 0.19%.
The diff coverage is n/a.

Impacted file tree graph

@@                Coverage Diff                @@
##             4.1-feature    #4986      +/-   ##
=================================================
+ Coverage          76.18%   76.37%   +0.19%     
- Complexity          6124     6190      +66     
=================================================
  Files                437      445       +8     
  Lines              20736    20963     +227     
=================================================
+ Hits               15798    16011     +213     
- Misses              4938     4952      +14     
Flag Coverage Δ
tests 76.37% <ø> (+0.19%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...be/Service/PurchaseFlow/Processor/TaxProcessor.php 79.62% <0.00%> (-3.71%) ⬇️
.../Eccube/Controller/Admin/Order/OrderController.php 83.66% <0.00%> (-0.49%) ⬇️
src/Eccube/Service/CartService.php 93.75% <0.00%> (-0.03%) ⬇️
src/Eccube/Repository/MemberRepository.php 100.00% <0.00%> (ø)
...roller/Admin/Setting/System/SecurityController.php 0.00% <0.00%> (ø)
.../Eccube/Form/Type/Admin/SearchLoginHistoryType.php 100.00% <0.00%> (ø)
src/Eccube/Entity/LoginHistory.php 87.87% <0.00%> (ø)
src/Eccube/Repository/LoginHistoryRepository.php 100.00% <0.00%> (ø)
src/Eccube/Entity/Master/LoginHistoryStatus.php 0.00% <0.00%> (ø)
src/Eccube/EventListener/LoginHistoryListener.php 95.23% <0.00%> (ø)
... and 9 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c46e77c...b46b162. Read the comment docs.

@chihiro-adachi chihiro-adachi merged commit 48c6ca6 into EC-CUBE:4.1-feature Jul 2, 2021
@chihiro-adachi
Copy link
Contributor

@matsuoshi
ありがつございます、マージしました

@k-yamamura
Copy link
Contributor

今更ですが、

{{ app.request.schemeAndHttpHost }}{{ asset(img, 'save_image') }}

と絶対URLで記述する必要がある箇所ですが、 #5057 に記述している、{{ absolute_url() }} を使った

absolute_url(asset(img, 'save_image'))

を利用するか、EC-CUBEとしてどちらかで統一しておいた方が良さそうなのと、フルパスで記述する場合、

{{ app.request.schemeAndHttpHost }}{{ app.request.basePath }}{{ asset(img, 'save_image') }}

と環境によっては{{ app.request.basePath }}が必要です。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affected:template フロントテンプレートの変更 enhancement 機能追加
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants