Install HikaShop Starter (free via the "Install from web" interface)
Go in the Extensions>HikaShop>Orders menu
Create a new order with the "new" button
Click on the "invoice" button
It opens a popup with the invoice of the order and there is now a javascript error in the console of the browser.
https://i.imgur.com/DEktYsL.png
No error in the console
The error below in the console of the browser:
Uncaught TypeError: Cannot read properties of null (reading 'children') on line 25 of media/templates/administrator/atum/js/template.js
Joomla 4 latest version + HikaShop latest version
The issue was first reported to us here:
https://www.hikashop.com/forum/orders-management/903764-product-custom-fields-on-orders-invoices.html#338382
The error happens because the code in template.js is looking for header divs to process them. However, in modals these elements are not displayed by the template.
I don't have the error when I check the popups of joomla pages as template.js is not loaded there.
I suppose that this happens because HikaShop loads some elements (like jquery or bootstrap ?) in its popups which leads to the template.js file being loaded even though it's not needed.
It's possible for us to fix this by adding such HTML in the modal views:
<div id="header"><div class="header-title"></div><div class="header-items"></div></div><div id="header-more-items"></div>
There are actually several javascript errors:
However, I think it would be better to modify the javascript of the template to check that the elements are there before processing them.
But maybe someone knowing better how atum works would have another idea ?
Labels |
Added:
No Code Attached Yet
|
Thanks for your answer.
I understand what you're saying, however, the URL of the modal I'm pointing at also has &tmpl=component in it. Here is a screenshot of the content of the modal loaded directly :
https://i.imgur.com/AE8OzWo.png
You can see that the URL has the &tmpl=component parameter but there is the JS error on the template.js file in the console.
Nevertheless, the file media/templates/administrator/atum/js/template.js is still in the header.
And I don't know how that is possible nor what I should do or where to look to find what is doing that. Do you have an idea ?
I tried adding
$wa = JFactory::getApplication()->getDocument()->getWebAssetManager();
$wa->disableScript('template.atum');
to the view displaying the invoice modal in HikaShop, but it doesn't change anything, which is normal since the component.php file of the template is processed after the view file and already does it.
On another note, wouldn't adding the extra check in the javascript be a good practice in case something unexpected happens on the page and the HTML is not there ?
However, I think it would be better to modify the javascript of the template to check that the elements are there before processing them.
As you already know the fix, please make a PR
However, I think it would be better to modify the javascript of the template to check that the elements are there before processing them.
As you already know the fix, please make a PR
Well, I wanted to discuss if this was a good idea or not as I'm not familiar with atum or that javascript.
Some more of if()
should not be bad :)
You can see that the URL has the &tmpl=component parameter but there is the JS error on the template.js file in the console.
if that’s the case then this is a bug in the atum template. In the component.php the template.js should be ignored
@hikashop-nicolas Ok the problem is on your side, the URL needs to be like:
http://host.local:8080/joomla-cms/administrator/index.php?option=com_hikashop&ctrl=order&task=invoice&tmpl=component&type=full&order_id=1
but it is like http://host.local:8080/joomla-cms/administrator/index.php?option=com_hikashop&ctrl=order&task=invoice&tmpl=component&type=full&order_id=1
the &
parts are breaking the bank here
you should escape the url only if it’s going to be displayed in the browser, for php usage keep the non escaped
I guess this can be closed
The URL is not the problem. If you check my previous screenshot, the javascript error is there in the console even though the URL has & and not & in the address bar of the browser.
Are you saying you don't have the error on your end when you look at the invoice ?
In that case, it must mean that there is something else at play which ends up loading the template.js file for some reason on my end and not on yours.
But as Fedik said, I think it's a good idea to add some extra checks in the javascript of the template. I'll look at submitting a PR.
@hikashop-nicolas check your HTML of the iframe. Copy the URL to another browser tab and then edit it and replace the &
with &
Fixing the template.js won't fix anything on your side as you're loading the complete backend (menu, top bar, etc)
The URL is not the problem. If you check my previous screenshot, the javascript error is there in the console even though the URL has & and not & in the address bar of the browser.
Pfff that's the URL of the top page I'm talking about the URL of the iframe Check my images, these are the URLs of the IFRAME, the first one is what your component produces (which is completely wrong) and the 2nd one is what would work...
Seriously there's nothing wrong with the core here, you're escaping the URL when you shouldn't, that's all
No, that's not the URL of the top page, it's the URL of the iframe that I had already openned in another tab.
Please look at my screenshot again: https://i.imgur.com/AE8OzWo.png
The screenshot is of the iframe that I openned in another tab. I did it like that especially to show you that the URL of the iframe is correct and I still have the js error.
If the parameters of the URL for the popup had amp; then the popup would display the dashboard of HikaShop with the Joomla menus and everything, like in your screenshot, with the URL with the amp;.
But as you can see if you look at the popup, it doesn't show the dashboard and the joomla menus in it, only the invoice.
Also if you check the HTML of the top page where the button is, the URL is correct, without the amp; , see here: https://i.imgur.com/h3hTCoT.png
So I'm not sure where you're getting the amp; in your URL from.
@hikashop-nicolas you can add some breakpoints both in the index.php and the component.php to debug this. I already told you what's failing and it's not component.php as that entry point DOES NOT LOAD the template.js...
Yes, I understood that, and I thank you for that explanation.
can this be closed then ? @hikashop-nicolas
Labels |
Added:
Information Required
|
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2022-01-18 12:53:40 |
Closed_By | ⇒ | Quy |
That's the wrong assumption, the script is not loaded for the modals if the correct entry point is set. In the core wherever there's a modal the iframe URL is always pointing to
?tmpl=component
so that the modal will not load unneeded code:Here's one example:
joomla-cms/administrator/modules/mod_multilangstatus/tmpl/default.php
Line 28 in a24393f
And the relative code that disables the script in the component.php entry point:
joomla-cms/administrator/templates/atum/component.php
Lines 34 to 35 in a24393f
In short, this is not a core problem...