Array saving data in the bank with a field written array

0

I have two fields which saved in the database (in this case would be to review the application in magento, but that does not matter much). These fields are being saved correctly, but with a problem, it saves one of the fields written array . The datum and address type fields are saved correctly.

HTML code for fields:

<div class="field small small-left left">
  <label for="comments"><?php echo $this->__('Referência: ') ?></label>
  <div class="input-box">
      <input style="width: 100% !important;" class="input-text" id="comments_1" name="comments[]" title="<?php echo $this->__('Pontos de Referência') ?>" />
   </div>
</div>

   <div class="field info">
    <label for="commentsEnd" class="tipoEnd">Tipo de Endereço:</label>
    <div class="input-box">
       <div class="styled-select">
       <select id="comments_2" name="comments[]" title="<?php echo $this->__('Tipo de Endereço') ?>" class="onestep">
          <option value="">Selecione</option>
          <option value="residencial">Residencial</option>
          <option value="comercial">Comercial</option>
       </select>
       </div>
    </div>

code in the module Model, which runs the Array and saves the fields:

if (!empty($oscOrderData['comments'])) {

    $order = $observer->getEvent()->getOrder();
    /* @var $order Mage_Sales_Model_Order */

    // Force array type
    if(!is_array($oscOrderData['comments']))
        $oscOrderData['comments'] = array($oscOrderData['comments']);

    foreach($oscOrderData['comments'] as $comment) {
        $order->addStatusHistoryComment($comment);
    }
    $order->save();
}
    
asked by anonymous 11.10.2017 / 21:43

1 answer

0

The problem was not to have more than input with name="comments[]" , but it was in the duplication of the code in the Observer.php file of the module, ie, there were two equal codes and so I was saving a field to more written Array . I removed one of the codes and the problem was solved.

    
13.10.2017 / 18:26