3

I want to show the billing address in a div not in select type box.

In billing.phtmlfile

<div class="input-box">
    <?php echo $this->getAddressesHtmlSelect('billing') ?>
</div>

This statement is creating select box and displaying the address. Here is the code in Checkout_Block_Onepage_Abstract.php

public function getAddressesHtmlSelect($type)
{
    if ($this->isCustomerLoggedIn()) {
        $options = array();
        foreach ($this->getCustomer()->getAddresses() as $address) {
            $options[] = array(
                'value' => $address->getId(),
                'label' => $address->format('oneline')

            );

        }
        $addressId = $this->getAddress()->getCustomerAddressId();
        Mage::log($addressId,null,'address.log');
        if (empty($addressId)) {
            if ($type=='billing') {
                $address = $this->getCustomer()->getPrimaryBillingAddress();
            } else {
                $address = $this->getCustomer()->getPrimaryShippingAddress();
            }
            if ($address) {
                $addressId = $address->getId();
            }
        }

        $select = $this->getLayout()->createBlock('core/html_select')
            ->setName($type.'_address_id')
            ->setId($type.'-address-select')
            ->setClass('address-select')
            ->setExtraParams('onchange="'.$type.'.newAddress(!this.value)"')
            ->setValue($addressId)
            ->setOptions($options);

        $select->addOption('', Mage::helper('checkout')->__('New Address'));

        return $select->getHtml();
    }
    return '';
}

This function is returning the address.

1 Answer 1

2

There is no in build function to list the customer address as div

You have get the customer address by following code

use the below code after this

<?php echo $this->getAddressesHtmlSelect('billing') ?>

and hide the address select box (i.e., Display:none)

<?php $customerId = Mage::getSingleton('customer/session')->getCustomer();?>    
<?php $customer = Mage::getModel('customer/customer')->load($customerId->getId()); ?>
<?php $data = array();?>

<?php foreach ($customer->getAddresses() as $address):?>
<?php $data = $address->toArray();?>
<div id="addresseList<?php echo $data['entity_id'];?>">
    <a href="javaScript:void(0);" onclick="setAdd(<?php echo $data['entity_id'];?>,this)" id="<?php echo $data['entity_id'];?>">
        <address>                         
            <?php echo '<p><b>'.$data['firstname'].' '.$data['lastname'].'</b></p>';?>
            <?php echo '<p>'.$data['street'].'</p>';?>
            <?php echo '<p>'.$data['city'].','.$data['region'].','.$data['postcode'].'</p>';?>
            <?php $country_name = Mage::app()->getLocale()->getCountryTranslation($data['country_id']);?>
            <?php echo '<p>'.$country_name.'</p>';?>
            <?php echo 'T: '.$data['telephone'];?>
        </address>
    </a>
</div>
<?php endforeach;?>
 // new address button
<div class="actions text-center">
    <a href="javaScript:void(0);" onclick="setNewAddress()" class="btn"><?php echo $this->__('Add New');?></a>
</div>

then add the below script

<script type="text/javascript">
//<![CDATA[
function setAdd(value)
{
    ​document.getElementById('billing-address-select').value = value;
    //jQuery("#billing-address-select").val(value);
}

function setNewAddress()
{ 
    $('billing-address-select') && billing.newAddress(!$('billing-address-select').value);
}

//]]>
</script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.