Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
My drupal commande and drupal are up to date.
I have tested with drupal commerce development version and same problem.
When I edit an order, I have this error.
Sometimes it works, sometimes it didn't. There is no difference between my order i don't understand why is bugued.
The website encountered an unexpected error. Please try again later.
Error: Call to a member function getCountryCode() on null in Drupal\commerce_order\AddressBook->isAvailable() (line 189 of modules/contrib/commerce/modules/order/src/AddressBook.php).
Drupal\commerce_order\AddressBook->isAvailable(Object, Array) (Line: 99)
Drupal\commerce_order\AddressBook->loadAll(Object, 'customer', Array) (Line: 169)
Drupal\commerce_order\Plugin\Commerce\InlineForm\CustomerProfile->buildInlineForm(Array, Object) (Line: 111)
Drupal\commerce_order\Plugin\Field\FieldWidget\BillingProfileWidget->formElement(Object, 0, Array, Array, Object) (Line: 335)
Drupal\Core\Field\WidgetBase->formSingleElement(Object, 0, Array, Array, Object) (Line: 202)
Drupal\Core\Field\WidgetBase->formMultipleElements(Object, Array, Object) (Line: 104)
Drupal\Core\Field\WidgetBase->form(Object, Array, Object) (Line: 177)
Drupal\Core\Entity\Entity\EntityFormDisplay->buildForm(Object, Array, Object) (Line: 125)
Drupal\Core\Entity\ContentEntityForm->form(Array, Object) (Line: 61)
Drupal\commerce_order\Form\OrderForm->form(Array, Object) (Line: 117)
Drupal\Core\Entity\EntityForm->buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 519)
Drupal\Core\Form\FormBuilder->retrieveForm('commerce_order_default_edit_form', Object) (Line: 276)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 93)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 582)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 151)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 693)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
Comments
Comment #2
bojanz CreditAttribution: bojanz commentedOpen the file throwing the error (AddressBook.php), and go to the line in question (189). It is the return line:
Since $address is NULL, it tells you that you have a broken $profile somewhere in the system, one without an address field, which should be impossible, since the address field is required.
Comment #3
Asterovim CreditAttribution: Asterovim as a volunteer commentedHello Bonjanz and thanks you.
My website use only one country.
I have commented all the
protected function isAvailable(ProfileInterface $profile, array $available_countries)
And now i can see all the order informations. The user profile is not empty.
I think it could be because i don't use the address field with my customer. I have make it private field and all field of address are hidden.
This was not the case before. It's a new bug :(
Comment #5
bojanz CreditAttribution: bojanz at Centarro commentedPushed a fix for the crash in question. There is no reason not to account for an empty address here.
However, keep in mind that you will see other crashes over time, because Commerce was not designed to have profiles without an address. For example, many payment gateways will crash. You can always make sure that your address at least has the country code set, to avoid that problem.
Note that payment gateways have a "Collect billing information" checkbox (#2905028: Add a per-gateway setting to skip collecting billing information) that allows you to configure not collecting billing information (so no $profile at all), but it sounds like you are still collecting other information on the profile.
Comment #7
Beulette CreditAttribution: Beulette as a volunteer commentedHi, I'm getting the same error and can't process to my updates from 2.14 to 2.16 because of it, is there a solution how to add the address field that is missing ?
Comment #8
Beulette CreditAttribution: Beulette as a volunteer commentedOk, actually I have the field when I take a look in back-office.
Maybe the commerce paypal module isn't using it the good way, most required fields aren't populated.