Closed (fixed)
Project:
Commerce Ajax Add to Cart
Version:
7.x-2.x-dev
Component:
Code
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
2 Jan 2016 at 05:35 UTC
Updated:
16 Jul 2017 at 08:54 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
joelpittetComment #3
mglamanIf the cart is empty, do any of these resources need to be added?
Comment #4
joelpittet@mglaman Yes, I believe they are needed, if you have AJAX add to cart, the resource needs to be available after the cart addition AJAX to be able to populate 'ajax-shopping-cart-wrapper'. The CSS is self explanatory.
Comment #5
subhojit777I was not able replicate the JS error. The ajax library is required by the "remove from cart" link, and it will only appear if there is some item in the cart.
Comment #6
joelpittetPretty sure this is still needed
Comment #7
subhojit777You are concerned about this part of the module:
We need
drupal_add_library('system', 'drupal.ajax', TRUE);so as to ajaxify the "Remove from cart" link. And this link is only going to appear if there is a product in the cart. And suppose there is a product in cart, then Drupal ajax library is going to be added in the page.This is a vanilla Drupal + Commerce installation, there is no product in cart, and there are no JS errors.

Please mention the steps so that I can replicate the problem.
Comment #8
subhojit777Comment #9
joelpittet@subhojit777 the
dc_ajax_add_cart_html.jsfile tries to extendDrupal.ajaxand there is no check that object does or doesn't exist and that is why the error shows when you don't havedrupal.ajaxlibrary loaded. It's essentially a dependency.The latest code it should be in
dc_ajax_add_cart_include_cart_resources().Any other library that adds
drupal.ajaxwould unintentionally solve this dependency problem.Here's a new patch.
Comment #10
mglamanTo make this even more of a nitpickery: why not hook_library to have dependency declared there. Then we only need to register the library and we get the CSS, JS and dependencies
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/func...
Comment #11
joelpittet@mglaman was going to recommend that as well but didn't want to push my luck because it was already closed:P But if that is preferred I don't mind writing that patch.
Comment #13
subhojit777Yeah true. Thanks for pointing it out. I never thought it this way. I was assuming that the ajax library was added from the block view only. I carried out a test by removing
drupal_add_library('system', 'drupal.ajax', TRUE);and still it was functioning. This patch is infact better than the previous one.The ajax functionalities in the block, and ajaxifying the "Add to Cart" button, all of them needs to be decoupled, but that is not the scope of this issue. I would very much like to decouple them in the 8.x version of this module.
I've opened another issue #2891050: Use hook_library() to add resources which is going to implement Matt's suggestion.
Thank you Joël :)
Comment #14
joelpittetThanks for committing that, I'll post a WIP patch in the other issue.
Comment #15
subhojit777We have a separate issue for adding
hook_library()#2891050: Use hook_library() to add resources