Skip to content

Commit

Permalink
Merge pull request EC-CUBE#4920 from matsuoshi/feature/new-item-block
Browse files Browse the repository at this point in the history
新着商品ブロックにて、商品を動的に表示する
  • Loading branch information
ji-eunsoo authored Apr 1, 2024
2 parents c5ff366 + 9389cef commit 01337a0
Show file tree
Hide file tree
Showing 10 changed files with 205 additions and 1 deletion.
34 changes: 34 additions & 0 deletions app/DoctrineMigrations/Version20240312170000.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?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 Version20240312170000 extends AbstractMigration
{
const NAME = 'dtb_block';

public function up(Schema $schema): void
{
// テーブルが存在しない場合終了
if (!$schema->hasTable(self::NAME)) {
return;
}

$blockExists = $this->connection->fetchOne("SELECT COUNT(*) FROM dtb_block WHERE file_name = 'auto_new_item'");
if ($blockExists == 0) {
$this->addSql("INSERT INTO dtb_block (device_type_id, block_name, file_name, create_date, update_date, use_controller, deletable, discriminator_type) VALUES (10, '新着商品(自動取得)', 'auto_new_item', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, '1', '0', 'block')");
}
}

public function down(Schema $schema): void
{
$this->addSql("DELETE FROM dtb_block WHERE file_name = 'auto_new_item'");
}
}
1 change: 1 addition & 0 deletions app/config/eccube/packages/eccube.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,4 @@ parameters:
- pdf
eccube_login_throttling_max_attempts: 5
eccube_login_throttling_interval: '30 minutes'
eccube_max_number_new_items_get: 5
61 changes: 61 additions & 0 deletions src/Eccube/Controller/Block/AutoNewItemController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Eccube\Controller\Block;

use Eccube\Controller\AbstractController;
use Eccube\Repository\Master\ProductListOrderByRepository;
use Eccube\Repository\ProductRepository;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;

