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?
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
– Philip Developer
Yes, Mangento is a complex and simple tool at the same time, we just have to "unravel" it and it becomes a great tool.
– Gustavo Souza