Error: Call to a member function getPurchasableEntityTypeId() on null in Drupal\commerce_order\Entity\OrderItem::bundleFieldDefinitions() (line 326 of modules/commerce/modules/order/src/Entity/OrderItem.php).

Drupal\commerce_order\Entity\OrderItem::bundleFieldDefinitions(Object, NULL, Array) (Line: 331)
Drupal\Core\Entity\EntityFieldManager->buildBundleFieldDefinitions('commerce_order_item', NULL, Array) (Line: 298)
Drupal\Core\Entity\EntityFieldManager->getFieldDefinitions('commerce_order_item', NULL) (Line: 68)
Drupal\og\OgGroupAudienceHelper->getAllGroupAudienceFields('commerce_order_item', NULL) (Line: 46)
Drupal\og\OgGroupAudienceHelper->hasGroupAudienceField('commerce_order_item', NULL) (Line: 269)
Drupal\og\Og::isGroupContent('commerce_order_item', NULL) (Line: 151)
Drupal\og_ui\BundleFormAlter->addGroupContent(Array, Object) (Line: 73)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joachim created an issue. See original summary.

IIAasattler’s picture

I get this same error message when I attempt to click "Add view from template", even though what I want to do has nothing to do with Commerce (I'm adding a calendar to my site.) I have uninstalled and reinstalled the Calendar and Views Template modules, but this continues to prevent me from adding a new view to my site, but I cannot uninstall and reinstall Commerce as the shopping cart is fully functional. Not sure what is interfering here.

nydragondad’s picture

I face the similar issue, but I did not install OG, instead, I have the group module, I guess it has something to do with the group feature, if possible, can someone share your solution here, thanks.

otarza’s picture

I have same problem and it's not related to OG or group module because I don't have any of those installed.

I just have all Commerce core modules enabled and Calendar module.

When I try to "Add view from template" I get this error.

joachim’s picture

My bug at least is caused by OG, which doesn't check in its form alterations whether the current entity actually has a non-NULL id before going off to get fields.

The crash doesn't occur on other forms to add entity types because those don't have a bundleFieldDefinitions() method in their entity class.

jwjoshuawalker’s picture

Title: OG causes 'Add order item type' form to crash » OG, Calendar modules cause 'Add order item type', 'Add view from template' forms to crash

Same here, happens with Calendar module on and visiting "Add view from template".
No error with Calendar module off.

This is the line in OrderItem.php:

$order_item_type = OrderItemType::load($bundle);
$purchasable_entity_type = $order_item_type->getPurchasableEntityTypeId();

$order_item_type is NULL when it tries.

joachim’s picture

jwjoshuawalker’s picture

@joachim,

Not sure, as far as I can tell, the core and Webform modules (for reference) do it in the same way Commerce is.

Taxonomy being an oddball, see below example:

/modules/taxonomy/taxonomy.routing.yml:    _entity_create_access: 'taxonomy_term:{taxonomy_vocabulary}'
/modules/taxonomy/taxonomy.routing.yml:    _entity_create_access: 'taxonomy_vocabulary'
/modules/views_ui/views_ui.routing.yml:    _entity_create_access: view
/modules/shortcut/shortcut.routing.yml:    _entity_create_access: 'shortcut_set'
mglaman’s picture

Can we identify what Calendar module is doing to cause this crash? Before Workbench Moderation did the same and we found a fix.

I don't want to add a test which includes Calendar due to how the Drupal.org facade works. It'll then add test_dependencies as require-dev (effectively adding it to all sites who run composer without --no-dev)

dkolarevic’s picture

Same problem here with Calendar module. I removed line 71 in ViewsFieldTemplate.php. Not sure if this is the best way but in my case that worked.

pimok3000’s picture

I can confirm that the patch from #10 is working for me with no side effects (so far ... :) )

snsblvd’s picture

The patch needed to modified the calendar module file "/src/Plugin/ViewsTemplateBuilder/ViewsFieldTemplate.php", that's why I had to adjust the patch a bit. In my case the OG Module is not installed (only commerce, calendar, views_templates). And its working (but I have no idea what the patch has for impact). Im a newbie about coding/modules.

But should this issue not go into the calendar module or is this just an ugly fix?

pyxio’s picture

i have the same issue but i am not using calendar. does anybody have any idea what is causing my errors? it happens when i click the uninstall tab

The website encountered an unexpected error. Please try again later.
Error: Call to a member function getPurchasableEntityTypeId() on null in Drupal\commerce_order\Entity\OrderItem::bundleFieldDefinitions() (line 377 of modules/contrib/commerce/modules/order/src/Entity/OrderItem.php).
Drupal\commerce_order\Entity\OrderItem::bundleFieldDefinitions(Object, 'addon', Array) (Line: 362)
Drupal\Core\Entity\EntityFieldManager->buildBundleFieldDefinitions('commerce_order_item', 'addon', Array) (Line: 329)
Drupal\Core\Entity\EntityFieldManager->getFieldDefinitions('commerce_order_item', 'addon') (Line: 195)
Drupal\Core\Entity\EntityManager->getFieldDefinitions('commerce_order_item', 'addon') (Line: 427)
Drupal\Core\Entity\EntityDisplayBase->getFieldDefinitions() (Line: 181)
Drupal\Core\Entity\EntityDisplayBase->init() (Line: 143)
Drupal\Core\Entity\EntityDisplayBase->__construct(Array, 'entity_view_display') (Line: 175)
Drupal\Core\Entity\Entity\EntityViewDisplay->__construct(Array, 'entity_view_display') (Line: 322)
Drupal\Core\Entity\EntityStorageBase->mapFromStorageRecords(Array, Array) (Line: 189)
Drupal\Core\Config\Entity\ConfigEntityStorage->doLoadMultiple(NULL) (Line: 242)
Drupal\Core\Entity\EntityStorageBase->loadMultiple(NULL) (Line: 534)
Drupal\Core\Entity\Entity::loadMultiple(NULL) (Line: 21)
Drupal\bootstrap_layouts\Plugin\BootstrapLayouts\Ds->loadInstances() (Line: 41)
Drupal\bootstrap_layouts\BootstrapLayoutsUninstallValidator->validate('bootstrap_layouts') (Line: 560)
Drupal\Core\Extension\ModuleInstaller->validateUninstall(Array) (Line: 99)
Drupal\Core\ProxyClass\Extension\ModuleInstaller->validateUninstall(Array) (Line: 123)
Drupal\system\Form\ModulesUninstallForm->buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 514)
Drupal\Core\Form\FormBuilder->retrieveForm('system_modules_uninstall', Object) (Line: 271)
Drupal\Core\Form\FormBuilder->buildForm('system_modules_uninstall', Object) (Line: 74)
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: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 664)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

