1

I've read the docs but I can't seem to get this to work properly. I want to edit a single address on a separate page from where all addresses for a customer are listed. I have the link to the edit page, which looks like this:

<a href="{{ url('account/edit-address') }}?addressId={{ address.id }}">Edit</a>

Then on that edit-address template I have the following:

{% set addressId = craft.request.getParam('addressId') %}

<form method="post">
    {{ getCsrfInput() }}
    <input type="hidden" name="action" value="commerce/customerAddresses/save">
    <input type="hidden" name="redirect" value="account/address-book">

    {% if addressId %}
        <input type="hidden" name="address[id]" value="{{ addressId }}">
    {% endif %}

    <input type="text" name="address[firstName]" value="{{ address ? address[firstName] : '' }}">
    <input type="text" name="address[lastName]" value="{{ address ? address[lastName] : '' }}">
</form>

That leads to a "Variable 'address' does not exist" error. I understand why I get that error but I'm not sure how to get the value field to show the address info. Having a blank form field isn't going to cut it.

1

Are you looking for something like this? The second example will ensure an address variable exists, even if it is set to null.

{% set address = craft.commerce.customer.address(addressId) %}

or

{% set address = address is defined ? address : null %}

As for accessing the data, you would just do this:

{{ address ? address.firstName : '' }}

Another way to do it (without needing to define a null address variable) is:

{{ address.firstName ?? '' }}

| improve this answer | |
  • Yes! Thanks Luke - I wasn't sure how to set the address variable exactly. – Angie Herrera Nov 10 '16 at 2:39

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.