I'm using customized commerce cart view. I added delete button to cart, after clicking on it, I get the usual
EntityMetadataWrapperException: Invalid data value given. Be sure it matches the required data type and format. in EntityDrupalWrapper->set() (line 736 of /home/szantogabor/public_html/stocklogos/stocklogos/sites/all/modules/contrib/entity/includes/entity.wrapper.inc).
error.

It seems, the form of delete button doesn't contain the $order object, so the first arg of rules event After removing a product from the cart is FALSE.

I'm not sure, it is the proper way, but I could make it work with this:

--- a/modules/line_item/includes/views/handlers/commerce_line_item_handler_field_edit_delete.inc
+++ b/modules/line_item/includes/views/handlers/commerce_line_item_handler_field_edit_delete.inc
@@ -40,6 +40,8 @@ class commerce_line_item_handler_field_edit_delete extends views_handler_field {
     // in order to get the base key value (for example, nid for nodes).
     foreach ($this->view->result as $row_id => $row) {
       $line_item_id = $this->get_value($row);
+      $line_item = commerce_line_item_load($line_item_id);
+      $form_state['order'] = commerce_order_load($line_item->order_id);
 
       $form[$this->options['id']][$row_id] = array(
         '#type' => 'submit',
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

szantog’s picture

FileSize
10.84 KB
rszrama’s picture

Version: 7.x-1.9 » 7.x-1.x-dev
Issue tags: +sprint
nvahalik’s picture

Status: Active » Needs review
FileSize
901 bytes

Instead of including it in the loop, this patch loads the first result and then adds the order to the form state.

$first_line_item = reset($this->view->result);
$line_item = commerce_line_item_load($first_line_item);
$form_state['order'] = commerce_order_load($line_item->order_id);

Status: Needs review » Needs work

The last submitted patch, 3: delete_line_item_button-2269037-3.patch, failed testing.

nvahalik’s picture

Status: Needs work » Needs review
FileSize
919 bytes

My bad!

mglaman’s picture

Status: Needs review » Reviewed & tested by the community

Checks out for me! I wonder how many times we need to load an order from a line item ID and if a helper function issue should get tossed open.

rszrama’s picture

Category: Bug report » Support request
Status: Reviewed & tested by the community » Postponed (maintainer needs more info)

Hmm, honestly I'm not sure what we should do here, but the patch smells. It may solve the original use case, but what about when the View contains line items from multiple orders? Or line items from no order?

Additionally, I added a delete button to my shopping cart block and it worked just fine without this patch. I think we need better steps to reproduce this issue and then some accommodation, say, to only load an order into the form state when all line items are of the same order. But more likely we just need to leave the handler alone and to fix whatever is expecting the order to be in the form state.

To start with, can we get steps to reproduce the issue from a vanilla Drupal Commerce install?