Problem/Motivation
The cart block, if present on the /cart page, and the product remove button as obtained from #2910740: Ajaxify the Remove from cart button has been used, then the cart block should also be ajaxifically updated.
Although this feature is not necessary, but it would be good for UX.
Proposed resolution
Not yet decided. But looks like I have to use dc_ajax_add_cart.refresh_page_elements_helper service.
Help required. See #6
Remaining tasks
Not yet decided.
User interface changes
The cart block should be updated ajaxifically.
API changes
Not yet decided.
Data model changes
N/A
Comments
Comment #2
subhojit777Comment #3
subhojit777Comment #4
subhojit777Comment #5
subhojit777Comment #6
subhojit777I spent a few hours on this issue. I added submit callback in
Drupal\dc_ajax_add_cart_views\Plugin\views\field\RemoveButton, this was removing the order item, and was returning an ajax response that would refresh the cart block. I useddc_ajax_add_cart.refresh_page_elements_helperservice. But it throws an exception:Looks like the views submit callback is not the right place to return the ajax response. (unlike form submit callback)
I also tried doing the above using a custom ajax callback, but it breaks the ajax functionality of the order item removal.
I need help on this issue. It would be great if someone proposes an approach to achieve this, or may be point out what I am doing wrong.
Comment #7
subhojit777Comment #8
subhojit777Not sure but we can make use of the code that's is #2910744: Add a popup confirmation
Comment #9
jefuri commentedSame issue with quantities I guess. The ajax response does not update the view in the cart.
Added a eventsubcriber to update the cart block on order item update, remove and add to make sure this is triggerd.
And not only from the product form.
Comment #10
imclean commentedResult:
PHP Fatal error: Trait 'Drupal\Tests\commerce\FunctionalJavascript\JavascriptTestTrait' not found in /var/www/html/modules/contrib/dc_ajax_add_cart/tests/src/Functional/AjaxAddCartTestBase.php on line 13>For a solution, see: #3045863: Trait 'Drupal\Tests\commerce\FunctionalJavascript\JavascriptTestTrait' not found
Also some coding standard issues.
Comment #11
vasyok commentedFor me #9 does not work. After push Remove button - nothing happened.

Here is my view:
Comment #12
durum commented#9 almost works:
Scenario 1: There is 1 item in the cart. Successfully removes the item & refreshes the block.
Scenario 2: There are 2 or more items in the cart. You remove the last one. Nothing happens. Refresh the page. Item gone.
Scenario 3: There are 2 or more items in the cart. You remove any of them except the last one. Nothing happens. Refresh the page. The item you removed and all the following items are gone.
Same results with Ajax enabled and disabled in the view settings.