I updated commerce on a site I am developing a week or so ago, and while everything went fine, I started noticing weird issues with views (I would click on a views field, the AJAX loading widget would come up, and then it would disappear and console showed an AJAX error). I spent a bit of time debugging it today and found the cause, and I figured I would share in case it is happening to anyone else.

I checked Apache logs, and this is the error that I found:

Error: Call to a member function getType() on null in /web/modules/contrib/commerce/modules/price/commerce_price.module on line 58 #0

Line 58 of commerce_price.module is part of a new function that was added with the latest release in order to remove the calculated price option from variations that do not support it, from what I gather, but for whatever reason it was being executed when I clicked views fields like "title" on the product entity to change settings like "link to product".

I commented out this entire if statement, cleared cache, and everything is working as expected:

    if ($field_definition->getType() === 'commerce_price' && !PriceCalculatedFormatter::isApplicable($field_definition)) {
      unset($form['options']['type']['#options']['commerce_price_calculated']);
    }

it is crashing on $field_definition->getType(), because $field_definition can apparently be null sometimes and getType() throws an exception when that happens.

Hopefully this helps anybody facing the same issue out.

Comments

Gode.Agarunov created an issue. See original summary.

bojanz’s picture

Status: Active » Closed (duplicate)

Thanks! Reopened #3088905: The "Calculated" price formatter must not show up for order item fields on the views ui (since it never made it into a tagged release), let's continue there.