I've made a script in a custom module that is dependent on customer-data.js
, a .js file initiated by Magento_Customer.
So, what I did in my module.xml:
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Vendor_AjaxCart" setup_version="2.0.0">
<sequence>
<module name="Magento_Customer" />
</sequence>
</module>
</config>
But still, my .js file which runs in the custom module gets loaded before the customer-data.js.
The only way I can get everything working is using a time out like this:
<script>
setTimeout(function() {
require([
'Vendor_AjaxCart/js/cartAjaxQty'
]);
}, 5000);
</script>
which makes sure it gets loaded AFTER customer-data.js.
Is there another way to fix this?
When I look at app/etc/config.php, my module should be instantiated AFTER Magento_Customer.
I tried doing the following in the .phtml:
<script>
require ([
'jquery'
],
function ($) {
$(document).ready(function () {
require([
'Vendor_AjaxCart/js/cartAjaxQty'
]);
});
});
</script>
But unfortunately no luck either. STILL the file gets loaded before customer-data.js
-- For anyone wanting to see the source code --
Module_AjaxCart
in the module.xml file andVendor_AjaxCart
in your JS.