EC-CUBE4のご注文手続きのお問い合わせ項目を必須にするプラグインを作る方法です。
まずは以下のコマンドでプラグインの雛形を作ります。
プラグインコードはなんでも良いのですが、今回は「ShoppingMessage」にしてください。
bin/console eccube:plugin:generate
ご注文手続きフォームの拡張
ご注文フォームを拡張します。
自動生成されたプラグイン一式内のForm/Extensionディレクトリ内に以下のOrderTypeExtension.phpファイルを設置して下さい。
<?php
namespace Plugin\ShoppingMessage\Form\Extension;
use Symfony\Component\Form\AbstractTypeExtension;
use Eccube\Form\Type\Shopping\OrderType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
/**
* ご注文手続きのお問い合わせを必須にする
*
* @author Akira Kurozumi <info@a-zumi.net>
*/
class OrderTypeExtension extends AbstractTypeExtension {
public function buildForm(FormBuilderInterface $builder, array $options)
{
if($options['skip_add_form']) {
return;
}
$options = $builder->get('message')->getOptions();
$options['required'] = true;
$options['constraints'][] = new Assert\NotBlank;
$builder->add('message', TextareaType::class, $options);
}
public function getExtendedType()
{
return OrderType::class;
}
}
上記はOrderTypeクラスで設定されているお問い合わせ(message) を必須にするように拡張しています。
プラグインのインストールと有効化
以上で完成です。
プラグインのインストールと有効化を行うと適用されます。
このプラグインのファイル一式はこちら。

このプラグインを有効にすると、
The child with the name “message” does not exist.
というエラーが出て注文完了出来なくなってしまいます。
ご連絡ありがとうございます。
注文完了できないバグを修正しましたのでご確認下さい。
宜しくお願い致します。