Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core js refacto #282

Merged
merged 24 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
cart actions
  • Loading branch information
Oksydan committed Sep 26, 2023
commit b0e378b5b3724be773184ddf2ade526b8e56f763
9 changes: 8 additions & 1 deletion _dev/js/theme/core/cart/cartController.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import deleteVoucherHandler from './handler/voucher/deleteVoucherHandler';
import addToCartHandler from './handler/cart/addToCartHandler';
import deleteFromCartHandler from './handler/cart/deleteFromCartHandler';
import quantityChangeHandler from './handler/cart/quantityChangeHandler';
import updateCartHandler from './handler/cart/updateCartHandler';
import updatedCartHandler from './handler/cart/updatedCartHandler';
import useCustomQuantityInput from '../../components/useCustomQuantityInput';

const { on } = useEvent();
Expand Down Expand Up @@ -45,8 +47,13 @@ const cartController = () => {

attachSpinnerEvents();

prestashop.on('updatedCart', () => {
prestashop.on('updatedCart', (event) => {
attachSpinnerEvents();
updatedCartHandler(event);
});

prestashop.on('updateCart', (event) => {
updateCartHandler(event);
});
};

Expand Down
51 changes: 0 additions & 51 deletions _dev/js/theme/core/cart/cartQuantity.js

This file was deleted.

Empty file.
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
import useAlertToast from '@js/theme/components/useAlertToast';
import parseToHtml from '@js/theme/utils/parseToHtml';
import prestashop from 'prestashop';
import parseToHtml from '../../../../utils/parseToHtml';
import useAlertToast from '../../../../components/useAlertToast';

const { danger } = useAlertToast();

const handleUpdatedEvent = () => {
document.querySelector('body').classList.remove('cart-loading');
};

const handleUpdateEvent = async (event) => {
const updateCartHandler = async (event) => {
prestashop.cart = event.resp.cart;

const quickViewModal = document.querySelector(prestashop.selectors.cart.quickview);

// TO DO REMOVE JQUERY
$(quickViewModal).modal('hide');
document.querySelector('body').classList.add('cart-loading');

try {
Expand Down Expand Up @@ -45,9 +36,4 @@ const handleUpdateEvent = async (event) => {
}
};

const updateCart = () => {
prestashop.on('updateCart', handleUpdateEvent);
prestashop.on('updatedCart', handleUpdatedEvent);
};

export default updateCart;
export default updateCartHandler;
5 changes: 5 additions & 0 deletions _dev/js/theme/core/cart/handler/cart/updatedCartHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const updatedCartHandler = () => {
document.querySelector('body').classList.remove('cart-loading');
};

export default updatedCartHandler;
4 changes: 0 additions & 4 deletions _dev/js/theme/core/cart/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import updateCart from '@js/theme/core/cart/updateCart';
import cartQuantity from '@js/theme/core/cart/cartQuantity';
import DOMReady from '@js/theme/utils/DOMReady';
import prestashop from 'prestashop';
import cartController from './cartController';
Expand All @@ -9,7 +7,5 @@ prestashop.cart = prestashop.cart || {};
const { init } = cartController();

DOMReady(() => {
updateCart();
cartQuantity();
init();
});