Magento2 管理画面themeの作成
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
]
開始行:
[[Magentoめも]]
*Magento2 管理画面themeの作成 [#ed4f20e0]
管理画面側のテンプレートを触りたい場合はthemeを作成すると...
作成したthemeをmodule側に設定し、コントローラーをオーバー...
*設定ファイルの作成 [#v22b4c2a]
app/design/adminhtml/VendorName/ThemeName/ の構成になりま...
VendorName = Yassujp~
ThemeName = blank とします。
app/design/adminhtml/Yassujp/blank/theme.xml
<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-insta...
<title>Yassujp Blank</title>
<parent>Magento/backend</parent>
</theme>
app/design/adminhtml/Yassujp/blank/registration.php
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::THE...
'adminhtml/Yassujp/blank',
__DIR__
);
*module側に定義追加 [#vb42af96]
app/code/Yassujp/HelloWorld/etc/module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-inst...
<module name="Yassujp_HelloWorld" setup_version="1.0...
<sequence>
<module name="Magento_Theme"/>
</sequence>
</module>
</config>
app/code/Yassujp/HelloWorld/etc/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-inst...
<type name="Magento\Theme\Model\View\Design">
<arguments>
<argument name="themes" xsi:type="array">
<item name="adminhtml" xsi:type="string"...
</argument>
</arguments>
</type>
</config>
これで準備がようやく完了です。
コマンドラインにて以下を実行します。
$ php bin/magento setup:upgrade
*変更したいテンプレートをコピー [#oe16ae21]
今回は管理画面でSALES - Orders - View で確認できる注文詳...
該当するテンプレートは以下のパスになります。~
vendor\magento\module-sales\view\adminhtml\templates\orde...
コピー先のパスは以下になります。~
app\design\adminhtml\Yassujp\blank\Magento_Sales\template...
あとはこのテンプレートに追加するだけです。~
Statusの下に以下のように記述してみました。
<div class="admin__field">
<label for="history_price" class="admin_...
<?php echo __('Price') ?>
</label>
<div class="admin__field-control">
<input name="history[price]"
type="text"
id="history_price"
class="admin__control-text"
value="" />
</div>
</div>
*コントローラーをオーバーライドする [#r164211b]
追加したフォームから受け取った値を保存してみます。
app/code/Yassujp/HelloWorld/etc/module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-inst...
<module name="Yassujp_HelloWorld" schema_version="1....
<sequence>
<module name="Magento_Theme"/>
<module name="Magento_Sales"/>
</sequence>
</module>
</config>
app/code/Yassujp/HelloWorld/etc/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-inst...
<type name="Magento\Theme\Model\View\Design">
<arguments>
<argument name="themes" xsi:type="array">
<item name="adminhtml" xsi:type="string"...
</argument>
</arguments>
</type>
<preference for="Magento\Sales\Controller\Adminhtml\...
</config>
vendor\magento\module-sales\Controller\Adminhtml\Order\Ad...
app\code\Yassujp\HelloWorld\Controller\Adminhtml\Order\Ad...
<?php
namespace Yassujp\HelloWorld\Controller\Adminhtml\Order;
class AddComment extends \Magento\Sales\Controller\Admin...
{
public function execute()
{
$order = $this->_initOrder();
if ($order) {
try {
$data = $this->getRequest()->getPost('hi...
if (empty($data['comment']) && $data['st...
throw new \Magento\Framework\Excepti...
}
$notify = isset($data['is_customer_notif...
$visible = isset($data['is_visible_on_fr...
$history = $order->addStatusHistoryComme...
$history->setIsVisibleOnFront($visible);
$history->setIsCustomerNotified($notify);
$history->save();
$comment = trim(strip_tags($data['commen...
$order->save();
/** @var OrderCommentSender $orderCommen...
$orderCommentSender = $this->_objectMana...
->create('Magento\Sales\Model\Order\E...
$orderCommentSender->send($order, $notif...
return $this->resultPageFactory->create();
} catch (\Magento\Framework\Exception\Locali...
$response = ['error' => true, 'message' ...
} catch (\Exception $e) {
$response = ['error' => true, 'message' ...
}
if (is_array($response)) {
$resultJson = $this->resultJsonFactory->...
$resultJson->setData($response);
return $resultJson;
}
}
return $this->resultRedirectFactory->create()->s...
}
}
コマンドラインにて以下を実行します。
$ php bin/magento setup:upgrade
これで入力された金額がコメントの後ろに追加されて保存され...
終了行:
[[Magentoめも]]
*Magento2 管理画面themeの作成 [#ed4f20e0]
管理画面側のテンプレートを触りたい場合はthemeを作成すると...
作成したthemeをmodule側に設定し、コントローラーをオーバー...
*設定ファイルの作成 [#v22b4c2a]
app/design/adminhtml/VendorName/ThemeName/ の構成になりま...
VendorName = Yassujp~
ThemeName = blank とします。
app/design/adminhtml/Yassujp/blank/theme.xml
<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-insta...
<title>Yassujp Blank</title>
<parent>Magento/backend</parent>
</theme>
app/design/adminhtml/Yassujp/blank/registration.php
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::THE...
'adminhtml/Yassujp/blank',
__DIR__
);
*module側に定義追加 [#vb42af96]
app/code/Yassujp/HelloWorld/etc/module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-inst...
<module name="Yassujp_HelloWorld" setup_version="1.0...
<sequence>
<module name="Magento_Theme"/>
</sequence>
</module>
</config>
app/code/Yassujp/HelloWorld/etc/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-inst...
<type name="Magento\Theme\Model\View\Design">
<arguments>
<argument name="themes" xsi:type="array">
<item name="adminhtml" xsi:type="string"...
</argument>
</arguments>
</type>
</config>
これで準備がようやく完了です。
コマンドラインにて以下を実行します。
$ php bin/magento setup:upgrade
*変更したいテンプレートをコピー [#oe16ae21]
今回は管理画面でSALES - Orders - View で確認できる注文詳...
該当するテンプレートは以下のパスになります。~
vendor\magento\module-sales\view\adminhtml\templates\orde...
コピー先のパスは以下になります。~
app\design\adminhtml\Yassujp\blank\Magento_Sales\template...
あとはこのテンプレートに追加するだけです。~
Statusの下に以下のように記述してみました。
<div class="admin__field">
<label for="history_price" class="admin_...
<?php echo __('Price') ?>
</label>
<div class="admin__field-control">
<input name="history[price]"
type="text"
id="history_price"
class="admin__control-text"
value="" />
</div>
</div>
*コントローラーをオーバーライドする [#r164211b]
追加したフォームから受け取った値を保存してみます。
app/code/Yassujp/HelloWorld/etc/module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-inst...
<module name="Yassujp_HelloWorld" schema_version="1....
<sequence>
<module name="Magento_Theme"/>
<module name="Magento_Sales"/>
</sequence>
</module>
</config>
app/code/Yassujp/HelloWorld/etc/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-inst...
<type name="Magento\Theme\Model\View\Design">
<arguments>
<argument name="themes" xsi:type="array">
<item name="adminhtml" xsi:type="string"...
</argument>
</arguments>
</type>
<preference for="Magento\Sales\Controller\Adminhtml\...
</config>
vendor\magento\module-sales\Controller\Adminhtml\Order\Ad...
app\code\Yassujp\HelloWorld\Controller\Adminhtml\Order\Ad...
<?php
namespace Yassujp\HelloWorld\Controller\Adminhtml\Order;
class AddComment extends \Magento\Sales\Controller\Admin...
{
public function execute()
{
$order = $this->_initOrder();
if ($order) {
try {
$data = $this->getRequest()->getPost('hi...
if (empty($data['comment']) && $data['st...
throw new \Magento\Framework\Excepti...
}
$notify = isset($data['is_customer_notif...
$visible = isset($data['is_visible_on_fr...
$history = $order->addStatusHistoryComme...
$history->setIsVisibleOnFront($visible);
$history->setIsCustomerNotified($notify);
$history->save();
$comment = trim(strip_tags($data['commen...
$order->save();
/** @var OrderCommentSender $orderCommen...
$orderCommentSender = $this->_objectMana...
->create('Magento\Sales\Model\Order\E...
$orderCommentSender->send($order, $notif...
return $this->resultPageFactory->create();
} catch (\Magento\Framework\Exception\Locali...
$response = ['error' => true, 'message' ...
} catch (\Exception $e) {
$response = ['error' => true, 'message' ...
}
if (is_array($response)) {
$resultJson = $this->resultJsonFactory->...
$resultJson->setData($response);
return $resultJson;
}
}
return $this->resultRedirectFactory->create()->s...
}
}
コマンドラインにて以下を実行します。
$ php bin/magento setup:upgrade
これで入力された金額がコメントの後ろに追加されて保存され...
ページ名: