Jump to content

Sauvegarder plusieurs checkbox dans la base de données


Recommended Posts

Bonjour,

 

Je dois ajouter la possibilité de sélectionner plusieurs jours de la semaine dans les paramètres généraux du transporteur (dans la page admin, en dessous de "url suivi"). J'ai créé le champ "shipping_days" dans la tables carrier. J'ai overridé la fonction renderStepOne() de la classe "AdminCarrierWizardControllerCore" comme ceci pour rajouter des case à cocher des jour de la semaine :

 


public function renderStepOne($carrier)
    {
$this->fields_form = array(
'form' => array(
'id_form' => 'step_carrier_general',
'input' => array(
array(
'type' => 'text',
'label' => $this->trans('Carrier name', array(), 'Admin.Shipping.Feature'),
'name' => 'name',
'required' => true,
'hint' => array(
sprintf($this->trans('Allowed characters: letters, spaces and "%s".', array(), 'Admin.Shipping.Help'), '().-'),
$this->trans('The carrier\'s name will be displayed during checkout.', array(), 'Admin.Shipping.Help'),
$this->trans('For in-store pickup, enter 0 to replace the carrier name with your shop name.', array(), 'Admin.Shipping.Help')
)
),
array(
'type' => 'text',
'label' => $this->trans('Transit time', array(), 'Admin.Shipping.Feature'),
'name' => 'delay',
'lang' => true,
'required' => true,
'maxlength' => 128,
'hint' => $this->trans('The delivery time will be displayed during checkout.', array(), 'Admin.Shipping.Help')
),
array(
'type' => 'text',
'label' => $this->trans('Speed grade', array(), 'Admin.Shipping.Feature'),
'name' => 'grade',
'required' => false,
'size' => 1,
'hint' => $this->trans('Enter "0" for a longest shipping delay, or "9" for the shortest shipping delay.', array(), 'Admin.Shipping.Help')
),
array(
'type' => 'logo',
'label' => $this->trans('Logo', array(), 'Admin.Global'),
'name' => 'logo'
),
array(
'type' => 'text',
'label' => $this->trans('Tracking URL', array(), 'Admin.Shipping.Feature'),
'name' => 'url',
'hint' => $this->trans('Delivery tracking URL: Type \'@\' where the tracking number should appear. It will be automatically replaced by the tracking number.', array(), 'Admin.Shipping.Help'),
'desc' => $this->trans('For example: \'http://example.com/track.php?num=@\' with \'@\' where the tracking number should appear.', array(), 'Admin.Shipping.Help')
),
array(
'label' => 'Jours d affichage',
'name' => 'shipping_days',
'type' => 'checkbox',
'values' => array(
'query' => array(
array(
'id' => 'on',
'name' => 'Lundi',
'val' => '1'
),
array(
'id' => 'on',
'name' => 'Mardi',
'val' => '2'
),
array(
'id' => 'on',
'name' => 'Mercredi',
'val' => '3'
),
array(
'id' => 'on',
'name' => 'Jeudi',
'val' => '4'
),
array(
'id' => 'on',
'name' => 'Vendredi',
'val' => '5'
),
array(
'id' => 'on',
'name' => 'Samedi',
'val' => '6'
),
array(
'id' => 'on',
'name' => 'Dimanche',
'val' => '7'
),
),
'id' => 'id',
'name' => 'name'
)
),
)
)
);
}

 

L'affichage se passe bien (je peux sélectionner plusieurs jours de la semaine). Mais l'enregistrement ne se fait pas dans la table carrier. J'ai overridé la classe objectModel CarrierCore en mettant cette ligne :

self::$definition['fields']['shipping_days'] = array('type' => self::TYPE_STRING);

 Cette méthode fonctionne si le champ est de type 'text" mais pas si c'est un groupe de checkbox.

 

Quelqu'un aurait-il déjà réussi à sauvegardé des valeurs de checkbox dans la base de donnée ? par exemple sous forme {1;3;6} pour sauvegarder lundi, mercredi et samedi. Il faudra ensuite que j'affiche dans la partie front seulement les transporteurs du jour de la semaine. Par exemple si on est "mercredi", le transporteur dont le champ 'shipping_days' contient {1;3;6} sera affiché.

 

Merci pour votre aide.

Link to comment
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
×
×
  • Create New...