class AutoNewItemController extends AbstractController
{
/**
* @var ProductRepository
*/
private $productRepository;

/**
* @var ProductListOrderByRepository
*/
private $productListOrderByRepository;

public function __construct(
ProductRepository $productRepository,
ProductListOrderByRepository $productListOrderByRepository
) {
$this->productRepository = $productRepository;
$this->productListOrderByRepository = $productListOrderByRepository;
}

/**
* @Route("/block/auto_new_item", name="block_auto_new_item")
* @Template("Block/auto_new_item.twig")
*
* @param Request $request
* @return array
*/
public function index(Request $request)
{
$qb = $this->productRepository->getQueryBuilderBySearchData([
'orderby' => $this->productListOrderByRepository->find($this->eccubeConfig['eccube_product_order_newer']),
])
->setMaxResults($this->eccubeConfig['eccube_max_number_new_items_get']);

return [
'Products' => $qb->getQuery()->getResult(),
];
}
}
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 @@ -14,3 +14,4 @@ id,device_type_id,block_name,file_name,create_date,update_date,use_controller,de
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
17,10,Calendar,calendar,2021-03-16 12:00:00,2021-03-16 12:00:00,1,0,block
18,10,Auto New Items,auto_new_item,2024-03-12 17:00:00,2024-03-12 17:00:00,1,0,block
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 @@ -14,3 +14,4 @@
"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"
"17","10","カレンダー","calendar","2021-03-16 12:00:00","2021-03-16 12:00:00","1","0","block"
"18","10","新着商品(自動取得)","auto_new_item","2024-03-12 17:00:00","2024-03-12 17:00:00","1","0","block"
1 change: 1 addition & 0 deletions src/Eccube/Resource/locale/messages.en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ front.block.eyecatch.view_list: See all
front.block.new_item.title__en: NEW ITEMS
front.block.new_item.title__ja: New Items
front.block.new_item.more: More
# Deprecated https://github.com/EC-CUBE/ec-cube/pull/4920
front.block.new_item.item_1_name: "Colorful Gelato: 'CUBE'"
front.block.new_item.item_1_price: $1,200 (tax incl.)
front.block.new_item.item_2_name: Cherry Ice Cream Sandwiches
Expand Down
1 change: 1 addition & 0 deletions src/Eccube/Resource/locale/messages.ja.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ front.block.eyecatch.view_list: 一覧を見る
front.block.new_item.title__en: NEW ITEM
front.block.new_item.title__ja: 新着商品
front.block.new_item.more: more
# Deprecated https://github.com/EC-CUBE/ec-cube/pull/4920
front.block.new_item.item_1_name: 彩のジェラート"CUBE"
front.block.new_item.item_1_price: ¥1,200(税込)
front.block.new_item.item_2_name: チェリーアイスサンド
Expand Down
42 changes: 42 additions & 0 deletions src/Eccube/Resource/template/default/Block/auto_new_item.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{#
This file is part of EC-CUBE
Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
http://www.ec-cube.co.jp/
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
#}

{% if Products is defined %}
<div class="ec-role">
<div class="ec-newItemRole">
<div class="ec-newItemRole__list">
<div class="ec-newItemRole__listItem">
<div class="ec-newItemRole__listItemHeading ec-secHeading--tandem">
<span class="ec-secHeading__en">{{ 'front.block.new_item.title__en'|trans }}</span>
<span class="ec-secHeading__line"></span>
<span class="ec-secHeading__ja">{{ 'front.block.new_item.title__ja'|trans }}</span>
<a class="ec-inlineBtn--top" href="{{ url('product_list') }}">{{ 'front.block.new_item.more'|trans }}</a>
</div>
</div>
{% for Product in Products %}
<div class="ec-newItemRole__listItem __getAutoNewItemBlock">
<a href="{{ url('product_detail', {'id': Product.id}) }}">
<img src="{{ asset(Product.main_list_image|no_image_product, 'save_image') }}" alt="{{ Product.name }}">
<p class="ec-newItemRole__listItemTitle">{{ Product.name }}</p>
<p class="ec-newItemRole__listItemPrice">
{% if Product.hasProductClass and Product.getPrice02Min != Product.getPrice02Max %}
{{ Product.getPrice02IncTaxMin|price }} ~ {{ Product.getPrice02IncTaxMax|price }}
{% else %}
{{ Product.getPrice02IncTaxMin|price }}
{% endif %}
</p>
</a>
</div>
{% endfor %}
</div>
</div>
</div>
{% endif %}
2 changes: 1 addition & 1 deletion src/Eccube/Resource/template/default/Block/new_item.twig
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ file that was distributed with this source code.
</div>
</div>
</div>
</div>
</div>
62 changes: 62 additions & 0 deletions tests/Eccube/Tests/Web/Block/NewItemTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Eccube\Tests\Web\Block;

use Eccube\Tests\Web\AbstractWebTestCase;

class NewItemTest extends AbstractWebTestCase
{
/**
* {@inheritdoc}
*
* @throws \Doctrine\DBAL\DBALException
*/
protected function setUp(): void
{
parent::setUp();

// レイアウト管理に自動取得の新着商品を追加
$sql = "
insert into dtb_block_position (
section,
block_id,
layout_id,
block_row,
discriminator_type)
values(
7,
18,
1,
3,
'blockposition'
);";

$this->entityManager->getConnection()->exec($sql);
}
public function testNewItemBlock()
{
// 新着商品が表示されている
$crawler = $this->client->request('GET', $this->generateUrl('homepage'));
$node = $crawler->filter('.ec-newItemRole__listItemTitle');
$this->assertTrue(count($node) > 0);
}

public function testAutoNewItemBlock()
{
// 自動取得の新着商品が表示されている
$crawler = $this->client->request('GET', $this->generateUrl('homepage'));
$node = $crawler->filter('.__getAutoNewItemBlock');
$this->assertTrue(count($node) > 0);
}
}

0 comments on commit 01337a0

Please sign in to comment.