elaman’s picture

I have this issue when using Default Content Deploy module.

Probable cause:

bundleFieldDefinitions

method doesn't check if bundle is empty. Other modules all have checks. I will check this and provide the patch.

elaman’s picture

Title: OG, Calendar modules cause 'Add order item type', 'Add view from template' forms to crash » bundleFieldDefinitions method in OrderItem class doesn't have failsafe
Status: Active » Needs review
FileSize
4.12 KB

Provided patch should fix the issue. I've tested my use case, please help to test.

joachim’s picture

That patch is babysitting broken code. The $bundle parameter should never be empty.

pyxio’s picture

@Elaman - thank you. this patch fixes the issue.

mglaman’s picture

Status: Needs review » Needs work

Why would bundleFieldDefinitions receive an empty bundle? Other contrib are doing things wrong if this is happening. All entities have bundles, even if they don't have support for configurable bundles (ie: users. The bundle is just "user').

joachim’s picture

Title: bundleFieldDefinitions method in OrderItem class doesn't have failsafe » OG, Calendar modules cause 'Add order item type', 'Add view from template' forms to crash

Indeed. Restoring the original title.

shabana.navas’s picture

I just enabled the Calendar module and getting the same exact behavior going to Add view from template. The bundle we're getting here is the 'event' type.

