forked from EC-CUBE/ec-cube
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request EC-CUBE#4920 from matsuoshi/feature/new-item-block
新着商品ブロックにて、商品を動的に表示する
- Loading branch information
Showing
10 changed files
with
205 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/Eccube/Resource/template/default/Block/auto_new_item.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,4 +43,4 @@ file that was distributed with this source code. | |
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |