Problem/Motivation
The 7.x version shows a confirmation popup (via ajax) after you add a porduct to cart. Do something similar in 8.x as well. This would be a sweet feature of this module.

Proposed resolution
There are loads of options/ideas available here:
- https://www.drupal.org/project/commerce_add_to_cart_confirmation
- #2622558: [commerce_add_to_cart_confirmation] Commerce add to cart confirmation
- https://www.drupal.org/sandbox/saurabh-vijayvargiya/2886412
Pick one of them, and integrate it with this module. DON'T add anything of your own, as I did in 7.x
Decided to write a sub-module for this feature, and not use the options mentioned above. Reasons:
commerce_add_to_cart_confirmationport is still in progress #2622558: [commerce_add_to_cart_confirmation] Commerce add to cart confirmation. I checked the 8.x fork, and I liked Brock's approach better #15. It is minimal and simple. Uses core's libraries to show the confirmation message as popup. If latercommerce_add_to_cart_confirmationsucceeds as 8.x port, then the sub-module can be re-written so that it usescommerce_add_to_cart_confirmation- https://www.drupal.org/sandbox/saurabh-vijayvargiya/2886412 is WIP. As I saw on the day when I decided to write a sub-module.
This feature should be added as a sub-module. Reason: People may/may-not want the popup confirmation by default. Commerce Kickstart has the ability to disable the popup confirmation, and I want that ability in this module.
Remaining tasks
N/A
User interface changes
Not yet decided.
API changes
N/A
Data model changes
N/A
| Comment | File | Size | Author |
|---|---|---|---|
| #22 | 2910744-22.patch | 13.48 KB | subhojit777 |
| confirmation-popup.png | 13.78 KB | subhojit777 |
Comments
Comment #2
brockfanning commentedFirst off, this module looks REALLY promising and well-maintained! I'm looking forward to helping out, if needed.
Personally I think this popup behavior is a major requirement, because of the fact that AJAX is typically used to avoid changes in page scroll. If the AJAX itself causes the page to scroll to the top, this benefit is lost. In fact most users/clients will probably assume the page refreshed completely.
So I think it's important to get away from status messages and implement this popup functionality. I'm attaching an example patch (not intended to be reviewed) of the first step: removing the scroll change. I'll start thinking about the popup implementation next.
Comment #3
brockfanning commentedHere's a bit more progress - putting the status message into a modal. Still a lot to do though, like implementing the popup with a Twig template.
Comment #4
subhojit777Re: #2:
This is a good UX feature that you mentioned.
Showing the status messages is necessary. While working in 7.x version of this module, people complained that this module does not shows feedback messages, or error messages. So, I do not want to lose this feature in 8.x.
If you still do not want the status messages, you can either fork this module https://github.com/subhojit777/dc_ajax_add_cart, or you can create a new issue and upload a patch there and use it with https://github.com/cweagans/composer-patches.
Re #3:
Thank you for taking the lead :) Some feedback:
Comment #5
subhojit777Comment #6
brockfanning commentedHere's an attempt at this submodule, which also adds a new view mode for product variations, and a Twig template for the popup.
Comment #8
brockfanning commentedTesting fixes.
Comment #9
subhojit777Thank you :) I will test the patch. We will need tests of course. I will update this issue with the test cases and feedback. Thank you.
Comment #10
subhojit777Some observations (mostly nitpiks):
Could you please add this instructions in the parent module's README. This should be added under Installation and usage of the parent README.
s/dc_ajax_add_cart/drupal:dc_ajax_add_cart. Sometimes coder throws error if not done like that.Not required. We are passing the whole entity.
I have a feeling that we can replace
hook_form_alter()with a more specifichook_form_BASE_FORM_ID_alter (). And remove the innerifcondition.Use depedency injection instead.
We don't need this. We are already passing the full entity.
Remove this. This is not used anywhere.
Ideally this should be coming from an admin setting. But not to worry now. We can do that later, in a separate issue.
Just do
dc_ajax_add_cart_popup. Others will be enabled as dependent modules.Have you checked running this in the default
testingprofile.AWESOME!! AWESOME!! This is great. Thank you for adding the tests without being asked.
Sorry for my last comment. I just skimmed the patch last time, didn't checked it fully.
I have also added negative tests. Add another test that would check whether the popup is indeed ajaxified. I check that by not calling
$this->waitForAjaxToFinish().I would say that your work is almost perfect :) 👌 Thank you Brock.
Comment #11
subhojit777Some observations (mostly nitpiks):
Could you please add this instructions in the parent module's README. This should be added under Installation and usage of the parent README.
s/dc_ajax_add_cart/drupal:dc_ajax_add_cart. Sometimes coder throws error if not done like that.Not required. We are passing the whole entity.
I have a feeling that we can replace
hook_form_alter()with a more specifichook_form_BASE_FORM_ID_alter (). And remove the innerifcondition.Use depedency injection instead.
We don't need this. We are already passing the full entity.
Remove this. This is not used anywhere.
Ideally this should be coming from an admin setting. But not to worry now. We can do that later, in a separate issue.
Just do
dc_ajax_add_cart_popup. Others will be enabled as dependent modules.Have you checked running this in the default
testingprofile.AWESOME!! AWESOME!! This is great. Thank you for adding the tests without being asked.
Sorry for my last comment. I just skimmed the patch last time, didn't checked it fully.
I have also added negative tests. Add another test that would check whether the popup is indeed ajaxified. I check that by not calling
$this->waitForAjaxToFinish().I would say that your work is almost perfect :) 👌 Thank you Brock.
Comment #12
brockfanning commentedThanks for the feedback. Here's an attempt to hit all those items.
Comment #14
brockfanning commentedNot sure what's going on with the tests - locally I get occasional/scattered failures but not so many as above. Hopefully it was a fluke, and this time will be better. Also I noticed I forgot the README change, so here is another try with an updated patch.
Comment #15
brockfanning commentedAlmost there - a couple of code-sniff fixes.
Comment #16
subhojit777Thank you :) I will take a look.
Comment #17
subhojit777Thanks. Some more nitpiks and test improvements we could do:
s/The is a sumodule/A submodule.
We should write a test for this.
We should write a test for this.
Will not be required. We are already testing in the parent module's test.
This is okay. But it would be great, if we test this backend-wise as well. Like, check if the current response contains
OpenModalDialogCommand.This is okay. But it would be great, if we test this backend-wise as well. Like, check if the current response contains
OpenModalDialogCommand.Thanks for the effort Brock. I was looking into the bugs that were reported few days ago.
The patch looks perfect. I think we can use this idea in your patch to fix #2930926: Cart block should be updated (ajax) when item removed from cart. I will try to do the fixes next week, and do a manual check on my local. Thank you.
Comment #18
brockfanning commentedHi @subhojit777, cool. Let me know if there's anything else I can help with.
Comment #19
subhojit777Comment #20
subhojit777Comment #21
subhojit777Comment #22
subhojit777Comment #23
subhojit777Hey Brock,
Could you please review the patch in #22. I have added some notes below.
This
ifis covered inAjaxAddCartPopupTest::testAjaxPopup()that you wrote. We are good here.I have added this test which is going to check that the popup appears only if a product is added to cart via ajax, i.e. this
ifcondition:It also had the check whether the product is added to cart. So that means, it checks that product is successfuly aded to cart, while the popup does not appears.
In #17.4 I asked you to remove this. But later I realized that it should be here. Because it checks
AjaxAddToCartPopupSubscriber'sif (!$this->purchasedEntity). i.e. popup appears ONLY when an item is added to cart.In #17.5 I asked for a backend check, i.e. whether
OpenModalDialogCommandis indeed present. That check is going to be tricky here. Mink does not keeps track of the type of response.I also compared this with Commerce core. They are doing something similar to check event subscribers.
Lets keep it this way. Simple. Later we can add a backend check test if there is a problem.
Comment #24
subhojit777Comment #25
n3xo commentedAny ideas on how to display the cart directly in the pop-up? So I think the user experience should improve!
Comment #26
subhojit777You need to show the cart itself in the popup everytime product is added to cart?
You can take the idea from here.
You have to pass the cart block markup in the
$content. You can check the existing module code. You will find the code to programmatically render the block. You have glue them together.Comment #27
brockfanning commented@subhojit777: Everything looks great to me, except the change to .travis.yml is keeping it from applying. Here's a version without that change, in case it's helpful.
Comment #28
subhojit777No that's okay. I changed the Travis settings a bit, otherwise it was failing for readme. Thanks for the review. I will push it and make a new release.
Comment #30
brockfanning commentedComment #32
subhojit777@brockfanning Thanks for the help :)
Comment #33
subhojit777This is now available as beta1 release.