EC-CUBE4で追加された機能、「その他の明細」ですが非常に便利ですよね。
商品じゃないけどよく受注に追加したいような明細を今までは「商品」として登録するかオプション系のプラグインを用いるという手法をとることが多かったのですが、明細を追加することで別に管理することができるようになったわけです。
初期状態では手数料・送料・割引が「その他の明細」に登録されていますが、この種類を増やす方法をご紹介します。
1.mtb_order_item_typeテーブルに明細の種類を追加
まずmtb_order_item_typeテーブルに追加したい明細の種類を登録します。
データベースへの登録はマスタデータ管理から行っても、phpMyAdmin等を使っても方法は問いません。
ID11でその他明細を追加しました。
2. 明細追加のモーダルに表示
src/Eccube/Controller/Admin/Order/EditController.phpを修正します。
コアファイルを修正したくない方はCustomizeディレクトリにこのメソッドを記載すればオーバーライドできます。
/**
* その他明細情報を取得
*
* @Route("/%eccube_admin_route%/order/search/order_item_type", name="admin_order_search_order_item_type")
* @Template("@admin/Order/order_item_type.twig")
*
* @param Request $request
*
* @return array
*/
public function searchOrderItemType(Request $request)
{
if ($request->isXmlHttpRequest() && $this->isTokenValid()) {
log_debug('search order item type start.');
$Charge = $this->entityManager->find(OrderItemType::class, OrderItemType::CHARGE);
$DeliveryFee = $this->entityManager->find(OrderItemType::class, OrderItemType::DELIVERY_FEE);
$Discount = $this->entityManager->find(OrderItemType::class, OrderItemType::DISCOUNT);
$NonTaxable = $this->entityManager->find(TaxType::class, TaxType::NON_TAXABLE);
$Taxation = $this->entityManager->find(TaxType::class, TaxType::TAXATION);
$OrderItemTypes = [
['OrderItemType' => $Charge, 'TaxType' => $Taxation],
['OrderItemType' => $DeliveryFee, 'TaxType' => $Taxation],
['OrderItemType' => $Discount, 'TaxType' => $Taxation],
['OrderItemType' => $Discount, 'TaxType' => $NonTaxable],
['OrderItemType' => $this->entityManager->find(OrderItemType::class, 11), 'TaxType' => $Taxation],
];
return [
'OrderItemTypes' => $OrderItemTypes,
];
}
}
[‘OrderItemType’ => $this->entityManager->find(OrderItemType::class, 11), ‘TaxType’ => $Taxation]の行で、追加したID11の明細をモーダル内に表示しています。
$Taxationは「課税」のデータを指定しています。
3.表示した結果
受注登録画面の「その他の明細を追加」をクリックした際に、モーダルで「その他明細」が追加されれば成功です。

EC-CUBEに関するお問い合わせ
[重要]現在公式にセキュリティサポートが切れていないPHPは8.1以上、MySQLは8.0以上で、対応しているEC-CUBEバージョンは4.2以上です。古いEC-CUBEを使っている方は適切なタイミングでバージョンアップをご検討ください。

EC-CUBEゴールドパートナー