Warning: __clone method called on non-object in commerce_cart_order_refresh() (line 791 of /home/.../modules/commerce/modules/cart/commerce_cart.module).

I get this error when a line item has been deleted from an order prior to the cart being viewed. checking the loop in the function I find that the line item that throws the error is set to NULL. It is removed from the order with $order_wrapper-line_items->offsetUnset(), the order is saved, and then the line item is deleted.

1. Are there clear instructions for properly removing a line item from an order to avoid the array object still having a NULL pointer for the key?

2. In the alternative can we add a not null conditional for the loop to avoid this error?

Comments

graker’s picture

I have the same error, on the sime line.

The issue appeared when user was trying to delete an entry from the cart, using Commerce Cart Ajax module. The ajax error was thrown and then the site gone BSOD with the error described by topic starter.

Everett Zufelt’s picture

Category: bug » support
Status: Active » Needs review

I was actually testing on 7.x-1.2, I notice on 7.x-1.x that this is fixed. Can someone tell me whre I might find the patch of this change for use w/ drush make?

commerce-7.x-1.x: commerce_cart.module

function commerce_cart_order_refresh($order) {
  $order_wrapper = entity_metadata_wrapper('commerce_order', $order);

  // Loop over every line item on the order...
  $line_item_changed = FALSE;

  foreach ($order_wrapper->commerce_line_items as $delta => $line_item_wrapper) {
    // If the current line item actually no longer exists...
    if (!$line_item_wrapper->value()) {
      // Remove the reference from the order and continue to the next value.
      unset($order_wrapper->commerce_line_items[$delta]);
      continue;
    }
Everett Zufelt’s picture

Status: Needs review » Fixed

I found #1423204: Add some self healing for order line item references. Looks like it is dependent on an Entity module patch that just got committed 2 days ago. So, it's wait for releases or patch manually for now.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.