1

When a user registers on my site, I am asking for their first, last, email and address.

I would like to be able to pass the data I already have along to commerce. So when I get to the /address screen, as much of that form is already pre-populated.

I see this:

{% set modelName = modelName is defined ? modelName : 'address' %}
{% set model = address is defined ? address : null %}

So I (think) the ideal solution is to set the model to the user model. I will never allow guest checkout on this site, yet I want to keep as much flexibility as possible (not delete a bunch of stuff). So I gave this a shot:

{% if currentUser %}
    {% set modelName = modelName is defined ? modelName : 'user' %}
    {% set model = user is defined ? user : null %}
{% else %}
    {% set modelName = modelName is defined ? modelName : 'address' %}
    {% set model = address is defined ? address : null %}
{% endif %}

And I get this error:

Craft\UserModel and its behaviors do not have a method or closure named "businessName".

Which makes perfect sense - that's not in the user model.

I could go into the form filed and just set the values like this:

<input type="text" id="{{ modelName }}-firstName" class="form-control"
                   name="{{ modelName }}[firstName]"
                   value="{{ currentUser.firstName }}">

But is that going to lead to disaster? Thank you for any suggestions!

1 Answer 1

1

What I gathered from the documentation, you could try this:

{% set customer = craft.commerce.getCustomer() %}

then

{{ customer.address.businessName }}

or it might be

{{ customer.addresses.businessName }}

https://craftcommerce.com/docs/customer-model

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.