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',
Comment | File | Size | Author |
---|---|---|---|
#5 | delete_line_item_button-2269037-5.patch | 919 bytes | nvahalik |
#1 | 2269037_views_export.txt | 10.84 KB | szantog |
Comments
Comment #1
szantog CreditAttribution: szantog commentedComment #2
rszrama CreditAttribution: rszrama commentedTagging for http://contribkanban.com/#/board/commerce/7.x-1.x.
Comment #3
nvahalik CreditAttribution: nvahalik at Centarro commentedInstead of including it in the loop, this patch loads the first result and then adds the order to the form state.
Comment #5
nvahalik CreditAttribution: nvahalik at Centarro commentedMy bad!
Comment #6
mglamanChecks 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.
Comment #7
rszrama CreditAttribution: rszrama at Centarro commentedHmm, 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?