Hi,

I've got error:

TypeError: Argument 1 passed to Drupal\commerce_order\PriceCalculator::calculate() must implement interface Drupal\commerce\PurchasableEntityInterface, null given, called in /var/www/html/web/modules/contrib/price_difference_formatter/src/Plugin/Field/FieldFormatter/PriceDifferenceFormatter.php on line 51 in Drupal\commerce_order\PriceCalculator->calculate() (line 105 of /var/www/html/web/modules/contrib/commerce/modules/order/src/PriceCalculator.php) 

Prepared a patch to resolve this.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

dj1999 created an issue. See original summary.

interdruper’s picture

Status: Active » Needs review
StatusFileSize
new705 bytes

This error is triggered because the code assumes that $order_item->getPurchasedEntity() will always return an entity, but this can return NULL:

/**
 * Gets the purchased entity.
 *
 * @return \Drupal\commerce\PurchasableEntityInterface|null
 *   The purchased entity, or NULL.
 */
public function getPurchasedEntity();

This can easily happen in practice, when locked carts contains a product variation that have been deleted.

An simplier alternative patch to #1 is provided.

keshavv’s picture

Status: Needs review » Reviewed & tested by the community

Reviewed the patch code and tested it locally. Looks like its working perfect. Moving to RTBC

lubwn’s picture

Patch from #2 works good for me. Thanks a lot!

vvs’s picture

Status: Reviewed & tested by the community » Needs work

Patch #2 is worked against error, but now I have many cart forms on cart page: https://i.imgur.com/GsoBQDM.jpg

chetan 11 made their first commit to this issue’s fork.

chetan 11’s picture

Status: Needs work » Needs review

Hi,
I have fixed the above error on "price difference formatter" module.
Please check the raised MR.
Thanks.

  • trebormc committed 72a8e964 on 8.x-1.x
    Issue #3224337 by trebormc, chetan 11, interdruper, dj1999, keshavv,...
trebormc’s picture

Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.