バージョン選択

フォーラム

メニュー

オンライン状況

63 人のユーザが現在オンラインです。 (51 人のユーザが フォーラム を参照しています。)
登録ユーザ: 0
ゲスト: 63
もっと...

サイト内検索

質問 > フロント機能 > 新規会員登録の項目追加について

フロント機能

新規スレッドを追加する

スレッド表示 | 古いものから 前のトピック | 次のトピック | 下へ
投稿者 スレッド
kiki_mtk
投稿日時: 2020/10/15 20:42
対応状況: 解決済
新米
登録日: 2020/10/13
居住地:
投稿: 5
Re: 新規会員登録の項目追加について
お世話になります。
本件、上記のアドバイスを下に修正を加えたところ無事に解決しました。

ありがとうございました。
umebius
投稿日時: 2020/10/14 0:34
対応状況: −−−
登録日: 2016/7/22
居住地:
投稿: 2085
Re: 新規会員登録の項目追加について
ChoiceTypeではなく、EntityTypeを使われると、integerではなくオブジェクト(\Plugin\CustomerRank\Entity\CustomerRank)を直接取得可能です。

EntityTypeの使い方はEC-CUBE内で使用されているので参考にしてみてください。

Symfonyのドキュメントにもあります
https://symfony.com/doc/3.4/reference/forms/types/entity.html


----------------
EC-CUBEカスタマイズ・高速化・脆弱性対策・SEO ご相談ください。

2系・3系から4系へのバージョンアップ実績豊富

kiki_mtk
投稿日時: 2020/10/13 22:52
対応状況: −−−
新米
登録日: 2020/10/13
居住地:
投稿: 5
新規会員登録の項目追加について
[レンタルサーバ] xserver
[OS] Windows10 64bit
[PHP] 7.3.16
[データベース] MySQL5.7
[WEBサーバ] 使用しているWEBサーバ名、バージョン
[ブラウザ] 使用しているブラウザ名、バージョン
[導入プラグインの有無] 会員ランクプラグイン

上記プラグインで「dtb_customer」テーブルに追加された、「customer_rank_id」カラムに値を、

新規会員登録フォームからセレクトボックスを使用して入力したいのですが、

※セレクトボックスで「Gold」を選択→「customer_rank_id」に「1」が格納のように

本来の使用方法は購入額等に応じて管理画面からランクの設定をできるプラグインであり、ユーザー側でランクを選択できるものではない。

\app\Customize\Form\Extension\CustomerRankExtension.phpを作成し以下のコードを作成

class CustomerRankExtension extends AbstractTypeExtension
{

    /**
     * @var CustomerRankRepository
     */
    private $customerRankRepository;


    /**
     * CustomerRankController constructor.
     * @param CustomerRankRepository $customerRankRepository
     */
    public function __construct(CustomerRankRepository $customerRankRepository)
    {
        $this->customerRankRepository = $customerRankRepository;
    }

    public function buildForm(FormBuilderInterface $builder, array $options)
    {

        $CustomerRanks = $this->customerRankRepository->getList();
        $choices = [];
        foreach($CustomerRanks as $CustomerRank){
            $choices[$CustomerRank->getId()] = $CustomerRank->getName();
        }

        $builder
        ->add(
            'CustomerRank',
            ChoiceType::class,
            [
                'label' => trans('customerrank.common.rank'),
                'required' => false,
                'mapped' => true,
                'placeholder' => "ご希望のコースを選択してください",
                'choices' => array_flip($choices),
            ]
        );
    }

    /**
     * {@inheritdoc}
     */
    public function getExtendedType()
    {
        return EntryType::class;
    }

}



上記のコードでセレクトボックスは追加され、valueに値も入っているのですが

Expected argument of type "Plugin\CustomerRank\Entity\CustomerRank or null", "integer" given


のエラーが登録フォーム画面から内容確認画面に遷移したところ発生。

内容の通りInteger型の引数が必要となるのですが、「customer_rank_id」カラムのsetter/getterの管理をしているのが

app\Plugin\CustomerRank\Entity\CustomerTrait.phpの

public function setCustomerRank(\Plugin\CustomerRank\Entity\CustomerRank $customerRank = null)
    {
        $this->CustomerRank = $customerRank;

        return $this;
    }

    public function getCustomerRank()
    {
        return $this->CustomerRank;
    }


のため、setCustomerRank()の引数等を変更してしまうと、通常のプラグインの動作に影響が出てしまうと考えます。

そこで試しに、\app\Customize\Form\Extension\CustomerRankExtension.phpで拡張している、

EntryType.phpが参照している、\app\proxy\entity\src\Eccube\Entity\Customer.phpの中に

public function setCustomerRank($customerRank)
        {
            $this->CustomerRank = $customerRank;

            return $this;
        }


        public function getCustomerRank()
        {
            return $this->CustomerRank;
        }



のgetter/setterを配置したところ、確認画面に遷移が成功しました。

ところが、次の確認画面から登録ボタンを押したところ、以下のエラーが発生

Expected value of type "Plugin\CustomerRank\Entity\CustomerRank" for association field "Eccube\Entity\Customer#$CustomerRank", got "integer" instead.


内容を確認する限り、app\Customize\Controller\EntryController.php内の
$this->entityManager->flush();



の処理中にエラーが発生したものだと思うのですが、こちらも取得した引数の型が「\Plugin\CustomerRank\Entity\CustomerRank」でなければならないのに対し「integer」で取得されているのが原因だと考えます。

あくまで仮設の範疇ですが、

入力フォーム → 内容確認画面 では\app\proxy\entity\src\Eccube\Entity\Customer.php内のsetCustomerRank($customerRank)が呼び出され、

内容確認画面 → 完了画面 ではapp\Plugin\CustomerRank\Entity\CustomerTrait.php内のsetCustomerRank(\Plugin\CustomerRank\Entity\CustomerRank $customerRank = null)が呼び出されているということでしょうか?

改善内容としては、

①setCustomerRank(\Plugin\CustomerRank\Entity\CustomerRank $customerRank = null)の型をinteger型に変える
②現在integer型で取得しているデータを\Plugin\CustomerRank\Entity\CustomerRankのクラスに変える

の2つだと考えていますが、方法がわかりません。

どなたかご助力お願いいたします。





スレッド表示 | 古いものから 前のトピック | 次のトピック | トップ


 



ログイン


EC-CUBE公式 Amazon Payプラグイン

統計情報

総メンバー数は88,710名です
総投稿数は109,948件です

投稿数ランキング

1
seasoft
7367
2
468
3217
3
AMUAMU
2712
4
nanasess
2313
5
umebius
2085
6
yuh
1819
7
h_tanaka
1638
8
red
1570
9
mcontact
1285
10
tsuji
958
11
fukap
907
12
shutta
835
13
tao_s
799
14 ramrun 789
15 karin 689
16 sumida 641
17
homan
633
18 DELIGHT 572
19
patapata
502
20
flealog
485


ネットショップの壺

EC-CUBEインテグレートパートナー

Copyright© EC-CUBE CO.,LTD. All Rights Reserved.