- 追加された行はこの色です。
- 削除された行はこの色です。
* EC-CUBEカスタマイズ [#n13d282b]
#setlinebreak(on);
バージョン: EC-CUBE ver3
#contents
-- 関連
--- [[ECCUBEカスタマイズ - 数量毎に送料を追加する]]
-- 参考
--- http://doc.ec-cube.net/
--- https://github.com/EC-CUBE/ec-cube
--- https://github.com/EC-CUBE/eccube3-doc
--- https://www.doctrine-project.org/projects/orm.html
** css/jsファイル追加 [#sea5b155]
#html(<div style="padding-left:10px;">)
*** css/jsファイル作成 [#t058f4dc]
#html(<div style="padding-left:10px;">)
以下のディレクトリ配下に作成する
以下、custom.css 及び custom.js を追加する場合の例だが、
default_frame.twig で link や script タグをどう書くかだけの話なので、別に何処でも良い気はする。
|種別|ファイル|h
|フロントページ用cs|html/template/default/css/custom.css|
|管理ページ用css|html/template/admin/assets/css/custom.css|
|フロントページ用js|html/template/default/js/custom.js|
|管理ページ用js|html/template/admin/assets/js/custom.js|
#html(</div>)
*** css/jsファイルを読み込むように default_frame.twig を修正する [#je27ad6b]
#html(<div style="padding-left:10px;">)
以下のファイルに link 及び script タグを追加。
|フロントページ用|src/Eccube/Resource/template/default/default_frame.twig|
|管理ページ用|src/Eccube/Resource/template/admin/default_frame.twig|
#html(</div>)
#html(</div>)
** 会員登録をスキップする [#gef5dc9b]
#html(<div style="padding-left:10px;">)
*** 購入時の会員ログイン画面をスキップ [#x0969857]
src/Eccube/Controller/CartController.php
#mycode2(){{
public function buystep(Application $app, Request $request)
{
.
.
//return $app->redirect($app->url('shopping'));
return $app->redirect($app->url('shopping_nonmember'));
}
}}
src/Eccube/Controller/ShoppingController.php
#mycode2(){{
/**
* 購入画面表示
*
* @param Application $app
* @param Request $request
* @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
*/
public function index(Application $app, Request $request)
{
.
.
if (is_null($Customer)) {
// 会員登録スキップ
return $app->redirect($app->url('shopping_nonmember'));
//log_info('未ログインのためログイン画面にリダイレクト');
//return $app->redirect($app->url('shopping_login'));
}
.
.
.
/**
* ログイン
*/
public function login(Application $app, Request $request)
{
// 会員管理しないため、ログインはスキップ
return $app->redirect($app->url('shopping'));
/*
if (!$app['eccube.service.cart']->isLocked()) {
.
.
*/
}}
#html(</div>)
** Controllerを追加する [#h663c8bb]
#html(<div style="padding-left:10px;">)
以下、新着商品の一覧を表示するブロックコントローラを追加する例を記載する。
*** ルーティング追加 [#e1a4a68c]
#html(<div style="padding-left:10px;">)
src/Eccube/ControllerProvider/FrontControllerProvider.php
#mycode2(){{
.
.
$c->match('/block/newitems', '\Eccube\Controller\Block\NewItemsController::index')->bind('block_new_items');
}}
#html(</div>)
*** コントローラ追加 [#i456b6a3]
#html(<div style="padding-left:10px;">)
コントローラからデータベースを読む際には、ORマッパーとしてDoctrineが利用できる。
以下、商品マスタに最近登録された商品の一覧を取得する例を記載する。
※https://www.doctrine-project.org/projects/orm.html
src/Eccube/Controller/Block/NewItemsController.php
#mycode2(){{
<?php
namespace Eccube\Controller\Block;
use Eccube\Application;
use Doctrine\ORM\Query\ResultSetMapping;
class NewItemsController
{
public function index(Application $app)
{
$newItems = $this->selectNewItems($app['orm.em']);
return $app->render('Block/new_items.twig', array(
'NewItems' => $newItems,
));
}
private function selectNewItems($em)
{
$sql = 'SELECT t1.product_id, t1.name, t1.description_detail, t2.file_name
FROM dtb_product t1
left outer join
dtb_product_image t2 on t1.product_id = t2.product_id
WHERE t1.del_flg = 0 and t1.status = 1
ORDER BY t1.create_date desc, t1.product_id
LIMIT 12';
$rsm = new ResultSetMapping();;
$rsm->addScalarResult('product_id', 'product_id');
$rsm->addScalarResult('name', 'name');
$rsm->addScalarResult('description_detail', 'description_detail');
$rsm->addScalarResult('file_name', 'file_name');
$query = $em->createNativeQuery($sql, $rsm);
$result = $query->getResult();
$items = array();
$preId = null;
foreach ($result as $row) {
if ($preId != $row["product_id"]) {
$items[] = $row;
}
$preId = $row["product_id"];
}
return $items;
}
}
}}
#html(</div>)
#html(</div>)
** ブロックをincludeする [#sa6f45cc]
#html(<div style="padding-left:10px;">)
*** 静的ブロックの場合 [#l9864a10]
#html(<div style="padding-left:10px;">)
#mycode2(){{
{{ include('Block/sample1.twig', ignore_missing = true) }}
}}
#html(</div>)
*** 動的ブロックの場合 [#hba4d767]
#html(<div style="padding-left:10px;">)
動的ブロックの場合は controller を通過させる必要がある為、FrontControllerProvider にルーティングを追加後、以下の通り記載する。
※以下のコードは、上記「Controllerを追加する」で追加したコントローラを通過させる場合。
#mycode2(){{
{{ render(path('block_new_items')) }}
}}
#html(</div>)
#html(</div>)
** 注文番号を連番以外にする [#n5eafd2e]
#html(<div style="padding-left:10px;">)
#TODO
src/Eccube/Controller/ShoppingController.php
#mycode2(){{
// TODO:
}}
src/Eccube/Service/ShoppingService.php
#mycode2(){{
// TODO:
}}
src/Eccube/Service/MailService.php
#mycode2(){{
// TODO:
}}
src/Eccube/Resource/template/default/Shopping/complete.twig
#mycode2(){{
// TODO:
}}
src/Eccube/Resource/template/default/Mail/order.twig
#mycode2(){{
// TODO:
}}
#html(</div>)