Breaking: #333 - Switch from jQuery to vanilla JavaScript
See Issue 333
Description
Using the jQuery library is outdated. Therefore jQuery in the existing JavaScript code is replaced with vanilla JavaScript. Furthermore is the JavaScript code splitted up and via [Asset Viewhelper](https://docs.typo3.org/other/typo3/view-helper-reference/12.4/en-us/typo3/fluid/latest/Asset/Script.html) included in the templates and partials where the corresponding JavaScript is needed.
For better development of the JavaScript a build process is added, using [esbuild](https://esbuild.github.io/). The original JavaScript files are now located in Build/
where you can find further information how to work with these files during development.
Affected Installations
Installations which use the default templates and partials from the extension just do no longer need to include jQuery. Installations which have individualized templates or partials might need to adapt templates or partials.
Migration
1. Remove old JavaScript It is no longer necessary to include jQuery for this extension.
The old JavaScript file /Resources/
does no longer exist. If it was included in some
JavaScript bundling then it must be removed.
2. Migrate to new JavaScript If you have individual templates and/or partials than you can migrate in two ways:
2. ALTERNATIVE A: Add JavaScript via TypoScript The easier but less performant migration is to include all JavaScript files with TypoScript, e.g. as follows:
page.includeJSFooter {
tx_cart_add_to_cart = EXT:cart/Resources/Public/JavaScript/add_to_cart.js
tx_cart_change_be_variant = EXT:cart/Resources/Public/JavaScript/change_be_variant.js
tx_cart_prevent_multi_submit = EXT:cart/Resources/Public/JavaScript/prevent_multi_submit.js
tx_cart_update_country = EXT:cart/Resources/Public/JavaScript/update_country.js
tx_cart_update_currency = EXT:cart/Resources/Public/JavaScript/update_currency.js
tx_cart_update_payment_shipping = EXT:cart/Resources/Public/JavaScript/update_payment_shipping.js
}
Note
The name of the directory for the JavaScript files is no longer /Java
(plural) but /Java
(singular).
2. ALTERNATIVE B: Add JavaScript via Asset Viewhelper
The more performant way requires more job some job in your partials and templates. Even templates of extensions like e.g.
EXT:
are affected.
It's necessary to include the [asset viewhelpers](https://docs.typo3.org/other/typo3/view-helper-reference/12.4/en-us/typo3/fluid/latest/Asset/Script.html) as they are included in the updated partials and templates.
The following partials are affected:
Resources/
→ includesPrivate/ Partials/ Cart/ Coupon Form. html EXT:
cart/ Resources/ Public/ Java Script/ prevent_ multi_ submit. js Resources/
→ includesPrivate/ Partials/ Cart/ Currency Form. html EXT:
cart/ Resources/ Public/ Java Script/ update_ currency. js Resources/
→ includesPrivate/ Partials/ Cart/ Order Form. html EXT:
cart/ Resources/ Public/ Java Script/ prevent_ multi_ submit. js Resources/
→ includesPrivate/ Partials/ Cart/ Order Form/ Address/ Shipping. html EXT:
cart/ Resources/ Public/ Java Script/ update_ country. js Resources/
→ includesPrivate/ Partials/ Cart/ Order Form/ Payment Method. html EXT:
cart/ Resources/ Public/ Java Script/ update_ payment_ shipping. js Resources/
→ includesPrivate/ Partials/ Cart/ Order Form/ Shipping Method. html EXT:
cart/ Resources/ Public/ Java Script/ update_ payment_ shipping. js Resources/
→ includesPrivate/ Partials/ Cart/ Product Form. html EXT:
cart/ Resources/ Public/ Java Script/ prevent_ multi_ submit. js
The following templates are affected:
Resources/
→ includesPrivate/ Templates/ Cart/ Show Step2. html EXT:
andcart/ Resources/ Public/ Java Script/ prevent_ multi_ submit. js EXT:
cart/ Resources/ Public/ Java Script/ update_ country. js Resources/
→ includesPrivate/ Templates/ Cart/ Show Step3. html EXT:
cart/ Resources/ Public/ Java Script/ prevent_ multi_ submit. js Resources/
→ includesPrivate/ Templates/ Cart/ Show Step4. html EXT:
cart/ Resources/ Public/ Java Script/ prevent_ multi_ submit. js Resources/
→ includesPrivate/ Templates/ Currency/ Edit. html EXT:
cart/ Resources/ Public/ Java Script/ update_ currency. js
3. Update HTML
3.a) Replace inline JavaScript with hidden div (in another file)
The inline JavaScript in your overrides of Resources/
can be removed,
instead a hidden div
has to be added in your overrides of Resources/
Remove the following script
from your overrides of Resources/
and from Resources/
## Delete the following in Resources/Private/Templates/Cart/Show.html and Resources/Private/Templates/Cart/Cart/ShowStep2.html
<script type="text/javascript"></script>
Add the following div
in your overrides of Resources/
## in Resources/Private/Partials/Cart/OrderForm/Address/Shipping.html
<div hidden data-ajax-update-country-action-url="{f:uri.action(controller: 'Cart\Country', action: 'update', pageType: '2278001') -> f:format.raw()}"></div>
3.b) Move checkbox for shipping address to partial The checkbox in the order form where the customer can choose whether billing and shipping address differ moved into a partial. `Resources/Private/Partials/Cart/OrderForm/Address/Shipping.html
Delete the following from your overrides of Resources/
and Resources/
.
<div class="form-list shipping-same-as-billing-wrapper">
<div class="control">
<label for="shipping-same-as-billing">
<f:form.checkbox property="shippingSameAsBilling"
id="shipping-same-as-billing"
value="1"
title="{f:translate(key:'tx_cart.same_address')}"
additionalAttributes="{f:if(condition:'{cart.shippingSameAsBilling}', then: '{checked: \'checked\'}')}"/>
<span><f:translate key="tx_cart.same_address"/></span>
</label>
</div>
</div>
Add in your override of Resources/
<div class="form-list shipping-same-as-billing-wrapper">
<div class="control">
<label for="shipping-same-as-billing">
<f:form.checkbox property="shippingSameAsBilling"
id="shipping-same-as-billing"
value="1"
title="{f:translate(key:'tx_cart.same_address')}"
additionalAttributes="{f:if(condition:'{cart.shippingSameAsBilling}', then: '{checked: \'checked\'}')}"/>
<span><f:translate key="tx_cart.same_address"/></span>
</label>
</div>
</div>
4. Adapt JS in templates of other extensions (only needed when you chose step 2 ALTERNATIVE B) above)
When using EXT:
you need also to adapt /Resources/
:
You need to insert the following viewHelper:
<f:asset.script identifier="add-to-cart" src="EXT:cart/Resources/Public/JavaScript/add_to_cart.js" />
<f:asset.script identifier="change-be-variant" src="EXT:cart/Resources/Public/JavaScript/change_be_variant.js" />
Other extension which use a similar Cart
needs the same adaption.