cancel
Showing results for 
Search instead for 
Did you mean: 

Custom customer address attributes

   Did you know you can see the translated content as per your choice?

Translation is in progress. Please check again after few minutes.

Custom customer address attributes

I having trouble to show my custom customer address attributes in the frontend.

In the backend the fields are shown and i can insert / edit data of that customers address.

But in the front it wont work.

Then i editted one of the address edit phtml files and added the following

<div class="field number">
            <label class="label" for="number"><span><?php /* @escapeNotVerified */ echo __('Number') ?></span></label>
            <div class="control">
                <input type="text" name="number" value="<?php echo $block->escapeHtml($block->getAddress()->getNumber()) ?>" title="<?php /* @escapeNotVerified */ echo __('Number') ?>" class="input-text <?php /* @escapeNotVerified */ echo $this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('number') ?>" id="number">
            </div>
        </div>
        <div class="field number_addon">
            <label class="label" for="number_addon"><span><?php /* @escapeNotVerified */ echo __('Number addon') ?></span></label>
            <div class="control">
                <input type="text" name="number_addon" value="<?php echo $block->escapeHtml($block->getAddress()->getNumberAddon()) ?>" title="<?php /* @escapeNotVerified */ echo __('Number addon') ?>" class="input-text <?php /* @escapeNotVerified */ echo $this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('number_addon') ?>" id="number_addon">
            </div>
        </div>

Then the error was that the get function wouldnt work.
Then i added the extend of address.php data model

class Address extends \Magento\Customer\Model\Data\Address
{
    
    public function getNumber()
    {
        return $this->_get('number');
    }
    
    public function getNumberAddon()
    {
        return $this->_get('number_addon');
    }
    
}

Then still no data, but inserting and editing data is working, what i can see in the database.

What else do i need todo to get this to work, because google is helping me the wrong way.