1

I'm using Commerce 3.4.16, Craft 3.7.51.

I'm able to enter an address as part of checkout, and I can see that address in the CP, but when I go to the edit address screen on the front end, I get this error:

Calling unknown method: craft\elements\MatrixBlock::firstName()
...    
in .../templates/shop/_private/address/form.twig

The relevant code is:

{{ input('text', modelName ~ '[firstName]', model ? model.firstName : '', {
    id: modelName ~ '-firstName',
    class: ''
}) }}

I get the error in my custom template, and also when using the default templates.

If I take everything else out of the template, both {{ model }} and {{ modelName }} are defined, so I'm not sure what's going on.

1 Answer 1

1

You have a variable called model set to a matrix block (as per the error, a matrix block doesn't have a firstName field). The model needs to be an address model.

2
  • But there is no matrix block. I’m not sure why it thinks it’s a matrix and not an address model. The code is straight from the default templates.
    – artmem
    Sep 20, 2022 at 11:43
  • 2
    Figured it out. I was setting an unrelated variable called "address" that was referring to a matrix block in my layout template. That was conflicting with my model variable which was also set to "address". Changing the name of my original variable resolved the issue.
    – artmem
    Sep 20, 2022 at 14:41

Your Answer

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

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