lithiumlab’s picture

The following error comes out when trying to add a new Calendar view using the Add View from Template button in the views page.
Steps to reproduce:
Enable Commerce 2.x
Enable Calendar

location:
/admin/structure/views/template/list

message:

Error: Call to a member function getPurchasableEntityTypeId() on null in Drupal\commerce_order\Entity\OrderItem::bundleFieldDefinitions() (line 440 of modules/contrib/commerce/modules/order/src/Entity/OrderItem.php).

Applying #15 patch to Commerce 2.8.0 generates another error:

The website encountered an unexpected error. Please try again later.</br></br><em class="placeholder">Drupal\Component\Plugin\Exception\PluginNotFoundException</em>: The &quot;event&quot; plugin does not exist. in <em class="placeholder">Drupal\Core\Plugin\DefaultPluginManager-&gt;doGetDefinition()</em> (line <em class="placeholder">52</em> of <em class="placeholder">core/lib/Drupal/Component/Plugin/Discovery/DiscoveryTrait.php</em>). <pre class="backtrace">Drupal\Core\Plugin\DefaultPluginManager-&gt;getDefinition(&#039;event&#039;) (Line: 16)
Drupal\Core\Plugin\Factory\ContainerFactory-&gt;createInstance(&#039;event&#039;, Array) (Line: 84)
Drupal\Component\Plugin\PluginManagerBase-&gt;createInstance(&#039;event&#039;) (Line: 89)
Drupal\entity\BundlePlugin\BundlePluginHandler-&gt;getFieldDefinitions(&#039;event&#039;) (Line: 68)
entity_entity_bundle_field_info(Object, &#039;event&#039;, Array)
call_user_func_array(&#039;entity_entity_bundle_field_info&#039;, Array) (Line: 391)
Drupal\Core\Extension\ModuleHandler-&gt;invoke(&#039;entity&#039;, &#039;entity_bundle_field_info&#039;, Array) (Line: 387)
Drupal\Core\Entity\EntityFieldManager-&gt;buildBundleFieldDefinitions(&#039;commerce_payment_method&#039;, &#039;event&#039;, Array) (Line: 329)
Drupal\Core\Entity\EntityFieldManager-&gt;getFieldDefinitions(&#039;commerce_payment_method&#039;, &#039;event&#039;) (Line: 71)
Drupal\calendar\Plugin\ViewsTemplateBuilder\ViewsFieldTemplate-&gt;alterViewTemplateAfterCreation(Array, Array) (Line: 120)
Drupal\views_templates\Plugin\ViewsDuplicateBuilderBase-&gt;loadTemplate(Array) (Line: 211)
Drupal\views_templates\Plugin\ViewsDuplicateBuilderBase-&gt;templateExists() (Line: 65)
Drupal\views_templates\Controller\ViewsBuilderController-&gt;templateList()
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber-&gt;Drupal\Core\EventSubscriber\{closure}() (Line: 582)
Drupal\Core\Render\Renderer-&gt;executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber-&gt;wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber-&gt;Drupal\Core\EventSubscriber\{closure}() (Line: 151)
Symfony\Component\HttpKernel\HttpKernel-&gt;handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel-&gt;handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session-&gt;handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle-&gt;handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache-&gt;pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache-&gt;handle(Object, 1, 1) (Line: 50)
Drupal\ban\BanMiddleware-&gt;handle(Object, 1, 1) (Line: 84)
Drupal\shield\ShieldMiddleware-&gt;handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware-&gt;handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware-&gt;handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel-&gt;handle(Object, 1, 1) (Line: 666)
Drupal\Core\DrupalKernel-&gt;handle(Object) (Line: 19)

Any suggestions or workaround given that #15 patch generates another error?

Naitschi’s picture

Got the same Problem as mentioned in #21

andsigno82’s picture

patch #15 worked perfectly in my case. thanks @elaman

mglaman’s picture

Status: Needs work » Closed (outdated)

There hasn't been much traction here, and the problem is in OG/Calendar. Closing as outdated.