The Remove button doesn't show any message when a element is removed from the cart, it should display something as the Update cart or Add to cart buttons do.

Comments

pcambra’s picture

Pull request on https://github.com/pcambra/drupalcommerce/commit/de339c232d58587933670bc...

I've noticed that commerce_cart_order_product_line_item_delete gets the line_item_id and then does a wrapper so this would mean wrapping twice for the deletion, what do you think of replacing line_item_id as parameter for the wrapper itself?
The only other function affected is this one: commerce_cart_order_empty, which, by the way doesn't seem to be invoked anywhere

pcambra’s picture

Status: Active » Needs review
rszrama’s picture

Status: Needs review » Needs work

This won't work because it supposes that field will always be used to remove an item from the shopping cart. Instead, what needs to happen is the field's submit handler should just have a generic "Line item deleted." message when a remove button is clicked, but it should happen in its own submit handler so it can be overridden by the cart form to use a submit handler with a cart specific message.

You can see an example of this with the save button for the form. The submit array for the button specifies a separate submit handler found in commerce_line_item.module that displays the save message:

  $form['actions']['update'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
    '#submit' => array_merge($form['#submit'], array('commerce_line_item_line_item_views_form_submit')),
  );

The cart module alters the button's value and its #submit array to use a different submit handler for the message:

    // Change the Save button to say Update cart.
    $form['actions']['update']['#value'] = t('Update cart');
    $form['actions']['update']['#submit'] = array_merge($form['#submit'], array('commerce_cart_line_item_views_form_submit'));

When you give this another shot, just go ahead and wipe your branch and start over so I don't have to pull in this commit with the final solution.

pcambra’s picture

Status: Needs work » Needs review

Code moved to a submit function, same way that the update cart button does:
https://github.com/pcambra/drupalcommerce/commit/4d63e8fb1d73a48e9117e77...

rszrama’s picture

Status: Needs review » Needs work

Not quite there yet... you're getting the idea, but you're still referencing a "cart" from the line item module. The message in the default submit handler should just be "Line item deleted.", and the Cart module can alter the #submit array to use a different message submit handler about removing the item from the cart.

The first code block in my comment above was from the Line Item module, but the second one was from the Cart module.

rszrama’s picture

Issue tags: +beta blocker
pcambra’s picture

Assigned: Unassigned » pcambra
Status: Needs work » Needs review

Another version, this one with a default message in line_items module and the cart module overriding it

https://github.com/pcambra/drupalcommerce/commit/c332714020a509245d1a635...

rszrama’s picture

Cool. Looking much closer - I don't understand why you put the wrapper into the $form_state, though. : ?

pcambra’s picture

I think that at the point that the submit gets called, the line item has been already deleted, so is not possible to load the line item in the submit callback, we could also put only the title in the form state and move the conditions to the _form_alter instead to the submit.

rszrama’s picture

Oooh, good point. Didn't think of that. ; )

Maybe we just want to store the title or something then? Or, actually, if we store the line item itself, it can still be wrapped on submit. The wrapper doesn't depend on any data coming from the database.

pcambra’s picture

recidive’s picture

Status: Needs review » Reviewed & tested by the community

I've tested it and it works.

rszrama’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for the patch and review. Committed.

Status: Fixed » Closed (fixed)
Issue tags: -beta blocker

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