Jump to content

backoffice customer add dropdown field


massimopasquali
 Share

Recommended Posts

Hello,

I have to modify customer form in backoffice, I need to add a dropdown filed, carrier list and in particolar I have to show the name of carrier, but saveing the "id_carrier".

in my module I have add a hook, the new dropdown filed is "vettore1", nut it doesn't work.

Can you suggest me liek to do that? tnx in advance

public function hookActionCustomerFormBuilderModifier(array $params)
    {

        $queryBus = $this->get('prestashop.core.query_bus');

        $formBuilder = $params['form_builder'];

        $formBuilder->add('panthera_id', null, [
            'label' => $this->getTranslator()->trans('panthera_id', [], 'Modules.Backoffice.Admin'),
            'help' => 'Codice cliente Panthera.',
            'required'   => false,
            'empty_data' => '',
        ]);

        $formBuilder->add('optin', SwitchType::class, [
            'label' => $this->getTranslator()->trans('Privacy', [], 'Modules.Backoffice.Admin'),
            'required' => false,
        ]);

        $formBuilder->add('vettore1', null, [
            'label' => $this->getTranslator()->trans('vettore1', [], 'Modules.Backoffice.Admin'),
            'required'   => false,
            'options' => $idevents = array(
                    array(
                        'idevents' => 1,
                        'name' => 'methode 1'
                    ),
                    array(
                        'idevents' => 2,
                        'name' => 'methode 2'
                    ),
                    array(
                        'idevents' => 3,
                        'name' => 'methode 3'
                    ),
            ),
            //'id' => 'idevents',
            //'name' => 'vettore1'
        ]);

        $formBuilder->add('vettore2', null, [
            'label' => $this->getTranslator()->trans('vettore2', [], 'Modules.Backoffice.Admin'),
            'required'   => false,
            'empty_data' => '',
        ]);

        $formBuilder->add('porto_assegnato', SwitchType::class, [
            'label' => $this->getTranslator()->trans('porto_assegnato', [], 'Modules.Backoffice.Admin'),
            'required'   => false,
        ]);

        $formBuilder->add('abilita_consegna_mezzo_fni', SwitchType::class, [
            'label' => $this->getTranslator()->trans('abilita_consegna_mezzo_fni', [], 'Modules.Backoffice.Admin'),
            'required'   => false,
        ]);

        //$queryBus = $this->get('prestashop.core.query_bus');

        $pantheraIdSettings = $queryBus->handle(new GetPantheraIdSettingsForForm($params['id']));

        $isOptInSettings = $queryBus->handle(new GetOptInSettingsForForm($params['id']));

        //$vettore1Settings = $queryBus->handle(new GetVettore1SettingsForForm($params['id']));

        $vettore2Settings = $queryBus->handle(new GetVettore2SettingsForForm($params['id']));

        $params['data']['panthera_id'] = $pantheraIdSettings->panthera_id();

        $params['data']['optin'] = $isOptInSettings->isOptIn();

        //$params['data']['vettore1'] = $vettore1Settings->description();

        $params['data']['vettore2'] = $vettore2Settings->description();

        $params['data']['porto_assegnato'] = "111";

        $params['data']['abilita_consegna_mezzo_fni'] = "111";

        $formBuilder->setData($params['data']);
    }

 

Share this post


Link to post
Share on other sites

  • 2 months later...

oh i found it.

And yeah this is how i did it:

$formBuilder->add('NAME_OF_FIELD', ChoiceType::class, [
  'label' => 'YOUR_LABEL',
  'required' => false,
  'choices' => [
    'OPTION_NAME' => 'VALUE',
    'OPTION_NAME' => 'VALUE',
	'OPTION_NAME' => 'VALUE'
  ],
]);

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More