Some VM javascripts are not loaded in other templates than [vm]beez3

Started by man.of.earth, September 08, 2019, 19:43:39 PM

Previous topic - Next topic

man.of.earth

Hello,
I'm using other template than vmbeez3 or beez3.
On the cart page, after changing quantity of an item, in the Chrome developer console I get the following errors:

Uncaught TypeError: Virtuemart.checkQuantity is not a function at HTMLInputElement.onchange (cart:1017)
Uncaught TypeError: Virtuemart.checkQuantity is not a function at HTMLInputElement.onclick (cart:1017)
Uncaught TypeError: Virtuemart.checkQuantity is not a function at HTMLInputElement.onblur (cart:1017)

Comparing closely, I saw that in the VMbeez template there are 3 extra VM javascripts:

/components/com_virtuemart/assets/js/vmprices.js
/components/com_virtuemart/assets/js/chosen.jquery.min.js
/components/com_virtuemart/assets/js/cvfind.js

The absence of vmprices.js causes those errors.
For both variants of this this comparison, loading Joomla and VM jquery is unchecked in VM configuration.

What can I do in order that these 3 VM javascripts to be loaded [correctly] in other templates too?

Studio 42

If you have a old template. YOu need to add the code to add the javascript in your template override in :
YOURJOOMLA/templates/YOURTEMPLATE/html/com_virtuemart/cart/default.php
add
<?php echo vmJsApi::writeJS(); ?>

Studio 42


man.of.earth

Curiously, that line of code is already at the end of that file ???.

I also renamed temporarily the /templates/<template_name>/html/com_virtuemart directory and cleared the cache, in order that the template overrides not be used, but those javascripts are still not loaded.

later edit:
I added
vmJsApi::addJScript('vmprices');
in /templates/<TPL_NAME>/html/com_virtuemart/cart/default.php and the error is gone.

It's still curious why this script is loaded when using vmbeez3/beez3 and not when using other templates...

StefanSTS

Quote from: arcturus on September 10, 2019, 13:45:25 PM
It's still curious why this script is loaded when using vmbeez3/beez3 and not when using other templates...

Your question unfortunately is not precise enough.
If jprice is enabled in vmconfig, vmprices is called independently from the template. If that does not happen in "other" templates you have to look at the "other" templates.

It's either a changed setting in VM config, or your "one other" template unsets vmprices because it loads it's own or compresses and combines files.

Since you are investigating so much recently, you'll probably tell us soon where the change of behaviour came from. ;-)
--
Stefan Schumacher
www.jooglies.com - VirtueMart Invoice Layouts

Please use only stable versions with even numbers for your live shop! Use Alpha versions only if you know what risk you are taking.

man.of.earth

Hello StefanSTS,

I don't use a dedicated VM template. Beginning about one year ago, I simply created VM overrides in the current template and modified the files according to the needs.

Of course, I unchecked minification and compression when debugging, and also use a fresh test site for a second opinion.

It makes perfect sense that those 3 javascripts to be loaded independently of the template used, but they are loaded only in vmbeez3 and beez3 :D ???


later edit:
I solved the mystery :D: the difference was that those javascripts are loaded via modules, not cart page (the first two templates in the situation above also had all the modules loaded, and the other two did not).
mod_virtuemart_currencies is the one that loads vmprices.js . Since not all sites use multiple currencies (and do not load/publish mod_virtuemart_currencies), I think the vmprices.js should be loaded conditionally (loaded if not loaded already by the module) in the cart template (/templates/<TPL_NAME>/html/com_virtuemart/cart/default.php), as it's needed when changing the quantities of the products.


Milbo

vmprices.js is included per

vmJsApi::addJScript( 'vmprices',false,false);

in the function jPrice. The function jPrice is called by the views category, productdetails and in the product module, yes.

you can call this vmJsApi::addJScript( 'vmprices',false,false); 100 times, you will see the script only one time rendered.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

man.of.earth

Thanks Milbo for the clarifications.
However, I see that on the cart page, if no VM modules that call the function are also published, vmprices.js is not loaded, and it produces 3 errors upon modifying the quantities of the products added to the cart.
I think it would be a good idea to add it in /templates/YOURTEMPLATE/html/com_virtuemart/cart/default.php .

AH

I also do no see vmprices.js in the cart with my custom override
so added this to the cart/default.php

vmJsApi::addJScript( 'vmprices',false,false);
Regards
A

Joomla 4.4.5
php 8.1