How to insert values into a select when inserting them into the bank

Asked

Viewed 169 times

1

I need to enter data into the database, I’m taking data from an old database, I had some attributes that have a certain value, I created these attributes on the site so I can receive the data without any problem, the attributes that are of type select have their values, from the old site for having created and deleted attributes those that are used nowadays have values "high", for example 42, and this same attribute that I create in the new site comes with value 1, because it has not been deleted and inserted again, i would like to know how I would do a check to exchange the values of the attributes I have.

Example of how to add fields

As you can see in the code I add the fields like this, I give a select and then put it in its proper place with ->setNomedoCampo($dadoselecionado) in the case of ->setStoreId($loja) comes set as id 1 or 2, for having 2 stores, but formerly aviam 4, so I take as 3 and 4 the values of the old bank, but there are these values in the current bank, only 1 and 2, as I would deploy in this code a "converter" so that I can exchange these 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 wonder if there’s a way I can insert a value in the attribute without it gaining a "default" value, like I set before putting a value in the bank so I can hit the 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, could I put a value for them at the time of insertion here? 'Cause if I did I wouldn’t have to make a converter like 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 attributes values you would like to change

So there are the values assigned to options, 29, 30, 31, 32. But in the other site has other values, so when I insert in the bank will not be pulled these values correctly, someone would know if you have to set these values before entering?

inserir a descrição da imagem aqui

1 answer

0


I could not add already setting a numeric value, I had to change the values "in hand". in the part of the code where is the if is where I do the exchange of values, by pulling this value in the table by your row $value = $Row['value'] I take the variable of it and make a comparison, if the value is 15 it is exchanged by 3, then I still save the value in another Variel, I put the value in another variable for precaution does not have the need, so let’s assume that we have a select with two values, we have the values 15 and 16 in options, but the attribute we create 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);
  • 1

    Very cool the way you’re working with this logic there, it reminded me when I modified the admin of the Gento, creating an extension to change the banner and soon, I had to make some insertions in the database tbem, by the admin, but it’s a logic almost similar to this, only it’s all in the same back-end

  • Yes, Mangento is a complex and simple tool at the same time, we just have to "unravel" it and it becomes a great tool.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.