Initial commit: is_shoppingcart out of the box. V3.0.1
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||
header('Pragma: no-cache');
|
||||
|
||||
header('Location: ../');
|
||||
exit;
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||
header('Pragma: no-cache');
|
||||
|
||||
header('Location: ../');
|
||||
exit;
|
||||
@@ -0,0 +1,100 @@
|
||||
function initShoppingCart() {
|
||||
const body = document.querySelector('body');
|
||||
|
||||
function bindEvents() {
|
||||
const blockCart = document.querySelector('.js-blockcart');
|
||||
|
||||
// blockCart.addEventListener('show.bs.dropdown', () => { Change to vanilla js when bootstrap 5 is adopted
|
||||
$(blockCart).on('show.bs.dropdown', () => {
|
||||
body.classList.add('header-dropdown-open', 'block-cart-open');
|
||||
});
|
||||
|
||||
// blockCart.addEventListener('hide.bs.dropdown', (e) => { Change to vanilla js when bootstrap 5 is adopted
|
||||
$(blockCart).on('hide.bs.dropdown', (e) => {
|
||||
const { target } = e;
|
||||
if (!target.classList.contains('dropdown-close')
|
||||
&& (target.classList.contains('keep-open') || target.closest('.keep-open')
|
||||
|| (e.clickEvent && e.clickEvent.target.closest('.keep-open')))) {
|
||||
return false; // returning false should stop the dropdown from hiding.
|
||||
}
|
||||
body.classList.remove('header-dropdown-open', 'block-cart-open');
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
prestashop.blockcart = prestashop.blockcart || {};
|
||||
|
||||
const { showModal } = prestashop.blockcart;
|
||||
|
||||
bindEvents();
|
||||
|
||||
prestashop.on(
|
||||
'updateCart',
|
||||
(event) => {
|
||||
const refreshURL = document.querySelector('.js-blockcart').dataset.refreshUrl;
|
||||
let requestData = {};
|
||||
|
||||
if (event && event.reason && typeof event.resp !== 'undefined' && !event.resp.hasError) {
|
||||
requestData = {
|
||||
id_customization: event.reason.idCustomization,
|
||||
id_product_attribute: event.reason.idProductAttribute,
|
||||
id_product: event.reason.idProduct,
|
||||
action: event.reason.linkAction,
|
||||
ajax: 1,
|
||||
};
|
||||
}
|
||||
|
||||
requestData = Object.keys(requestData).map((key) => `${encodeURIComponent(key)}=${encodeURIComponent(requestData[key])}`).join('&');
|
||||
|
||||
if (event && event.resp && event.resp.hasError) {
|
||||
const errorModal = document.querySelector('#blockcart-error');
|
||||
const alertBlock = document.querySelector('.js-blockcart-alert');
|
||||
|
||||
alertBlock.innerHTML = event.resp.errors.join('<br/>');
|
||||
// errorModal.modal('show'); Change to vanilla js when bootstrap 5 is adopted
|
||||
$(errorModal).modal('show');
|
||||
}
|
||||
|
||||
fetch(refreshURL, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
body: requestData,
|
||||
})
|
||||
.then((resp) => resp.json())
|
||||
.then((resp) => {
|
||||
const previewHtml = new DOMParser().parseFromString(resp.preview, 'text/html').querySelector('.js-blockcart');
|
||||
|
||||
if (previewHtml) {
|
||||
document.querySelector('.js-blockcart').replaceWith(previewHtml);
|
||||
}
|
||||
|
||||
if (resp.modal) {
|
||||
showModal(resp.modal);
|
||||
}
|
||||
|
||||
prestashop.emit('updatedBlockCart', resp);
|
||||
|
||||
if (body.classList.contains('block-cart-open')) {
|
||||
const dropdown = body.querySelector('.js-blockcart [data-toggle="dropdown"]');
|
||||
|
||||
if (dropdown) {
|
||||
dropdown.click();
|
||||
}
|
||||
}
|
||||
|
||||
bindEvents();
|
||||
|
||||
body.classList.remove('cart-loading');
|
||||
})
|
||||
.catch((resp) => {
|
||||
prestashop.emit('handleError', { eventType: 'updateShoppingCart', resp });
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
initShoppingCart();
|
||||
});
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||
header('Pragma: no-cache');
|
||||
|
||||
header('Location: ../');
|
||||
exit;
|
||||
Reference in New Issue
Block a user