- First commit to issue fork.
- Merge request !4Issue #3298965: Make link an optional ajax call not a redirect via configuration β (Open) created by jannakha
- Status changed to Needs review
9 days ago 5:39am 19 June 2024 - π¦πΊAustralia jannakha Brisbane!
Check out MR!4
- just add 'use-ajax' class to the link and 'Add to cart' becomes AJAX link (see readme.md in MR)Optional:
add an event handler in your JS:$('html').on('addToCartLink.updated', (event) => { // process updated cart event, eg show a message "Item has been added to your cart!" });
- Status changed to Needs work
9 days ago 7:41am 19 June 2024 - π¦πΉAustria agoradesign
First of all, thank you very much for your MR, Jen :)
It looks 99% good to me, especially the custom event part. One thing I'm not happy with, is the hardcoded and very opinionated CSS selector used for the counter update. eg, this would apply to none of our Commerce sites at all. Would you mind making this selector configurable + empty check for this?
- π¦πΊAustralia jannakha Brisbane!
@agoradesign yeah, need to think about it
I used default Commerce template's classes.I'll try to see if I can pass all parameters (name of product, total count, etc) to the custom event - so all alterations can be done in own JS to keep config super slim.
- Status changed to Needs review
7 days ago 4:44am 21 June 2024 - π¦πΊAustralia jannakha Brisbane!
updated custom JS event to return data:
$('html').on('addToCartLink.updated', (event, data) => { // Cart has been updated, following data is available: // data.cart_total_count // data.product_title // data.quantity_added console.log(data); });
By default commerce_cart template will be updated:
... <span class="cart-block--summary__count">{{ count_text }}</span> ...
If template has been overwritten and classes don't exit - it will not cause an error.