0

I create a custom block, for create slider in front-end. This work perfectly in admin and save in database. enter image description here

Now I just add, a groupe_id instance of groupe_customer. so lock my form :

     $fieldset->addField('target', 'select', array(
        'label'     => Mage::helper('home')->__("Target"),
        'name'  => 'sd['.$this->getSlideNumber().'][target]',
        'values'    => Mage::getModel("home/home_target")->getOptionArray()
    ));

    $groups = Mage::getResourceModel('customer/group_collection')
              ->toOptionArray();

    $fieldset->addField('type_groupe_client', 'multiselect',array(
        'label'    =>  Mage::helper('home')->__('Group Customer'),
        'title'     => Mage::helper('home')->__('Group Customer'),
        'name'      => 'sd['.$this->getSlideNumber().'][type_groupe_client]',
        'values'   =>  $groups,
        'required'  => true,
    ));

When i choose multiple group customer, In my controller saveAction(), I check value of multi-select look my code : i do this =>

 $slideData['type_groupe_client'] = implode(',',$slideData['type_groupe_client']); 

    // Slider
            foreach ($this->getRequest()->getParam("sd") as $idx => $slideData) {
                $slide = Mage::getModel("home/home");
                if (isset($slideData["home_id"])) {
                    $slide->load($slideData["home_id"]);
                    if(isset($slideData["remove"])){
                        if(is_file(Mage::getBaseDir('media') . DS . $slide->getImage())){
                            unlink(Mage::getBaseDir('media') . DS . $slide->getImage());
                        }
                        $slide->delete();
                        continue;
                    }
                } else {
                    $slide->setCreatedAt(Zend_Date::now()->get(Zend_Date::ISO_8601));
                }

                $slideData['type_groupe_client'] = implode(',',$slideData['type_groupe_client']); 
                $slide->addData($slideData);

                if (isset($_FILES['sd'.$idx.'_image']['name']) and ( file_exists($_FILES['sd'.$idx.'_image']['tmp_name']))) {
                    $slide->setImage($this->manageImage('sd'.$idx.'_image'));
                } else {
                    $imageParams = $this->getRequest()->getParam('sd'.$idx.'_image');
                    if (isset($imageParams['delete']) && $imageParams['delete'] == 1) {
                        if(is_file(Mage::getBaseDir('media') . DS . $slide->getImage())){
                            unlink(Mage::getBaseDir('media') . DS . $slide->getImage());
                        }
                        $slide->setImage("");
                    }
                }

                $slide->save();
            }

When I var_dump( $slideData['type_groupe_client']), I have so good id in string : string(7) "0,1,2,3" But they not save in database, just the first when I choose , in this example only 0 is save in my row.

Can you help me please ?

  • Please check database column for group id, it might be numeric but instead it should be varchar – Nalin Savaliya Mar 1 '18 at 11:55
  • My row in database "type_groupe_client" is varchar(255) :) – devmagento Mar 1 '18 at 11:59
2

Please try this $slide->setData($slideData); instead $slide->addData($slideData);

  • Ok this work, i don't understand why, before before I add the multiselect this work and save in database. why addData() dont add my new row and after i save ? and setData do this – devmagento Mar 1 '18 at 12:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.