first commit
This commit is contained in:
1677
modules/ps_shoppingcart/composer.lock
generated
Normal file
1677
modules/ps_shoppingcart/composer.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
12
modules/ps_shoppingcart/config.xml
Normal file
12
modules/ps_shoppingcart/config.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<module>
|
||||
<name>ps_shoppingcart</name>
|
||||
<displayName><![CDATA[Shopping cart]]></displayName>
|
||||
<version><![CDATA[2.0.5]]></version>
|
||||
<description><![CDATA[Adds a block containing the customer's shopping cart.]]></description>
|
||||
<author><![CDATA[PrestaShop]]></author>
|
||||
<tab><![CDATA[front_office_features]]></tab>
|
||||
<is_configurable>1</is_configurable>
|
||||
<need_instance>0</need_instance>
|
||||
<limited_countries></limited_countries>
|
||||
</module>
|
||||
12
modules/ps_shoppingcart/config_pl.xml
Normal file
12
modules/ps_shoppingcart/config_pl.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<module>
|
||||
<name>ps_shoppingcart</name>
|
||||
<displayName><![CDATA[Koszyk]]></displayName>
|
||||
<version><![CDATA[2.0.5]]></version>
|
||||
<description><![CDATA[Display a shopping cart icon on your pages and the number of items it contains.]]></description>
|
||||
<author><![CDATA[PrestaShop]]></author>
|
||||
<tab><![CDATA[front_office_features]]></tab>
|
||||
<is_configurable>1</is_configurable>
|
||||
<need_instance>0</need_instance>
|
||||
<limited_countries></limited_countries>
|
||||
</module>
|
||||
54
modules/ps_shoppingcart/controllers/front/ajax.php
Normal file
54
modules/ps_shoppingcart/controllers/front/ajax.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?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
|
||||
*/
|
||||
class Ps_ShoppingcartAjaxModuleFrontController extends ModuleFrontController
|
||||
{
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $ssl = true;
|
||||
|
||||
/**
|
||||
* @see FrontController::initContent()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function initContent()
|
||||
{
|
||||
parent::initContent();
|
||||
|
||||
$modal = null;
|
||||
|
||||
if ($this->module instanceof Ps_Shoppingcart && Tools::getValue('action') === 'add-to-cart') {
|
||||
$modal = $this->module->renderModal(
|
||||
$this->context->cart,
|
||||
(int) Tools::getValue('id_product'),
|
||||
(int) Tools::getValue('id_product_attribute'),
|
||||
(int) Tools::getValue('id_customization')
|
||||
);
|
||||
}
|
||||
|
||||
ob_end_clean();
|
||||
header('Content-Type: application/json');
|
||||
exit(json_encode([
|
||||
'preview' => $this->module instanceof Ps_Shoppingcart ? $this->module->renderWidget(null, ['cart' => $this->context->cart]) : '',
|
||||
'modal' => $modal,
|
||||
]));
|
||||
}
|
||||
}
|
||||
34
modules/ps_shoppingcart/controllers/front/index.php
Normal file
34
modules/ps_shoppingcart/controllers/front/index.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* 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.md.
|
||||
* 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.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to https://devdocs.prestashop.com/ for more information.
|
||||
*
|
||||
* @author PrestaShop SA and Contributors <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
*/
|
||||
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;
|
||||
34
modules/ps_shoppingcart/controllers/index.php
Normal file
34
modules/ps_shoppingcart/controllers/index.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* 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.md.
|
||||
* 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.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to https://devdocs.prestashop.com/ for more information.
|
||||
*
|
||||
* @author PrestaShop SA and Contributors <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
*/
|
||||
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;
|
||||
BIN
modules/ps_shoppingcart/img/icon/basket.png
Normal file
BIN
modules/ps_shoppingcart/img/icon/basket.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 567 B |
BIN
modules/ps_shoppingcart/img/icon/basket_go.png
Normal file
BIN
modules/ps_shoppingcart/img/icon/basket_go.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 669 B |
BIN
modules/ps_shoppingcart/img/icon/checkout.png
Normal file
BIN
modules/ps_shoppingcart/img/icon/checkout.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 669 B |
BIN
modules/ps_shoppingcart/img/icon/delete.gif
Normal file
BIN
modules/ps_shoppingcart/img/icon/delete.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 213 B |
28
modules/ps_shoppingcart/img/icon/index.php
Normal file
28
modules/ps_shoppingcart/img/icon/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;
|
||||
BIN
modules/ps_shoppingcart/img/icon/pict_add_cart.png
Normal file
BIN
modules/ps_shoppingcart/img/icon/pict_add_cart.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 633 B |
28
modules/ps_shoppingcart/img/index.php
Normal file
28
modules/ps_shoppingcart/img/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
modules/ps_shoppingcart/index.php
Normal file
28
modules/ps_shoppingcart/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;
|
||||
BIN
modules/ps_shoppingcart/logo.png
Normal file
BIN
modules/ps_shoppingcart/logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.4 KiB |
28
modules/ps_shoppingcart/modal.tpl
Normal file
28
modules/ps_shoppingcart/modal.tpl
Normal file
@@ -0,0 +1,28 @@
|
||||
{**
|
||||
* 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
|
||||
*}
|
||||
<div id="blockcart-modal" data-close-on-click="true">
|
||||
<div>
|
||||
<section>
|
||||
<h1>{l s='Product Successfully Added to Your Shopping Cart' d='Shop.Theme.Checkout'}</h1>
|
||||
{$product.name}
|
||||
{hook h='displayCartModalContent' product=$product}
|
||||
</section>
|
||||
{hook h='displayCartModalFooter' product=$product}
|
||||
</div>
|
||||
</div>
|
||||
10
modules/ps_shoppingcart/phpstan.neon.dist
Normal file
10
modules/ps_shoppingcart/phpstan.neon.dist
Normal file
@@ -0,0 +1,10 @@
|
||||
parameters:
|
||||
level: 8
|
||||
bootstrapFiles:
|
||||
- .github/workflows/phpstan/autoload.php
|
||||
paths:
|
||||
- controllers
|
||||
- ps_shoppingcart.php
|
||||
ignoreErrors:
|
||||
- '#^Call to an undefined method AdminController|FrontController\:\:#'
|
||||
- '#^Call to an undefined method Module\:\:#'
|
||||
52
modules/ps_shoppingcart/ps_shoppingcart-product-line.tpl
Normal file
52
modules/ps_shoppingcart/ps_shoppingcart-product-line.tpl
Normal file
@@ -0,0 +1,52 @@
|
||||
{**
|
||||
* 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
|
||||
*}
|
||||
<span class="product-quantity">{$product.quantity}</span>
|
||||
<span class="product-name">{$product.name}</span>
|
||||
<span class="product-price">{$product.price}</span>
|
||||
<a class="remove-from-cart"
|
||||
rel="nofollow"
|
||||
href="{$product.remove_from_cart_url}"
|
||||
data-link-action="remove-from-cart"
|
||||
>
|
||||
{l s="Remove" d="Shop.Theme.Actions"}
|
||||
</a>
|
||||
{if $product.customizations|count}
|
||||
<div class="customizations">
|
||||
<ul>
|
||||
{foreach from=$product.customizations item="customization"}
|
||||
<li>
|
||||
<span class="product-quantity">{$customization.quantity}</span>
|
||||
<a href="{$customization.remove_from_cart_url}" class="remove-from-cart" rel="nofollow">{l s='Remove' d="Shop.Theme.Actions"}</a>
|
||||
<ul>
|
||||
{foreach from=$customization.fields item="field"}
|
||||
<li>
|
||||
<label>{$field.label}</label>
|
||||
{if $field.type == 'text'}
|
||||
<span>{$field.text}</span>
|
||||
{elseif $field.type == 'image'}
|
||||
<img src="{$field.image.small.url}">
|
||||
{/if}
|
||||
</li>
|
||||
{/foreach}
|
||||
</ul>
|
||||
</li>
|
||||
{/foreach}
|
||||
</ul>
|
||||
</div>
|
||||
{/if}
|
||||
76
modules/ps_shoppingcart/ps_shoppingcart.js
Normal file
76
modules/ps_shoppingcart/ps_shoppingcart.js
Normal file
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
||||
/**
|
||||
* This module exposes an extension point through `showModal` function.
|
||||
*
|
||||
* If you want to customize the way the modal window is displayed, you need to do:
|
||||
*
|
||||
* prestashop.blockcart = prestashop.blockcart || {};
|
||||
* prestashop.blockcart.showModal = function myOwnShowModal (modalHTML) {
|
||||
* // your own code
|
||||
* // please not that it is your responsibility to handle the modal "close" behavior
|
||||
* };
|
||||
*
|
||||
* Warning: your custom JavaScript needs to be included **before** this file.
|
||||
* The safest way to do so is to place your "override" inside the theme main JavaScript file.
|
||||
*
|
||||
*/
|
||||
|
||||
$(document).ready(function () {
|
||||
prestashop.blockcart = prestashop.blockcart || {};
|
||||
|
||||
var showModal = prestashop.blockcart.showModal || function (modal) {
|
||||
var $body = $('body');
|
||||
$body.append(modal);
|
||||
$body.one('click', '#blockcart-modal', function (event) {
|
||||
if (event.target.id === 'blockcart-modal') {
|
||||
$(event.target).remove();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
prestashop.on(
|
||||
'updateCart',
|
||||
function (event) {
|
||||
var refreshURL = $('.blockcart').data('refresh-url');
|
||||
var 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
|
||||
};
|
||||
}
|
||||
if (event && event.resp && event.resp.hasError) {
|
||||
prestashop.emit('showErrorNextToAddtoCartButton', { errorMessage: event.resp.errors.join('<br/>')});
|
||||
}
|
||||
$.post(refreshURL, requestData).then(function (resp) {
|
||||
var html = $('<div />').append($.parseHTML(resp.preview));
|
||||
$('.blockcart').replaceWith($(resp.preview).find('.blockcart'));
|
||||
if (resp.modal) {
|
||||
showModal(resp.modal);
|
||||
}
|
||||
}).fail(function (resp) {
|
||||
prestashop.emit('handleError', { eventType: 'updateShoppingCart', resp: resp });
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
276
modules/ps_shoppingcart/ps_shoppingcart.php
Normal file
276
modules/ps_shoppingcart/ps_shoppingcart.php
Normal file
@@ -0,0 +1,276 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
use PrestaShop\PrestaShop\Adapter\Cart\CartPresenter;
|
||||
|
||||
if (!defined('_PS_VERSION_')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
use PrestaShop\PrestaShop\Core\Module\WidgetInterface;
|
||||
|
||||
class Ps_Shoppingcart extends Module implements WidgetInterface
|
||||
{
|
||||
/**
|
||||
* @var string Name of the module running on PS 1.6.x. Used for data migration.
|
||||
*/
|
||||
const PS_16_EQUIVALENT_MODULE = 'blockcart';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->name = 'ps_shoppingcart';
|
||||
$this->tab = 'front_office_features';
|
||||
$this->version = '2.0.5';
|
||||
$this->author = 'PrestaShop';
|
||||
$this->need_instance = 0;
|
||||
|
||||
$this->bootstrap = true;
|
||||
parent::__construct();
|
||||
|
||||
$this->displayName = $this->trans('Shopping cart', [], 'Modules.Shoppingcart.Admin');
|
||||
$this->description = $this->trans('Display a shopping cart icon on your pages and the number of items it contains.', [], 'Modules.Shoppingcart.Admin');
|
||||
$this->ps_versions_compliancy = ['min' => '1.7.1.0', 'max' => _PS_VERSION_];
|
||||
$this->controllers = ['ajax'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function hookDisplayHeader()
|
||||
{
|
||||
if (Configuration::isCatalogMode()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Configuration::get('PS_BLOCK_CART_AJAX')) {
|
||||
$this->context->controller->registerJavascript('modules-shoppingcart', 'modules/' . $this->name . '/ps_shoppingcart.js', ['position' => 'bottom', 'priority' => 150]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function getCartSummaryURL()
|
||||
{
|
||||
return $this->context->link->getPageLink(
|
||||
'cart',
|
||||
null,
|
||||
$this->context->language->id,
|
||||
[
|
||||
'action' => 'show',
|
||||
],
|
||||
false,
|
||||
null,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $hookName
|
||||
* @param array<string,mixed> $params
|
||||
*
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
public function getWidgetVariables($hookName, array $params)
|
||||
{
|
||||
$cart_url = $this->getCartSummaryURL();
|
||||
|
||||
return [
|
||||
'cart' => (new CartPresenter())->present(isset($params['cart']) ? $params['cart'] : $this->context->cart),
|
||||
'refresh_url' => $this->context->link->getModuleLink('ps_shoppingcart', 'ajax', [], null, null, null, true),
|
||||
'cart_url' => $cart_url,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $hookName
|
||||
* @param array<string,mixed> $params
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function renderWidget($hookName, array $params)
|
||||
{
|
||||
if (Configuration::isCatalogMode()) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$this->smarty->assign($this->getWidgetVariables($hookName, $params));
|
||||
|
||||
return $this->fetch('module:ps_shoppingcart/ps_shoppingcart.tpl');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Cart $cart
|
||||
* @param int $id_product
|
||||
* @param int $id_product_attribute
|
||||
* @param int $id_customization
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function renderModal(Cart $cart, $id_product, $id_product_attribute, $id_customization)
|
||||
{
|
||||
$data = (new CartPresenter())->present($cart);
|
||||
$product = null;
|
||||
foreach ($data['products'] as $p) {
|
||||
if ((int) $p['id_product'] == $id_product &&
|
||||
(int) $p['id_product_attribute'] == $id_product_attribute &&
|
||||
(int) $p['id_customization'] == $id_customization) {
|
||||
$product = $p;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->smarty->assign([
|
||||
'product' => $product,
|
||||
'cart' => $data,
|
||||
'cart_url' => $this->getCartSummaryURL(),
|
||||
]);
|
||||
|
||||
return $this->fetch('module:ps_shoppingcart/modal.tpl');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getContent()
|
||||
{
|
||||
$output = '';
|
||||
if (Tools::isSubmit('submitBlockCart')) {
|
||||
$ajax = Tools::getValue('PS_BLOCK_CART_AJAX');
|
||||
if ($ajax != 0 && $ajax != 1) {
|
||||
$output .= $this->displayError($this->trans('Ajax: Invalid choice.', [], 'Modules.Shoppingcart.Admin'));
|
||||
} else {
|
||||
Configuration::updateValue('PS_BLOCK_CART_AJAX', (int) ($ajax));
|
||||
Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules') . '&configure=' . $this->name . '&conf=6');
|
||||
}
|
||||
}
|
||||
|
||||
return $output . $this->renderForm();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function install()
|
||||
{
|
||||
$this->uninstallPrestaShop16Module();
|
||||
|
||||
return
|
||||
parent::install()
|
||||
&& $this->registerHook('displayHeader')
|
||||
&& $this->registerHook('displayNav2')
|
||||
&& Configuration::updateValue('PS_BLOCK_CART_AJAX', 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Migrate data from 1.6 equivalent module (if applicable), then uninstall
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function uninstallPrestaShop16Module()
|
||||
{
|
||||
if (!Module::isInstalled(self::PS_16_EQUIVALENT_MODULE)) {
|
||||
return false;
|
||||
}
|
||||
$oldModule = Module::getInstanceByName(self::PS_16_EQUIVALENT_MODULE);
|
||||
if ($oldModule) {
|
||||
// This closure calls the parent class to prevent data to be erased
|
||||
// It allows the new module to be configured without migration
|
||||
$parentUninstallClosure = function () {
|
||||
return parent::uninstall();
|
||||
};
|
||||
$parentUninstallClosure = $parentUninstallClosure->bindTo($oldModule, get_class($oldModule));
|
||||
$parentUninstallClosure();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function renderForm()
|
||||
{
|
||||
$fields_form = [
|
||||
'form' => [
|
||||
'legend' => [
|
||||
'title' => $this->trans('Settings', [], 'Admin.Global'),
|
||||
'icon' => 'icon-cogs',
|
||||
],
|
||||
'input' => [
|
||||
[
|
||||
'type' => 'switch',
|
||||
'label' => $this->trans('Ajax cart', [], 'Modules.Shoppingcart.Admin'),
|
||||
'name' => 'PS_BLOCK_CART_AJAX',
|
||||
'is_bool' => true,
|
||||
'desc' => $this->trans('Activate Ajax mode for the cart (compatible with the default theme).', [], 'Modules.Shoppingcart.Admin'),
|
||||
'values' => [
|
||||
[
|
||||
'id' => 'active_on',
|
||||
'value' => 1,
|
||||
'label' => $this->trans('Yes', [], 'Admin.Global'),
|
||||
],
|
||||
[
|
||||
'id' => 'active_off',
|
||||
'value' => 0,
|
||||
'label' => $this->trans('No', [], 'Admin.Global'),
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'submit' => [
|
||||
'title' => $this->trans('Save', [], 'Admin.Actions'),
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$helper = new HelperForm();
|
||||
$helper->show_toolbar = false;
|
||||
$helper->table = $this->table;
|
||||
$lang = new Language((int) Configuration::get('PS_LANG_DEFAULT'));
|
||||
$helper->default_form_language = $lang->id;
|
||||
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
|
||||
|
||||
$helper->identifier = $this->identifier;
|
||||
$helper->submit_action = 'submitBlockCart';
|
||||
$helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false) . '&configure=' . $this->name . '&tab_module=' . $this->tab
|
||||
. '&module_name=' . $this->name;
|
||||
$helper->token = Tools::getAdminTokenLite('AdminModules');
|
||||
$helper->tpl_vars = [
|
||||
'fields_value' => $this->getConfigFieldsValues(),
|
||||
'languages' => $this->context->controller->getLanguages(),
|
||||
'id_language' => $this->context->language->id,
|
||||
];
|
||||
|
||||
return $helper->generateForm([$fields_form]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool[]
|
||||
*/
|
||||
public function getConfigFieldsValues()
|
||||
{
|
||||
return [
|
||||
'PS_BLOCK_CART_AJAX' => (bool) Tools::getValue('PS_BLOCK_CART_AJAX', Configuration::get('PS_BLOCK_CART_AJAX')),
|
||||
];
|
||||
}
|
||||
}
|
||||
47
modules/ps_shoppingcart/ps_shoppingcart.tpl
Normal file
47
modules/ps_shoppingcart/ps_shoppingcart.tpl
Normal file
@@ -0,0 +1,47 @@
|
||||
{**
|
||||
* 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
|
||||
*}
|
||||
<div id="blockcart-wrapper">
|
||||
<div class="blockcart cart-preview" data-refresh-url="{$refresh_url}">
|
||||
<div class="header">
|
||||
<a rel="nofollow" href="{$cart_url}">
|
||||
<span>{l s='Cart' d='Shop.Theme.Actions'}</span>
|
||||
<span>{$cart.summary_string}</span>
|
||||
</a>
|
||||
</div>
|
||||
<div class="body">
|
||||
<ul>
|
||||
{foreach from=$cart.products item=product}
|
||||
<li>{include 'module:ps_shoppingcart/ps_shoppingcart-product-line.tpl' product=$product}</li>
|
||||
{/foreach}
|
||||
</ul>
|
||||
<div class="cart-subtotals">
|
||||
{foreach from=$cart.subtotals item="subtotal"}
|
||||
<div class="{$subtotal.type}">
|
||||
<span class="label">{$subtotal.label}</span>
|
||||
<span class="value">{$subtotal.amount}</span>
|
||||
</div>
|
||||
{/foreach}
|
||||
</div>
|
||||
<div class="cart-total">
|
||||
<span class="label">{$cart.totals.total.label}</span>
|
||||
<span class="value">{$cart.totals.total.amount}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
28
modules/ps_shoppingcart/translations/index.php
Normal file
28
modules/ps_shoppingcart/translations/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;
|
||||
0
modules/ps_shoppingcart/translations/pl.php
Normal file
0
modules/ps_shoppingcart/translations/pl.php
Normal file
41
modules/ps_shoppingcart/upgrade/upgrade-2.0.5.php
Normal file
41
modules/ps_shoppingcart/upgrade/upgrade-2.0.5.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2018 PrestaShop.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (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:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* 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.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2016 PrestaShop SA
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param Module $module
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function upgrade_module_2_0_5($module)
|
||||
{
|
||||
// Unregister header old hook
|
||||
$module->unregisterHook('header');
|
||||
|
||||
// Register the new header hook
|
||||
$module->registerHook('displayHeader');
|
||||
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user