1
Answers
Vote up!
3
Vote down!

Add a remove item button on checkout page

On the first step of checkout process I have cart view. but i have to give the customer the chance to remove items from his cart at this stage.

I edited the view Shopping cart summary (Commerce Order) by adding a (Line Item) Commerce Line Item: Delete button (Remove).
But if we show button in view it becomes part of checkout suborm.
It always executes "Continue" button.

I tried to make "remowe" button with #ajax. But ajax 'triggering_element' becomes always first button of checkout form.

I found the same question at Drupal answers

Asked by: milkovsky
on October 6, 2013

Comments

My current solution is to build products cart table manualy in code directly in my custom commerce pane (without views ). Than my ajax works fine. But this takes a lot of time and my form is not flexible

- milkovsky on October 7, 2013

1 Answer

Vote up!
0
Vote down!

Copied my response here from Drupal Answers:

This is a pretty common support request, and the gist of it is you cannot use Views form functionality on Views embedded in the checkout form. The reason is pretty simple to understand - you end up nesting a FORM tag within a FORM tag because Views doesn't know that it's building form elements to render inside another form. The solution is not so simple.

The best advice I've been able to give thus far is to disable the cart contents checkout pane and create a Views block instead that uses the form functionality. However, if someone removes an item from the cart after making a change elsewhere on the page, the page would refresh and that data would be lost. Thus you'll want to figure out a way to have that remove button work via AJAX, which is totally possible through the forms API but remains undocumented as far as I know. If you do code a solution, a blog post about it or doc page on d.o would be great.

- Ryan

Ryan Szrama
Answer by: Ryan Szrama
Posted: Apr 25, 2014

Comments

@Ryan, thank you for the answer. I saw your post there. The advice is useful.
My checkout process was with very tricky design, so implementing separate block was not an easy task.
My solution was write custom pane and render the cart table (that was generated the views) on my own. So I created table in my form with amount textbox, buttons "update" (update amount) and "delete".
It was the best solution that I found. And I don't find it very good only because solution is not fast. You had to write all ajax callbacks for buttons on your own and the form was not simple.
The question is still open.

- milkovsky on April 25, 2014