Skip to content

Commit

Permalink
cart actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Oksydan committed Sep 26, 2023
1 parent dda40eb commit b0e378b
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 74 deletions.
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();
});

0 comments on commit b0e378b

Please sign in to comment.