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

商品詳細ページにSNS共有ボタンを表示する #4916

Open
wants to merge 6 commits into
base: 4.3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 38 additions & 0 deletions app/DoctrineMigrations/Version20210216115000.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20210216115000 extends AbstractMigration
{
public function up(Schema $schema): void
{
$blockId = $this->connection->fetchColumn("SELECT id FROM dtb_block WHERE file_name = 'social_buttons'");

// dtb_block に ソーシャルブロックがなければ作成する
if (!$blockId) {
$blockId = $this->connection->fetchColumn('SELECT MAX(id) + 1 FROM dtb_block');

$this->addSql("INSERT INTO dtb_block (
id, device_type_id, block_name, file_name, create_date, update_date, use_controller, deletable, discriminator_type
) VALUES(
?, 10, 'ソーシャルボタン', 'social_buttons', '2021-02-12 14:00:00', '2021-02-12 14:00:00', false, false, 'block'
)", [$blockId]);
}
}

public function down(Schema $schema): void
{
// dtb_block に ソーシャルブロックがあれば削除
$blockId = $this->connection->fetchColumn("SELECT id FROM dtb_block WHERE file_name = 'social_buttons'");
if ($blockId > 0) {
$this->addSql("DELETE FROM dtb_block_position WHERE block_id = ?", [$blockId]);
$this->addSql("DELETE FROM dtb_block WHERE file_name = 'social_buttons'");
}
}
}
25 changes: 25 additions & 0 deletions html/template/default/assets/css/style.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion html/template/default/assets/css/style.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion html/template/default/assets/css/style.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion html/template/default/assets/css/style.min.css.map

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions html/template/default/assets/scss/component/_2.3.otherbutton.scss
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,34 @@ Styleguide 2.3.1
bottom: 30px;
}
}

/*
SNSボタン

全ページで使用される、SNS共有ボタンのコンポーネントです。

ex [トップページ フッター](http://demo3.ec-cube.net/)

Markup:
.ec-socialButtons

Styleguide 2.3.2
*/
.ec-socialButtons {
display: flex;
justify-content: flex-end;
line-height: 1;
width: 100%;
max-width: 1150px;
margin: 16px auto 0;
padding-right: 20px;
padding-left: 20px;

.ec-socialButtons__btn:not(:last-of-type) {
margin-right: 16px;
}
}

.front_page .ec-socialButtons {
margin-top: 60px;
}
1 change: 1 addition & 0 deletions src/Eccube/Resource/doctrine/import_csv/en/dtb_block.csv
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ id,device_type_id,block_name,file_name,create_date,update_date,use_controller,de
12,10,News,news,2017-03-07 10:14:52,2017-03-07 10:14:52,0,0,block
13,10,Product Search,search_product,2017-03-07 10:14:52,2017-03-07 10:14:52,1,0,block
14,10,Featured,topic,2017-03-07 10:14:52,2017-03-07 10:14:52,0,0,block
15,10,Social Buttons,social_buttons,2021-02-12 14:00:00,2021-02-12 14:00:00,0,0,block
Copy link
Contributor

Choose a reason for hiding this comment

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

@matsuoshi
このあたりを参考に、マイグレーションの作成もお願いできますか?
https://github.com/EC-CUBE/ec-cube/blob/4.0/app/DoctrineMigrations/Version20201218044542.php

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@chihiro-adachi 確認ありがとうございます、マイグレーションファイルを追加しました

Copy link
Contributor

Choose a reason for hiding this comment

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

マイグレーションでエラーになりました。

An exception occurred while executing 'INSERT INTO dtb_block (
            id, device_type_id, block_name, file_name, create_date, update_date, use_controller, deletable, discriminator_type
        ) VALUES(
            ?, 10, "ソーシャルボタン", "social_buttons", "2021-02-12 14:00:00", "2021-02-12 14:00:00", 0, 0, "block"
        )' with params [15]:
