Initial commit: is_shoppingcart out of the box. V3.0.1
This commit is contained in:
4
is_shoppingcart/_theme_dev/.eslintignore
Normal file
4
is_shoppingcart/_theme_dev/.eslintignore
Normal file
@ -0,0 +1,4 @@
|
||||
/node_modules/
|
||||
/webpack/
|
||||
postcss.config.js
|
||||
webpack.config.js
|
||||
27
is_shoppingcart/_theme_dev/.eslintrc.js
Normal file
27
is_shoppingcart/_theme_dev/.eslintrc.js
Normal file
@ -0,0 +1,27 @@
|
||||
module.exports = {
|
||||
root: true,
|
||||
env: {
|
||||
browser: true,
|
||||
node: false,
|
||||
es6: true,
|
||||
jquery: true,
|
||||
},
|
||||
globals: {
|
||||
google: true,
|
||||
document: true,
|
||||
navigator: false,
|
||||
window: true,
|
||||
prestashop: true,
|
||||
},
|
||||
extends: ['airbnb-base'],
|
||||
rules: {
|
||||
'max-len': ['error', {code: 140}],
|
||||
'no-underscore-dangle': 'off',
|
||||
'no-restricted-syntax': 'off',
|
||||
'no-param-reassign': 'off',
|
||||
'import/no-unresolved': 'off',
|
||||
},
|
||||
parserOptions: {
|
||||
ecmaVersion: 2022
|
||||
},
|
||||
}
|
||||
1
is_shoppingcart/_theme_dev/.nvmrc
Normal file
1
is_shoppingcart/_theme_dev/.nvmrc
Normal file
@ -0,0 +1 @@
|
||||
v18.12.1
|
||||
6
is_shoppingcart/_theme_dev/.stylelintrc.json
Normal file
6
is_shoppingcart/_theme_dev/.stylelintrc.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"extends": "stylelint-config-recommended-scss",
|
||||
"rules": {
|
||||
"scss/at-extend-no-missing-placeholder": null
|
||||
}
|
||||
}
|
||||
11
is_shoppingcart/_theme_dev/index.php
Normal file
11
is_shoppingcart/_theme_dev/index.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
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;
|
||||
22
is_shoppingcart/_theme_dev/package.json
Normal file
22
is_shoppingcart/_theme_dev/package.json
Normal file
@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "is_shoppingcart",
|
||||
"description": "Shopping cart prestashop module",
|
||||
"type": "prestashop-module",
|
||||
"version": "3.0.0",
|
||||
"author": "Igor Stępień",
|
||||
"license": "GPL-3.0",
|
||||
"scripts": {
|
||||
"scss-lint": "stylelint \"**/*.scss\" --fix",
|
||||
"scss-lint-fix": "stylelint \"**/*.scss\" --fix",
|
||||
"js-lint": "eslint -c .eslintrc.js --ext .js,.vue ./src",
|
||||
"js-lint-fix": "eslint -c .eslintrc.js --ext .js,.vue ./src --fix"
|
||||
},
|
||||
"devDependencies": {
|
||||
"stylelint": "^14.11.0",
|
||||
"stylelint-config-recommended-scss": "^7.0.0",
|
||||
"eslint": "^8.23.0",
|
||||
"eslint-config-airbnb-base": "^15.0.0",
|
||||
"eslint-plugin-import": "^2.26.0",
|
||||
"postcss": "^8.3.6"
|
||||
}
|
||||
}
|
||||
28
is_shoppingcart/_theme_dev/src/index.php
Normal file
28
is_shoppingcart/_theme_dev/src/index.php
Normal file
@ -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;
|
||||
28
is_shoppingcart/_theme_dev/src/js/index.php
Normal file
28
is_shoppingcart/_theme_dev/src/js/index.php
Normal file
@ -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;
|
||||
100
is_shoppingcart/_theme_dev/src/js/theme/index.js
Normal file
100
is_shoppingcart/_theme_dev/src/js/theme/index.js
Normal file
@ -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();
|
||||
});
|
||||
28
is_shoppingcart/_theme_dev/src/js/theme/index.php
Normal file
28
is_shoppingcart/_theme_dev/src/js/theme/index.php
Normal file
@ -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;
|
||||
2096
is_shoppingcart/_theme_dev/yarn.lock
Normal file
2096
is_shoppingcart/_theme_dev/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user