2017-02-06 8 views
1

私はShopwareを学んでいます。私は解決する方法を理解できない何かに遭遇しました。フロントエンドのアカウントプロフィールフォームの顧客属性を更新する

私は顧客に属性を追加するテストプラグインを作成しています。私は登録フォームにコレスポンデントフィールドを追加して、ドキュメントのどこかで読んだように自動的に値をdbに保存します。

ここで、パスワードフィールドの後のアカウントプロファイルページで属性を編集できるようにしたかったのです。私はそこに入力を入れ、dbから値を表示することさえできました。しかし、値を変更して保存すると、その値は更新されません。私はそれがフィールド名を正しく取得することの問題であるかどうかわからない、または別のものを無効にする必要があるかどうかはわかりません。それとも不可能なのでしょうか?どのようにこれを達成するための任意の助けが大いに感謝されるでしょう。

以下

関連するコード:

プラグイン/ personal_fieldset.tpl

{extends file="parent:frontend/register/personal_fieldset.tpl"} 

{block name='frontend_register_personal_fieldset_password_description'} 
{$smarty.block.parent} 

<div class="register--test-field"> 
    <input autocomplete="section-personal test-field" 
      name="register[personal][attribute][testField]" 
      type="text" 
      placeholder="Test Field" 
      id="testfield" 
      value="{$form_data.attribute.testField|escape}" 
      class="register--field{if $errorFlags.testField} has--error{/if}" 
      /> 
</div> 
{/block} 

アカウントレジスタ

public function install(InstallContext $context) 
{ 
    $service = $this->container->get('shopware_attribute.crud_service'); 
    $service->update('s_user_attributes', 'test_field', 'string'); 

    $metaDataCache = Shopware()->Models()->getConfiguration()->getMetadataCacheImpl(); 
    $metaDataCache->deleteAll(); 
    Shopware()->Models()->generateAttributeModels(['s_user_attributes']); 

    return true; 
} 

ブートストラップ/ profile.tpl

{extends file="parent:frontend/account/profile.tpl"} 

{block name='frontend_account_profile_profile_required_info'} 
<div class="profile--test-field"> 
    <input autocomplete="section-personal test-field" 
      name="profile[attribute][testfield]" 
      type="text" 
      placeholder="Test Field" 
      id="testfield" 
      value="{$sUserData.additional.user.test_field|escape}" 
      class="profile--field{if $errorFlags.testField} has--error{/if}" 
    /> 
</div> 

{$smarty.block.parent} 
{/block} 

答えて

2

それはだとフォームタイプ使用o n登録はプロフィール上で同じではありません。あなたは\ Shopware \バンドル\ AccountBundle \フォーム\アカウント\ PersonalFormType :: buildFormをチェックすると 、あなたは属性がフォームに含まれており、それらが持続されることを意味し

$builder->add('attribute', AttributeFormType::class, [ 
      'data_class' => CustomerAttribute::class 
     ]); 

を見ることができます。そのため、登録フォームにその価値を保存することができます。

あなたは\ Shopware \ Bundle \ AccountBundle \ Form \ Account \ ProfileUpdateFormTypeです。ここで、属性はフォームビルダに追加されません。

ProfileUpdateFormTypeを拡張するにはどうすればよいですか?

  1. 購読Shopware_Form_Builderブートストラップ上(または特定の加入者クラスの)

    ます$ this-> subscribeEvent( 'Shopware_Form_Builder'、 'onFormBuild');メソッドを作成します

  2. は、あなたのロジック(\ Enlight_Event_EventArgs $イベント){ 場合($ event-> getReference()!== \ Shopware \バンドル\ AccountBundle \フォーム\アカウント

    パブリック関数のonFormBuildを追加するonFormBuild \ ProfileUpdateFormType :: class){ リターン; } $ビルダー= $イベント - > getBuilder();このアプローチで

    $builder->add('attribute', AttributeFormType::class, [ 
         'data_class' => CustomerAttribute::class 
        ]); 
    } 
    

すべての属性は、プロフィールフォームにご利用いただけます。

「属性」の代わりに「追加」プロパティを使用してから、コントローライベントをサブスクライブするか、コントローラのアクションを呼び出してカスタムデータを処理することができます。

関連する問題