1

We are working on a magento store website for a customer who only deals business to business. On the Magento onepage checkout, we want the address select dropdown box to show the company name and address, rather than just the individual's name and address. I've been trying to figure out how to do this but am completely stuck. The dropdown itself is given by the code

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

The block that creates this is

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();
    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 '';
}

I'm completely lost with this and any help would be gratefully received.

6

Magento supports multiple formats for addresses.
IN this case the oneline format is used.
You can view and edit this format in System->Configuration->Customer Configuration->Address Templates->Text One Line.
The default value is.

{{depend prefix}}{{var prefix}} {{/depend}}{{var firstname}} {{depend middlename}}{{var middlename}} {{/depend}}{{var lastname}}{{depend suffix}} {{var suffix}}{{/depend}}, {{var street}}, {{var city}}, {{var region}} {{var postcode}}, {{var country}}

If you want to add the company you must insert this piece of markup somewhere in the format above:

{{depend company}}, {{var company}}{{/depend}}

Here is an example. I added the company after the customer name:

{{depend prefix}}{{var prefix}} {{/depend}}{{var firstname}} {{depend middlename}}{{var middlename}} {{/depend}}{{var lastname}}{{depend suffix}} {{var suffix}}{{/depend}} {{depend company}}, {{var company}}{{/depend}}, {{var street}}, {{var city}}, {{var region}} {{var postcode}}, {{var country}}
  • You are my hero! I can't believe it was so simple. I'd been traipsing through masses of code. Many thanks for your help. – scarrott Feb 27 '14 at 18:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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