SQLSTATE[42703]: Undefined column: 7 ERROR:  column "ソーシャルボタン" does not exist
LINE 4:             $1, 10, "ソーシャルボタン", "social_buttons", "2...
                            ^

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kiy0taka すいません、マイグレーションのエラーを修正しました

Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
"7","11","1","3","blockposition"
"7","2","1","4","blockposition"
"7","12","1","5","blockposition"
"10","6","1","1","blockposition"
"10","15","1","1","blockposition"
"10","6","1","2","blockposition"
"11","13","1","1","blockposition"
"11","4","1","2","blockposition"
"11","9","1","3","blockposition"
"3","7","2","1","blockposition"
"3","10","2","2","blockposition"
"3","3","2","3","blockposition"
"10","6","2","1","blockposition"
"10","15","2","1","blockposition"
"10","6","2","2","blockposition"
"11","13","2","1","blockposition"
"11","4","2","2","blockposition"
"11","9","2","3","blockposition"
1 change: 1 addition & 0 deletions src/Eccube/Resource/doctrine/import_csv/ja/dtb_block.csv
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
"12","10","新着情報","news","2017-03-07 10:14:52","2017-03-07 10:14:52","0","0","block"
"13","10","商品検索","search_product","2017-03-07 10:14:52","2017-03-07 10:14:52","1","0","block"
"14","10","トピック","topic","2017-03-07 10:14:52","2017-03-07 10:14:52","0","0","block"
"15","10","ソーシャルボタン","social_buttons","2021-02-12 14:00:00","2021-02-12 14:00:00","0","0","block"
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
"7","11","1","3","blockposition"
"7","2","1","4","blockposition"
"7","12","1","5","blockposition"
"10","6","1","1","blockposition"
"10","15","1","1","blockposition"
"10","6","1","2","blockposition"
"11","13","1","1","blockposition"
"11","4","1","2","blockposition"
"11","9","1","3","blockposition"
"3","7","2","1","blockposition"
"3","10","2","2","blockposition"
"3","3","2","3","blockposition"
"10","6","2","1","blockposition"
"10","15","2","1","blockposition"
"10","6","2","2","blockposition"
"11","13","2","1","blockposition"
"11","4","2","2","blockposition"
"11","9","2","3","blockposition"
13 changes: 13 additions & 0 deletions src/Eccube/Resource/template/default/Block/social_buttons.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% if body_class is not defined or (body_class != 'mypage' and body_class != 'cart_page' and body_class != 'registration_page') %}
<div class="ec-socialButtons">
<div class="ec-socialButtons__btn ec-socialButtons--twitter">
<a href="https://twitter.com/share?ref_src=twsrc%5Etfw" class="twitter-share-button" data-show-count="false">Tweet</a>
<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
</div>
<div class="ec-socialButtons__btn ec-socialButtons--facebook">
<div id="fb-root"></div>
<script async defer crossorigin="anonymous" src="https://connect.facebook.net/ja_JP/sdk.js#xfbml=1&version=v9.0" nonce="akhQXdmn"></script>
<div class="fb-share-button" data-href="{{ app.request.uri }}" data-layout="button" data-size="small"><a target="_blank" href="https://www.facebook.com/sharer/sharer.php?src=sdkpreparse" class="fb-xfbml-parse-ignore">シェア</a></div>
</div>
</div>
{% endif %}
31 changes: 31 additions & 0 deletions tests/Eccube/Tests/Web/BlockControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,35 @@ public function testIndex()
);
$this->assertTrue($this->client->getResponse()->isSuccessful());
}

/**
* SNSボタンの表示テスト
*/
public function testSocialButtons()
{
// TOPページはSNSボタンが表示される
$crawler = $this->client->request('GET', $this->generateUrl('homepage'));
$node = $crawler->filter('.ec-socialButtons');
$this->assertNotEmpty($node);

// 商品詳細ページはSNSボタンが表示される
$crawler = $this->client->request('GET', $this->generateUrl('product_detail', ['id' => '1']));
$node = $crawler->filter('.ec-socialButtons');
$this->assertNotEmpty($node);

// マイページはSNSボタンが表示されない
$crawler = $this->client->request('GET', $this->generateUrl('mypage_login'));
$node = $crawler->filter('.ec-socialButtons');
$this->assertEmpty($node);

// カートページはSNSボタンが表示されない
$crawler = $this->client->request('GET', $this->generateUrl('cart'));
$node = $crawler->filter('.ec-socialButtons');
$this->assertEmpty($node);

// 会員登録ページはSNSボタンが表示されない
$crawler = $this->client->request('GET', $this->generateUrl('entry'));
$node = $crawler->filter('.ec-socialButtons');
$this->assertEmpty($node);
}
}