How to insert values inside a select when inserting it into the database

1

I need to insert data into the database, I'm getting the data from an old database, I had some attributes that have a certain value, I created those attributes in the site so that I can receive the data without any problem, the attributes that are type select has its values, the old site for having created and deleted attributes that are used today have high values, such as 42, and that same attribute that I create in the new site comes with value 1, because not being deleted and re-inserted, I would like to know how I would do a check to change the values of the attributes I have.

Example of how I add the fields

As you can see in the code I add the fields like this, I give a select and then put it in its place with ->setNomedoCampo($dadoselecionado) in case the ->setStoreId($loja) is set as id 1 or 2, for having 2 stores, but In the old database, only 1 and 2, how would I deploy a "converter" in this code so that I can exchange those values?

>
while($row = mysqli_fetch_array($select)){
                        $teste = array(
                                $clientes_id = $row['clientes_id'],
                                $nome = $row['nome'],
                                $sobrenome = $row['sobrenome'],
                                $site = $row['site'],
                                $loja = $row['loja'],
                                $grupo = $row['grupo'],
                                $prefixo = $row['prefixo'],
                                $assinatura = $row['assinatura']);

$customer = Mage::getModel("customer/customer");
                                $customer->setId($clientes_id)
                                         ->setFirstname($nome)
                                         ->setLastname($sobrenome)
                                         ->setWebsiteId($site)
                                         ->setStoreId($loja)
                                         ->setGroupId($grupo)
                                         ->setPrefix($prefixo)
                                         ->setMiddlename($assinatura);

Second question

I'd like to know if I have a value in the attribute that does not get a "default" value, such as before setting a value in the database so that it can hit old values. Below you can see how I add these new attributes to the database.

Attributes

Within "option" => array(... is where I put the options that will be selected, would I have to put a value for them at the time of insertion here? Because if you have not had the need to make a converter as in the case I explained above.

    $installer->addAttribute("customer", "occupation",  array(
    "type"     => "varchar",
    "backend"  => "",
    "label"    => "Profissão",
    "input"    => "select",
    "source"   => "",
    "visible"  => true,
    "required" => false,
    "default" => "",
    "frontend" => "",
    "unique"     => false,
    "source" => "eav/entity_attribute_source_table",
    "option" => array('values' => array('System Analist', 'Administrator')) 
    ));

Image with the values of the attributes you would like to change

Then there are the values assigned to the options, 29, 30, 31, 32. However in the other site there are other values, so when I enter the bank will not pull these values correctly, someone would know if you have setar these values before inserting?

    
asked by anonymous 09.11.2017 / 16:46

1 answer

0

I was not able to add already setting a numerical value, I had to change the values "at hand". in the part of the code where is the if is where I do the value exchange, pulling this value in the table by its line $ value = $ row ['value'] I take its variable and make a comparison, if the value is 15 it is changed by 3, then I still save the value in another variable, I put the value in another variable so there is no need for precaution, so let's assume we have a select with two values, we have values 15 and 16 in options, but the attribute we created has the values 3 and 4 would look like this:

Example

 if ($valor == 15) {
     $valor = 3;         //TROCAR PELO VALUE NUMERO DA OPTION
     $valorx = $valor;
     } 
 if ($valor == 16) {
     $valor = 4;         //TROCAR PELO VALUE NUMERO DA OPTION
     $valorx = $valor;
     } 

Code

  while($row = mysqli_fetch_array($select)){
                            $teste = array(
                                    $clientes_id = $row['clientes_id'],
                                    $nome = $row['nome'],
                                    $sobrenome = $row['sobrenome'],
                                    $site = $row['site'],
                                    $loja = $row['loja'],
                                    $grupo = $row['grupo'],
                                    $prefixo = $row['prefixo'],
                                    $assinatura = $row['assinatura']);

                                    if ($loja == 15) {
                                    $loja = 3;         //TROCAR PELO VALUE NUMERO DA OPTION
                                    $lojax = $loja;
                                }  

    $customer = Mage::getModel("customer/customer");
                                    $customer->setId($clientes_id)
                                             ->setFirstname($nome)
                                             ->setLastname($sobrenome)
                                             ->setWebsiteId($site)
                                             ->setStoreId($loja)
                                             ->setGroupId($grupo)
                                             ->setPrefix($prefixo)
                                             ->setMiddlename($assinatura);
    
10.11.2017 / 17:25