Por ser um software de foco internacional, o Magento precisa ser alterado para atender as necessidades nacionais. Uma delas é referente aos campos Número, Complemento e Bairro que não vem junto ao software por padrão. Apesar disso, o Magento permite configurar até 4 campos diferentes para preenchimento de endereço. Nesse artigo vamos fazer uso desses campos adicionais para o preenchimento do Número, Complemento e Bairro. Lembramos que todos os artigos do blog são focados na versão 1.4.2 do Magento.
O artigo é baseado no artigo do blog Diário de um Programador que sugere inclusive criar novos campos no banco de dados do Magento. Também inclui algumas configurações adicionais. No nosso caso, estamos nos focando na solução mais simples que foi sugerida nos comentários por Octávio Piramo.
Vá ao Painel Administrativo do Magento e em Sistema > Configuração. No menu lateral, vá na categoria Clientes e selecione Configuração. Na aba Opções de Nome e Endereço, no campo Número de linhas para endereço preencha 4. Selecione Salvar.
Agora vamos editar 3 arquivos de template:
app/design/frontend/base/default/template/customer/address/edit.phtml
app/design/frontend/base/default/template/checkout/onepage/billing.phtml
app/design/frontend/base/default/template/checkout/onepage/shipping.phtml
edit.phtml
Procure os códigos abaixo:
<?php for ($_i=2, $_n=$this->helper('customer/address')->getStreetLines(); $_i<=$_n; $_i++): ?>
<li>
<div>
<input type="text" name="street[]" value="<?php echo $this->htmlEscape($this->getAddress()->getStreet($_i)) ?>" title="<?php echo $this->__('Street Address %s', $_i) ?>" id="street_<?php echo $_i?>" />
</div>
</li>
<?php endfor ?>
E troque por:
<li>
<div style="width: 70px;">
<label for="numero"><em>*</em><?php echo $this->__('Número') ?></label>
<div style="width: 70px;">
<input id="numero" style="width: 52px;" title="<?php echo $this->__('Número') ?>" type="text" name="street[]" value="<?php echo $this->htmlEscape($this->getAddress()->getStreet(2)) ?>" /></div>
</div>
<div style="width: 238px;">
<label for="complemento"><?php echo $this->__('Complemento') ?></label>
<div style="width: 238px;">
<input id="complemento" style="width: 220px;" title="<?php echo $this->__('Complemento') ?>" type="text" name="street[]" value="<?php echo $this->htmlEscape($this->getAddress()->getStreet(3)) ?>" /></div>
</div>
<div style="width: 238px;">
<label for="bairro"><em>*</em><?php echo $this->__('Bairro') ?></label>
<div style="width: 238px;">
<input id="bairro" style="width: 221px;" title="<?php echo $this->__('City') ?>" type="text" name="street[]" value="<?php echo $this->htmlEscape($this->getAddress()->getStreet(4)) ?>" /></div>
</div>
</li>
billing.phtml
Procure os códigos abaixo:
<?php for ($_i=2, $_n=$this->helper('customer/address')->getStreetLines(); $_i<=$_n; $_i++): ?>
<li>
<div>
<input type="text" title="<?php echo $this->__('Street Address %s', $_i) ?>" name="billing[street][]" id="billing:street<?php echo $_i?>" value="<?php echo $this->htmlEscape($this->getAddress()->getStreet($_i)) ?>" />
</div>
</li>
<?php endfor ?>
E troque por:
<li>
<div style="width: 70px;">
<label for="billing:numero"><em>*</em><?php echo $this->__('Número') ?></label>
<div style="width: 70px;"><input id="billing:numero" style="width: 52px;" title="<?php echo $this->__('Número') ?>" type="text" name="billing[street][]" value="<?php echo $this->htmlEscape($this->getAddress()->getStreet(2)) ?>" /></div>
</div>
<div style="width: 238px;">
<label for="billing:complemento"><?php echo $this->__('Complemento') ?></label>
<div style="width: 238px;"><input id="billing:complemento" style="width: 220px;" title="<?php echo $this->__('Complemento') ?>" type="text" name="billing[street][]" value="<?php echo $this->htmlEscape($this->getAddress()->getStreet(3)) ?>" /></div>
</div>
<div style="width: 238px;">
<label for="billing:bairro"><em>*</em><?php echo $this->__('Bairro') ?></label>
<div style="width: 238px;"><input id="billing:bairro" style="width: 221px;" title="<?php echo $this->__('City') ?>" type="text" name="billing[street][]" value="<?php echo $this->htmlEscape($this->getAddress()->getStreet(4)) ?>" /></div>
</div>
</li>
shipping.phtml
Procure os códigos abaixo:
<?php for ($_i=2, $_n=$this->helper('customer/address')->getStreetLines(); $_i<=$_n; $_i++): ?>
<li>
<div>
<input type="text" title="<?php echo $this->__('Street Address %s', $_i) ?>" name="shipping[street][]" id="shipping:street<?php echo $_i?>" value="<?php echo $this->htmlEscape($this->getAddress()->getStreet($_i)) ?>" onchange="shipping.setSameAsBilling(false);" />
</div>
</li>
<?php endfor ?>
E troque por:
<li>
<div style="width: 70px;">
<label for="shipping:numero"><em>*</em><?php echo $this->__('Número') ?></label>
<div style="width: 70px;"><input id="shipping:numero" style="width: 52px;" title="<?php echo $this->__('Número') ?>" type="text" name="shipping[street][]" value="<?php echo $this->htmlEscape($this->getAddress()->getStreet(2)) ?>" onchange="shipping.setSameAsBilling(false);" /></div>
</div>
<div style="width: 238px;">
<label for="shipping:complemento"><?php echo $this->__('Complemento') ?></label>
<div style="width: 238px;"><input id="shipping:complemento" style="width: 220px;" title="<?php echo $this->__('Complemento') ?>" type="text" name="shipping[street][]" value="<?php echo $this->htmlEscape($this->getAddress()->getStreet(3)) ?>" onchange="shipping.setSameAsBilling(false);" /></div>
</div>
<div style="width: 238px;">
<label for="shipping:bairro"><em>*</em><?php echo $this->__('Bairro') ?></label>
<div style="width: 238px;"><input id="shipping:bairro" style="width: 221px;" title="<?php echo $this->__('City') ?>" type="text" name="shipping[street][]" value="<?php echo $this->htmlEscape($this->getAddress()->getStreet(4)) ?>" onchange="shipping.setSameAsBilling(false);" /></div>
</div>
</li>