first commit
This commit is contained in:
165
controllers/front/AddressController.php
Normal file
165
controllers/front/AddressController.php
Normal file
@@ -0,0 +1,165 @@
|
||||
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
class AddressControllerCore extends FrontController
|
||||
{
|
||||
public $auth = true;
|
||||
public $guestAllowed = true;
|
||||
public $php_self = 'address';
|
||||
public $authRedirection = 'addresses';
|
||||
public $ssl = true;
|
||||
|
||||
protected $address_form;
|
||||
protected $should_redirect = false;
|
||||
|
||||
/**
|
||||
* Initialize address controller.
|
||||
*
|
||||
* @see FrontController::init()
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
$this->address_form = $this->makeAddressForm();
|
||||
$this->context->smarty->assign('address_form', $this->address_form->getProxy());
|
||||
}
|
||||
|
||||
/**
|
||||
* Start forms process.
|
||||
*
|
||||
* @see FrontController::postProcess()
|
||||
*/
|
||||
public function postProcess()
|
||||
{
|
||||
$this->context->smarty->assign('editing', false);
|
||||
$id_address = (int) Tools::getValue('id_address');
|
||||
// Initialize address if an id exists
|
||||
if ($id_address) {
|
||||
$this->address_form->loadAddressById($id_address);
|
||||
}
|
||||
|
||||
// Fill the form with data
|
||||
$this->address_form->fillWith(Tools::getAllValues());
|
||||
|
||||
// Submit the address, don't care if it's an edit or add
|
||||
if (Tools::isSubmit('submitAddress')) {
|
||||
if (!$this->address_form->submit()) {
|
||||
$this->errors[] = $this->trans('Please fix the error below.', [], 'Shop.Notifications.Error');
|
||||
} else {
|
||||
if ($id_address) {
|
||||
$this->success[] = $this->trans('Address successfully updated!', [], 'Shop.Notifications.Success');
|
||||
} else {
|
||||
$this->success[] = $this->trans('Address successfully added!', [], 'Shop.Notifications.Success');
|
||||
}
|
||||
|
||||
$this->should_redirect = true;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// There is no id_adress, no need to continue
|
||||
if (!$id_address) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Tools::getValue('delete')) {
|
||||
$ok = $this->makeAddressPersister()->delete(
|
||||
new Address($id_address, $this->context->language->id),
|
||||
Tools::getValue('token')
|
||||
);
|
||||
if ($ok) {
|
||||
$this->success[] = $this->trans('Address successfully deleted!', [], 'Shop.Notifications.Success');
|
||||
$this->should_redirect = true;
|
||||
} else {
|
||||
$this->errors[] = $this->trans('Could not delete address.', [], 'Shop.Notifications.Error');
|
||||
}
|
||||
} else {
|
||||
$this->context->smarty->assign('editing', true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign template vars related to page content.
|
||||
*
|
||||
* @see FrontController::initContent()
|
||||
*/
|
||||
public function initContent()
|
||||
{
|
||||
if (!$this->ajax && $this->should_redirect) {
|
||||
if (($back = Tools::getValue('back')) && Tools::urlBelongsToShop($back)) {
|
||||
$mod = Tools::getValue('mod');
|
||||
$this->redirectWithNotifications('index.php?controller=' . $back . ($mod ? '&back=' . $mod : ''));
|
||||
} else {
|
||||
$this->redirectWithNotifications('index.php?controller=addresses');
|
||||
}
|
||||
}
|
||||
|
||||
parent::initContent();
|
||||
$this->setTemplate(
|
||||
'customer/address',
|
||||
[
|
||||
'entity' => 'address',
|
||||
'id' => (int) Tools::getValue('id_address'),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function getBreadcrumbLinks()
|
||||
{
|
||||
$breadcrumb = parent::getBreadcrumbLinks();
|
||||
|
||||
$breadcrumb['links'][] = $this->addMyAccountToBreadcrumb();
|
||||
|
||||
$breadcrumb['links'][] = [
|
||||
'title' => $this->trans('Addresses', [], 'Shop.Theme.Global'),
|
||||
'url' => $this->context->link->getPageLink('addresses'),
|
||||
];
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
|
||||
public function displayAjaxAddressForm()
|
||||
{
|
||||
$addressForm = $this->makeAddressForm();
|
||||
|
||||
if (Tools::getIsset('id_address') && ($id_address = (int) Tools::getValue('id_address'))) {
|
||||
$addressForm->loadAddressById($id_address);
|
||||
}
|
||||
|
||||
if (Tools::getIsset('id_country')) {
|
||||
$addressForm->fillWith(['id_country' => Tools::getValue('id_country')]);
|
||||
}
|
||||
|
||||
ob_end_clean();
|
||||
header('Content-Type: application/json');
|
||||
$this->ajaxRender(Tools::jsonEncode([
|
||||
'address_form' => $this->render(
|
||||
'customer/_partials/address-form',
|
||||
$addressForm->getTemplateVariables()
|
||||
),
|
||||
]));
|
||||
}
|
||||
}
|
||||
76
controllers/front/AddressesController.php
Normal file
76
controllers/front/AddressesController.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
class AddressesControllerCore extends FrontController
|
||||
{
|
||||
public $auth = true;
|
||||
public $php_self = 'addresses';
|
||||
public $authRedirection = 'addresses';
|
||||
public $ssl = true;
|
||||
|
||||
/**
|
||||
* Initialize addresses controller.
|
||||
*
|
||||
* @see FrontController::init()
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
|
||||
if (!Validate::isLoadedObject($this->context->customer)) {
|
||||
die(Tools::displayError($this->trans('The customer could not be found.', [], 'Shop.Notifications.Error')));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign template vars related to page content.
|
||||
*
|
||||
* @see FrontController::initContent()
|
||||
*/
|
||||
public function initContent()
|
||||
{
|
||||
if (count($this->context->customer->getSimpleAddresses()) <= 0) {
|
||||
$link = '<a href="' . $this->context->link->getPageLink('address', true) . '">' . $this->trans('Add a new address', [], 'Shop.Theme.Actions') . '</a>';
|
||||
$this->warning[] = $this->trans('No addresses are available. %s', [$link], 'Shop.Notifications.Success');
|
||||
}
|
||||
|
||||
parent::initContent();
|
||||
$this->setTemplate('customer/addresses');
|
||||
}
|
||||
|
||||
public function getBreadcrumbLinks()
|
||||
{
|
||||
$breadcrumb = parent::getBreadcrumbLinks();
|
||||
|
||||
$breadcrumb['links'][] = $this->addMyAccountToBreadcrumb();
|
||||
|
||||
$breadcrumb['links'][] = [
|
||||
'title' => $this->trans('Addresses', [], 'Shop.Theme.Global'),
|
||||
'url' => $this->context->link->getPageLink('addresses'),
|
||||
];
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
}
|
||||
81
controllers/front/AttachmentController.php
Normal file
81
controllers/front/AttachmentController.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
class AttachmentControllerCore extends FrontController
|
||||
{
|
||||
public function postProcess()
|
||||
{
|
||||
$a = new Attachment(Tools::getValue('id_attachment'), $this->context->language->id);
|
||||
if (!$a->id) {
|
||||
Tools::redirect('index.php');
|
||||
}
|
||||
|
||||
Hook::exec('actionDownloadAttachment', ['attachment' => &$a]);
|
||||
|
||||
if (ob_get_level() && ob_get_length() > 0) {
|
||||
ob_end_clean();
|
||||
}
|
||||
|
||||
header('Content-Transfer-Encoding: binary');
|
||||
header('Content-Type: ' . $a->mime);
|
||||
header('Content-Length: ' . filesize(_PS_DOWNLOAD_DIR_ . $a->file));
|
||||
header('Content-Disposition: attachment; filename="' . utf8_decode($a->file_name) . '"');
|
||||
@set_time_limit(0);
|
||||
$this->readfileChunked(_PS_DOWNLOAD_DIR_ . $a->file);
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see http://ca2.php.net/manual/en/function.readfile.php#54295
|
||||
*/
|
||||
public function readfileChunked($filename, $retbytes = true)
|
||||
{
|
||||
// how many bytes per chunk
|
||||
$chunksize = 1 * (1024 * 1024);
|
||||
$buffer = '';
|
||||
$totalBytes = 0;
|
||||
|
||||
$handle = fopen($filename, 'rb');
|
||||
if ($handle === false) {
|
||||
return false;
|
||||
}
|
||||
while (!feof($handle)) {
|
||||
$buffer = fread($handle, $chunksize);
|
||||
echo $buffer;
|
||||
ob_flush();
|
||||
flush();
|
||||
if ($retbytes) {
|
||||
$totalBytes += strlen($buffer);
|
||||
}
|
||||
}
|
||||
$status = fclose($handle);
|
||||
if ($retbytes && $status) {
|
||||
// return num. bytes delivered like readfile() does.
|
||||
return $totalBytes;
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
}
|
||||
128
controllers/front/AuthController.php
Normal file
128
controllers/front/AuthController.php
Normal file
@@ -0,0 +1,128 @@
|
||||
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
class AuthControllerCore extends FrontController
|
||||
{
|
||||
public $ssl = true;
|
||||
public $php_self = 'authentication';
|
||||
public $auth = false;
|
||||
|
||||
public function checkAccess()
|
||||
{
|
||||
if ($this->context->customer->isLogged() && !$this->ajax) {
|
||||
$this->redirect_after = ($this->authRedirection) ? urlencode($this->authRedirection) : 'my-account';
|
||||
$this->redirect();
|
||||
}
|
||||
|
||||
return parent::checkAccess();
|
||||
}
|
||||
|
||||
public function initContent()
|
||||
{
|
||||
$should_redirect = false;
|
||||
|
||||
if (Tools::isSubmit('submitCreate') || Tools::isSubmit('create_account')) {
|
||||
$register_form = $this
|
||||
->makeCustomerForm()
|
||||
->setGuestAllowed(false)
|
||||
->fillWith(Tools::getAllValues());
|
||||
|
||||
if (Tools::isSubmit('submitCreate')) {
|
||||
$hookResult = array_reduce(
|
||||
Hook::exec('actionSubmitAccountBefore', [], null, true),
|
||||
function ($carry, $item) {
|
||||
return $carry && $item;
|
||||
},
|
||||
true
|
||||
);
|
||||
if ($hookResult && $register_form->submit()) {
|
||||
$should_redirect = true;
|
||||
}
|
||||
}
|
||||
|
||||
$this->context->smarty->assign([
|
||||
'register_form' => $register_form->getProxy(),
|
||||
'hook_create_account_top' => Hook::exec('displayCustomerAccountFormTop'),
|
||||
]);
|
||||
$this->setTemplate('customer/registration');
|
||||
} else {
|
||||
$login_form = $this->makeLoginForm()->fillWith(
|
||||
Tools::getAllValues()
|
||||
);
|
||||
|
||||
if (Tools::isSubmit('submitLogin')) {
|
||||
if ($login_form->submit()) {
|
||||
$should_redirect = true;
|
||||
}
|
||||
}
|
||||
|
||||
$this->context->smarty->assign([
|
||||
'login_form' => $login_form->getProxy(),
|
||||
]);
|
||||
$this->setTemplate('customer/authentication');
|
||||
}
|
||||
|
||||
parent::initContent();
|
||||
|
||||
if ($should_redirect && !$this->ajax) {
|
||||
$back = urldecode(Tools::getValue('back'));
|
||||
|
||||
if (Tools::urlBelongsToShop($back)) {
|
||||
// Checks to see if "back" is a fully qualified
|
||||
// URL that is on OUR domain, with the right protocol
|
||||
return $this->redirectWithNotifications($back);
|
||||
}
|
||||
|
||||
// Well we're not redirecting to a URL,
|
||||
// so...
|
||||
if ($this->authRedirection) {
|
||||
// We may need to go there if defined
|
||||
return $this->redirectWithNotifications($this->authRedirection);
|
||||
}
|
||||
|
||||
// go home
|
||||
return $this->redirectWithNotifications(__PS_BASE_URI__);
|
||||
}
|
||||
}
|
||||
|
||||
public function getBreadcrumbLinks()
|
||||
{
|
||||
$breadcrumb = parent::getBreadcrumbLinks();
|
||||
|
||||
if (Tools::isSubmit('submitCreate') || Tools::isSubmit('create_account')) {
|
||||
$breadcrumb['links'][] = [
|
||||
'title' => $this->trans('Create an account', [], 'Shop.Theme.Customeraccount'),
|
||||
'url' => $this->context->link->getPageLink('authentication'),
|
||||
];
|
||||
} else {
|
||||
$breadcrumb['links'][] = [
|
||||
'title' => $this->trans('Log in to your account', [], 'Shop.Theme.Customeraccount'),
|
||||
'url' => $this->context->link->getPageLink('authentication'),
|
||||
];
|
||||
}
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
}
|
||||
858
controllers/front/CartController.php
Normal file
858
controllers/front/CartController.php
Normal file
@@ -0,0 +1,858 @@
|
||||
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
use PrestaShop\PrestaShop\Adapter\Presenter\Cart\CartPresenter;
|
||||
|
||||
class CartControllerCore extends FrontController
|
||||
{
|
||||
public $php_self = 'cart';
|
||||
|
||||
protected $id_product;
|
||||
protected $id_product_attribute;
|
||||
protected $id_address_delivery;
|
||||
protected $customization_id;
|
||||
protected $qty;
|
||||
/**
|
||||
* To specify if you are in the preview mode or not.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $preview;
|
||||
public $ssl = true;
|
||||
/**
|
||||
* An array of errors, in case the update action of product is wrong.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $updateOperationError = [];
|
||||
|
||||
/**
|
||||
* This is not a public page, so the canonical redirection is disabled.
|
||||
*
|
||||
* @param string $canonicalURL
|
||||
*/
|
||||
public function canonicalRedirection($canonicalURL = '')
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize cart controller.
|
||||
*
|
||||
* @see FrontController::init()
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
|
||||
// Send noindex to avoid ghost carts by bots
|
||||
header('X-Robots-Tag: noindex, nofollow', true);
|
||||
|
||||
// Get page main parameters
|
||||
$this->id_product = (int) Tools::getValue('id_product', null);
|
||||
$this->id_product_attribute = (int) Tools::getValue('id_product_attribute', Tools::getValue('ipa'));
|
||||
$this->customization_id = (int) Tools::getValue('id_customization');
|
||||
$this->qty = abs(Tools::getValue('qty', 1));
|
||||
$this->id_address_delivery = (int) Tools::getValue('id_address_delivery');
|
||||
$this->preview = ('1' === Tools::getValue('preview'));
|
||||
|
||||
/* Check if the products in the cart are available */
|
||||
if ('show' === Tools::getValue('action')) {
|
||||
$isAvailable = $this->areProductsAvailable();
|
||||
if (Tools::getIsset('checkout')) {
|
||||
return Tools::redirect($this->context->link->getPageLink('order'));
|
||||
}
|
||||
if (true !== $isAvailable) {
|
||||
$this->errors[] = $isAvailable;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see FrontController::initContent()
|
||||
*/
|
||||
public function initContent()
|
||||
{
|
||||
if (Configuration::isCatalogMode() && Tools::getValue('action') === 'show') {
|
||||
Tools::redirect('index.php');
|
||||
}
|
||||
|
||||
/*
|
||||
* Check that minimal quantity conditions are respected for each product in the cart
|
||||
* (this is to be applied only on page load, not for ajax calls)
|
||||
*/
|
||||
if (!Tools::getValue('ajax')) {
|
||||
$this->checkCartProductsMinimalQuantities();
|
||||
}
|
||||
$presenter = new CartPresenter();
|
||||
$presented_cart = $presenter->present($this->context->cart, $shouldSeparateGifts = true);
|
||||
|
||||
$this->context->smarty->assign([
|
||||
'cart' => $presented_cart,
|
||||
'static_token' => Tools::getToken(false),
|
||||
]);
|
||||
|
||||
if (count($presented_cart['products']) > 0) {
|
||||
$this->setTemplate('checkout/cart');
|
||||
} else {
|
||||
$this->context->smarty->assign([
|
||||
'allProductsLink' => $this->context->link->getCategoryLink(Configuration::get('PS_HOME_CATEGORY')),
|
||||
]);
|
||||
$this->setTemplate('checkout/cart-empty');
|
||||
}
|
||||
parent::initContent();
|
||||
}
|
||||
|
||||
public function displayAjaxUpdate()
|
||||
{
|
||||
if (Configuration::isCatalogMode()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$productsInCart = $this->context->cart->getProducts();
|
||||
$updatedProducts = array_filter($productsInCart, [$this, 'productInCartMatchesCriteria']);
|
||||
$updatedProduct = reset($updatedProducts);
|
||||
$productQuantity = $updatedProduct['quantity'];
|
||||
|
||||
if (!$this->errors) {
|
||||
$cartPresenter = new CartPresenter();
|
||||
$presentedCart = $cartPresenter->present($this->context->cart);
|
||||
|
||||
// filter product output
|
||||
$presentedCart['products'] = $this->get('prestashop.core.filter.front_end_object.product_collection')
|
||||
->filter($presentedCart['products']);
|
||||
|
||||
$this->ajaxRender(Tools::jsonEncode([
|
||||
'success' => true,
|
||||
'id_product' => $this->id_product,
|
||||
'id_product_attribute' => $this->id_product_attribute,
|
||||
'id_customization' => $this->customization_id,
|
||||
'quantity' => $productQuantity,
|
||||
'cart' => $presentedCart,
|
||||
'errors' => empty($this->updateOperationError) ? '' : reset($this->updateOperationError),
|
||||
]));
|
||||
|
||||
return;
|
||||
} else {
|
||||
$this->ajaxRender(Tools::jsonEncode([
|
||||
'hasError' => true,
|
||||
'errors' => $this->errors,
|
||||
'quantity' => $productQuantity,
|
||||
]));
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public function displayAjaxRefresh()
|
||||
{
|
||||
if (Configuration::isCatalogMode()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ob_end_clean();
|
||||
header('Content-Type: application/json');
|
||||
$this->ajaxRender(Tools::jsonEncode([
|
||||
'cart_detailed' => $this->render('checkout/_partials/cart-detailed'),
|
||||
'cart_detailed_totals' => $this->render('checkout/_partials/cart-detailed-totals'),
|
||||
'cart_summary_items_subtotal' => $this->render('checkout/_partials/cart-summary-items-subtotal'),
|
||||
'cart_summary_subtotals_container' => $this->render('checkout/_partials/cart-summary-subtotals'),
|
||||
'cart_summary_totals' => $this->render('checkout/_partials/cart-summary-totals'),
|
||||
'cart_detailed_actions' => $this->render('checkout/_partials/cart-detailed-actions'),
|
||||
'cart_voucher' => $this->render('checkout/_partials/cart-voucher'),
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated 1.7.3.1 the product link is now accessible
|
||||
* in #quantity_wanted[data-url-update]
|
||||
*/
|
||||
public function displayAjaxProductRefresh()
|
||||
{
|
||||
if ($this->id_product) {
|
||||
$idProductAttribute = 0;
|
||||
$groups = Tools::getValue('group');
|
||||
|
||||
if (!empty($groups)) {
|
||||
$idProductAttribute = (int) Product::getIdProductAttributeByIdAttributes(
|
||||
$this->id_product,
|
||||
$groups,
|
||||
true
|
||||
);
|
||||
}
|
||||
$url = $this->context->link->getProductLink(
|
||||
$this->id_product,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
$this->context->language->id,
|
||||
null,
|
||||
$idProductAttribute,
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
[
|
||||
'quantity_wanted' => (int) $this->qty,
|
||||
'preview' => $this->preview,
|
||||
]
|
||||
);
|
||||
} else {
|
||||
$url = false;
|
||||
}
|
||||
ob_end_clean();
|
||||
header('Content-Type: application/json');
|
||||
$this->ajaxRender(Tools::jsonEncode([
|
||||
'success' => true,
|
||||
'productUrl' => $url,
|
||||
]));
|
||||
}
|
||||
|
||||
public function postProcess()
|
||||
{
|
||||
$this->updateCart();
|
||||
}
|
||||
|
||||
protected function updateCart()
|
||||
{
|
||||
// Update the cart ONLY if $this->cookies are available, in order to avoid ghost carts created by bots
|
||||
if ($this->context->cookie->exists()
|
||||
&& !$this->errors
|
||||
&& !($this->context->customer->isLogged() && !$this->isTokenValid())
|
||||
) {
|
||||
if (Tools::getIsset('add') || Tools::getIsset('update')) {
|
||||
$this->processChangeProductInCart();
|
||||
} elseif (Tools::getIsset('delete')) {
|
||||
$this->processDeleteProductInCart();
|
||||
} elseif (CartRule::isFeatureActive()) {
|
||||
if (Tools::getIsset('addDiscount')) {
|
||||
if (!($code = trim(Tools::getValue('discount_name')))) {
|
||||
$this->errors[] = $this->trans(
|
||||
'You must enter a voucher code.',
|
||||
[],
|
||||
'Shop.Notifications.Error'
|
||||
);
|
||||
} elseif (!Validate::isCleanHtml($code)) {
|
||||
$this->errors[] = $this->trans(
|
||||
'The voucher code is invalid.',
|
||||
[],
|
||||
'Shop.Notifications.Error'
|
||||
);
|
||||
} else {
|
||||
if (($cartRule = new CartRule(CartRule::getIdByCode($code)))
|
||||
&& Validate::isLoadedObject($cartRule)
|
||||
) {
|
||||
if ($error = $cartRule->checkValidity($this->context, false, true)) {
|
||||
$this->errors[] = $error;
|
||||
} else {
|
||||
$this->context->cart->addCartRule($cartRule->id);
|
||||
}
|
||||
} else {
|
||||
$this->errors[] = $this->trans(
|
||||
'This voucher does not exist.',
|
||||
[],
|
||||
'Shop.Notifications.Error'
|
||||
);
|
||||
}
|
||||
}
|
||||
} elseif (($id_cart_rule = (int) Tools::getValue('deleteDiscount'))
|
||||
&& Validate::isUnsignedId($id_cart_rule)
|
||||
) {
|
||||
$this->context->cart->removeCartRule($id_cart_rule);
|
||||
CartRule::autoAddToCart($this->context);
|
||||
}
|
||||
}
|
||||
} elseif (!$this->isTokenValid() && Tools::getValue('action') !== 'show' && !Tools::getValue('ajax')) {
|
||||
Tools::redirect('index.php');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This process delete a product from the cart.
|
||||
*/
|
||||
protected function processDeleteProductInCart()
|
||||
{
|
||||
$customization_product = Db::getInstance()->executeS(
|
||||
'SELECT * FROM `' . _DB_PREFIX_ . 'customization`'
|
||||
. ' WHERE `id_cart` = ' . (int) $this->context->cart->id
|
||||
. ' AND `id_product` = ' . (int) $this->id_product
|
||||
. ' AND `id_customization` != ' . (int) $this->customization_id
|
||||
. ' AND `in_cart` = 1'
|
||||
. ' AND `quantity` > 0'
|
||||
);
|
||||
|
||||
if (count($customization_product)) {
|
||||
$product = new Product((int) $this->id_product);
|
||||
if ($this->id_product_attribute > 0) {
|
||||
$minimal_quantity = (int) Attribute::getAttributeMinimalQty($this->id_product_attribute);
|
||||
} else {
|
||||
$minimal_quantity = (int) $product->minimal_quantity;
|
||||
}
|
||||
|
||||
$total_quantity = 0;
|
||||
foreach ($customization_product as $custom) {
|
||||
$total_quantity += $custom['quantity'];
|
||||
}
|
||||
|
||||
if ($total_quantity < $minimal_quantity) {
|
||||
$this->errors[] = $this->trans(
|
||||
'You must add %quantity% minimum quantity',
|
||||
['%quantity%' => $minimal_quantity],
|
||||
'Shop.Notifications.Error'
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$data = [
|
||||
'id_cart' => (int) $this->context->cart->id,
|
||||
'id_product' => (int) $this->id_product,
|
||||
'id_product_attribute' => (int) $this->id_product_attribute,
|
||||
'customization_id' => (int) $this->customization_id,
|
||||
'id_address_delivery' => (int) $this->id_address_delivery,
|
||||
];
|
||||
|
||||
Hook::exec('actionObjectProductInCartDeleteBefore', $data, null, true);
|
||||
|
||||
if ($this->context->cart->deleteProduct(
|
||||
$this->id_product,
|
||||
$this->id_product_attribute,
|
||||
$this->customization_id,
|
||||
$this->id_address_delivery
|
||||
)) {
|
||||
Hook::exec('actionObjectProductInCartDeleteAfter', $data);
|
||||
|
||||
if (!Cart::getNbProducts((int) $this->context->cart->id)) {
|
||||
$this->context->cart->setDeliveryOption(null);
|
||||
$this->context->cart->gift = 0;
|
||||
$this->context->cart->gift_message = '';
|
||||
$this->context->cart->update();
|
||||
}
|
||||
|
||||
$isAvailable = $this->areProductsAvailable();
|
||||
if (true !== $isAvailable) {
|
||||
$this->updateOperationError[] = $isAvailable;
|
||||
}
|
||||
}
|
||||
|
||||
CartRule::autoRemoveFromCart();
|
||||
CartRule::autoAddToCart();
|
||||
}
|
||||
|
||||
/**
|
||||
* This process add or update a product in the cart.
|
||||
*/
|
||||
protected function processChangeProductInCart()
|
||||
{
|
||||
$mode = (Tools::getIsset('update') && $this->id_product) ? 'update' : 'add';
|
||||
$ErrorKey = ('update' === $mode) ? 'updateOperationError' : 'errors';
|
||||
|
||||
if (Tools::getIsset('group')) {
|
||||
$this->id_product_attribute = (int) Product::getIdProductAttributeByIdAttributes(
|
||||
$this->id_product,
|
||||
Tools::getValue('group')
|
||||
);
|
||||
}
|
||||
|
||||
if ($this->qty == 0) {
|
||||
$this->{$ErrorKey}[] = $this->trans(
|
||||
'Null quantity.',
|
||||
[],
|
||||
'Shop.Notifications.Error'
|
||||
);
|
||||
} elseif (!$this->id_product) {
|
||||
$this->{$ErrorKey}[] = $this->trans(
|
||||
'Product not found',
|
||||
[],
|
||||
'Shop.Notifications.Error'
|
||||
);
|
||||
}
|
||||
|
||||
if (!$this->context->cart->id) {
|
||||
if (Context::getContext()->cookie->id_guest) {
|
||||
$guest = new Guest(Context::getContext()->cookie->id_guest);
|
||||
$this->context->cart->mobile_theme = $guest->mobile_theme;
|
||||
}
|
||||
$this->context->cart->add();
|
||||
if ($this->context->cart->id) {
|
||||
$this->context->cookie->id_cart = (int) $this->context->cart->id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$cur_cart = $this->context->cart;
|
||||
$id_product = $this->id_product;
|
||||
$fixed_price = $_POST['fixed_price'];
|
||||
|
||||
if (isset($_POST['fixed_price'])){
|
||||
$remove_old_specific_price = Db::getInstance()->executeS(
|
||||
'DELETE FROM `' . _DB_PREFIX_ . 'specific_price`'
|
||||
. ' WHERE (`id_cart` = ' . (int) $cur_cart->id . ' OR `id_cart` = 0)'
|
||||
. ' AND `id_product` = ' . (int) $id_product
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($_POST['fixed_price'])){
|
||||
$specific_price_rule = new SpecificPriceRule();
|
||||
$specific_price_rule->name = 'Indywidualna cena wycinka';
|
||||
$specific_price_rule->id_shop = (int)$this->context->shop->id;
|
||||
$specific_price_rule->id_currency = 0;
|
||||
$specific_price_rule->id_country = 0;
|
||||
$specific_price_rule->id_group = 0;
|
||||
$specific_price_rule->from_quantity = 1;
|
||||
$specific_price_rule->price = $fixed_price;
|
||||
$specific_price_rule->reduction = 0;
|
||||
$specific_price_rule->reduction_tax = 0;
|
||||
$specific_price_rule->reduction_type = 'amount';
|
||||
$specific_price_rule->from = date("Y-m-d H:i:s");
|
||||
$specific_price_rule->to = date("Y-m-d").' 23:59:59';
|
||||
$specific_price_rule->add();
|
||||
$specific_price = new SpecificPrice();
|
||||
$specific_price->id_product = (int)$id_product; // choosen product id
|
||||
$specific_price->id_product_attribute = $id_customization;
|
||||
$specific_price->id_cart = (int)$cur_cart->id;
|
||||
$specific_price->id_shop = (int)$this->context->shop->id;
|
||||
$specific_price->id_currency = 0;
|
||||
$specific_price->id_country = 0;
|
||||
$specific_price->id_group = 0;
|
||||
$specific_price->id_customer = 0;
|
||||
$specific_price->from_quantity = 1;
|
||||
$specific_price->price = $fixed_price;
|
||||
$specific_price->reduction_type = 'amount';
|
||||
$specific_price->reduction_tax = 1;
|
||||
$specific_price->reduction = 0;
|
||||
$specific_price->from = date("Y-m-d").' 00:00:00';
|
||||
$specific_price->to = date("Y-m-d").' 23:59:59'; // or set date x days from now
|
||||
$specific_price->id_specific_price_rule = $specific_price_rule->id;
|
||||
$specific_price->add();
|
||||
}
|
||||
|
||||
$product = new Product($this->id_product, true, $this->context->language->id);
|
||||
if (!$product->id || !$product->active || !$product->checkAccess($this->context->cart->id_customer)) {
|
||||
$this->{$ErrorKey}[] = $this->trans(
|
||||
'This product (%product%) is no longer available.',
|
||||
['%product%' => $product->name],
|
||||
'Shop.Notifications.Error'
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$this->id_product_attribute && $product->hasAttributes()) {
|
||||
$minimum_quantity = ($product->out_of_stock == 2)
|
||||
? !Configuration::get('PS_ORDER_OUT_OF_STOCK')
|
||||
: !$product->out_of_stock;
|
||||
$this->id_product_attribute = Product::getDefaultAttribute($product->id, $minimum_quantity);
|
||||
// @todo do something better than a redirect admin !!
|
||||
if (!$this->id_product_attribute) {
|
||||
Tools::redirectAdmin($this->context->link->getProductLink($product));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
$combination = new Combination((int) $this->id_product_attribute);
|
||||
$attributes = $combination->getAttributesName((int) $this->context->language->id);
|
||||
|
||||
$id_combination = $attributes[0]["id_attribute"];
|
||||
|
||||
$id_lang = $this->context->language->id;
|
||||
|
||||
$attributesGroups = Db::getInstance()->ExecuteS('
|
||||
SELECT ag.`id_attribute_group`, ag.`is_color_group`, agl.`name` AS group_name, agl.`public_name` AS public_group_name,
|
||||
a.`id_attribute`, al.`name` AS attribute_name, a.`color` AS attribute_color, pai.id_image AS combination_image, pa.*
|
||||
FROM `'._DB_PREFIX_.'product_attribute` pa
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac ON pac.`id_product_attribute` = pa.`id_product_attribute`
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_attribute_image` AS pai ON pai.`id_product_attribute` = pa.`id_product_attribute`
|
||||
LEFT JOIN `'._DB_PREFIX_.'attribute` a ON a.`id_attribute` = pac.`id_attribute`
|
||||
LEFT JOIN `'._DB_PREFIX_.'attribute_group` ag ON ag.`id_attribute_group` = a.`id_attribute_group`
|
||||
LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON a.`id_attribute` = al.`id_attribute`
|
||||
LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl ON ag.`id_attribute_group` = agl.`id_attribute_group`
|
||||
WHERE pa.`id_product` = '.$id_product.'
|
||||
AND a.`id_attribute` = '.$id_combination.'
|
||||
ORDER BY agl.`public_name`, al.`name`');
|
||||
|
||||
$combination_image_id = $attributesGroups[0]["combination_image"];
|
||||
|
||||
$result2 = new Image($combination_image_id);
|
||||
$url = _PS_BASE_URL_._THEME_PROD_DIR_.$result2->getExistingImgPath().".jpg";
|
||||
|
||||
/*
|
||||
$id_attributes = Db::getInstance()->executeS('SELECT `id_attribute` FROM `' . _DB_PREFIX_ . 'product_attribute_combination`
|
||||
WHERE `id_product_attribute` = 9');
|
||||
*/
|
||||
|
||||
if (count($combination_image_id) == 0){
|
||||
$id_image = Product::getCover($id_product);
|
||||
if ($id_image > 0)
|
||||
{
|
||||
$image = new Image($id_image['id_image']);
|
||||
$url = _PS_BASE_URL_._THEME_PROD_DIR_.$image->getExistingImgPath().'.jpg';
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_POST['fixed_price'])){
|
||||
$name = $cur_cart->id."_".$id_product.".jpg";
|
||||
$img = _PS_IMG_DIR_.'wycinek/'.$name;
|
||||
file_put_contents($img, file_get_contents($url));
|
||||
}
|
||||
|
||||
if ($_POST["is_reflection"] == 1){
|
||||
$im0 = imagecreatefromjpeg($img);
|
||||
imageflip($im0, IMG_FLIP_HORIZONTAL);
|
||||
imagejpeg($im0, $img);
|
||||
imagedestroy($im0);
|
||||
}
|
||||
|
||||
|
||||
$img_name = $product->name;
|
||||
|
||||
$combination = new Combination($this->id_product_attribute);
|
||||
$img_name = $combination->reference;
|
||||
|
||||
$material_final = $attributes[1]["name"];
|
||||
|
||||
|
||||
if ($_POST["is_crop"] == 1){
|
||||
$im = imagecreatefromjpeg($img);
|
||||
|
||||
$crop_width = $_POST["crop_width"];
|
||||
$crop_height = $_POST["crop_height"];
|
||||
$crop_pos_x = $_POST["crop_pos_x"];
|
||||
$crop_pos_y = $_POST["crop_pos_y"];
|
||||
|
||||
$img_width = imagesx($im);
|
||||
$img_height = imagesy($im);
|
||||
|
||||
$real_crop_pos_x = $crop_pos_x * $img_width / 500;
|
||||
$real_crop_pos_y = $crop_pos_y * $img_height / 300;
|
||||
|
||||
$real_crop_width = $crop_width / 500 * $img_width;
|
||||
$real_crop_height = $crop_height / 300 * $img_height;
|
||||
|
||||
$im2 = imagecrop($im, ['x' => $real_crop_pos_x, 'y' => $real_crop_pos_y, 'width' => $real_crop_width, 'height' => $real_crop_height]);
|
||||
if ($im2 !== FALSE) {
|
||||
imagejpeg($im2, $img);
|
||||
imagedestroy($im2);
|
||||
}
|
||||
imagedestroy($im);
|
||||
|
||||
$txt_content = "";
|
||||
|
||||
$txt_content .= "X:".$crop_pos_x."\n";
|
||||
$txt_content .= "Y:".$crop_pos_y."\n";
|
||||
$txt_content .= "WIDTH:".$crop_width."\n";
|
||||
$txt_content .= "HEIGHT:".$crop_height."\n";
|
||||
$txt_content .= "IMAGE_WIDTH:500"."\n";
|
||||
$txt_content .= "IMAGE_HEIGHT:300"."\n";
|
||||
$txt_content .= "CART_ID:".$cur_cart->id."\n";
|
||||
$txt_content .= "PRODUCT_ID:".$id_product."\n";
|
||||
$txt_content .= "MATERIAL:".$material_final."\n";
|
||||
$txt_content .= "IMAGE_NAME:".$img_name."\n";
|
||||
|
||||
|
||||
$txt_content .= "COMBINATION_ID:".$this->id_product_attribute."\n";
|
||||
$txt_content .= "MIRROR_REFLECTION:".$_POST["is_reflection"]."\n";
|
||||
|
||||
$txt_name = $cur_cart->id."_".$id_product.".txt";
|
||||
$txt_dir = _PS_IMG_DIR_.'wycinek/'.$txt_name;
|
||||
|
||||
file_put_contents($txt_dir,$txt_content);
|
||||
|
||||
}
|
||||
|
||||
|
||||
$qty_to_check = $this->qty;
|
||||
$cart_products = $this->context->cart->getProducts();
|
||||
|
||||
if (is_array($cart_products)) {
|
||||
foreach ($cart_products as $cart_product) {
|
||||
if ($this->productInCartMatchesCriteria($cart_product)) {
|
||||
$qty_to_check = $cart_product['cart_quantity'];
|
||||
|
||||
if (Tools::getValue('op', 'up') == 'down') {
|
||||
$qty_to_check -= $this->qty;
|
||||
} else {
|
||||
$qty_to_check += $this->qty;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check product quantity availability
|
||||
if ('update' !== $mode && $this->shouldAvailabilityErrorBeRaised($product, $qty_to_check)) {
|
||||
$this->{$ErrorKey}[] = $this->trans(
|
||||
'The product is no longer available in this quantity.',
|
||||
[],
|
||||
'Shop.Notifications.Error'
|
||||
);
|
||||
}
|
||||
|
||||
// Check minimal_quantity
|
||||
if (!$this->id_product_attribute) {
|
||||
if ($qty_to_check < $product->minimal_quantity) {
|
||||
$this->errors[] = $this->trans(
|
||||
'The minimum purchase order quantity for the product %product% is %quantity%.',
|
||||
['%product%' => $product->name, '%quantity%' => $product->minimal_quantity],
|
||||
'Shop.Notifications.Error'
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
$combination = new Combination($this->id_product_attribute);
|
||||
if ($qty_to_check < $combination->minimal_quantity) {
|
||||
$this->errors[] = $this->trans(
|
||||
'The minimum purchase order quantity for the product %product% is %quantity%.',
|
||||
['%product%' => $product->name, '%quantity%' => $combination->minimal_quantity],
|
||||
'Shop.Notifications.Error'
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_POST['fixed_price'])){
|
||||
$cur_cart->updateQty(-1, $id_product, $id_customization);
|
||||
}
|
||||
|
||||
// If no errors, process product addition
|
||||
if (!$this->errors) {
|
||||
// Add cart if no cart found
|
||||
if (!$this->context->cart->id) {
|
||||
if (Context::getContext()->cookie->id_guest) {
|
||||
$guest = new Guest(Context::getContext()->cookie->id_guest);
|
||||
$this->context->cart->mobile_theme = $guest->mobile_theme;
|
||||
}
|
||||
$this->context->cart->add();
|
||||
if ($this->context->cart->id) {
|
||||
$this->context->cookie->id_cart = (int) $this->context->cart->id;
|
||||
}
|
||||
}
|
||||
|
||||
// Check customizable fields
|
||||
|
||||
if (!$product->hasAllRequiredCustomizableFields() && !$this->customization_id) {
|
||||
$this->{$ErrorKey}[] = $this->trans(
|
||||
'Please fill in all of the required fields, and then save your customizations.',
|
||||
[],
|
||||
'Shop.Notifications.Error'
|
||||
);
|
||||
}
|
||||
|
||||
if (!$this->errors) {
|
||||
$cart_rules = $this->context->cart->getCartRules();
|
||||
$available_cart_rules = CartRule::getCustomerCartRules(
|
||||
$this->context->language->id,
|
||||
(isset($this->context->customer->id) ? $this->context->customer->id : 0),
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
$this->context->cart,
|
||||
false,
|
||||
true
|
||||
);
|
||||
$update_quantity = $this->context->cart->updateQty(
|
||||
$this->qty,
|
||||
$this->id_product,
|
||||
$this->id_product_attribute,
|
||||
$this->customization_id,
|
||||
Tools::getValue('op', 'up'),
|
||||
$this->id_address_delivery,
|
||||
null,
|
||||
true,
|
||||
true
|
||||
);
|
||||
if ($update_quantity < 0) {
|
||||
// If product has attribute, minimal quantity is set with minimal quantity of attribute
|
||||
$minimal_quantity = ($this->id_product_attribute)
|
||||
? Attribute::getAttributeMinimalQty($this->id_product_attribute)
|
||||
: $product->minimal_quantity;
|
||||
$this->{$ErrorKey}[] = $this->trans(
|
||||
'You must add %quantity% minimum quantity',
|
||||
['%quantity%' => $minimal_quantity],
|
||||
'Shop.Notifications.Error'
|
||||
);
|
||||
} elseif (!$update_quantity) {
|
||||
$this->errors[] = $this->trans(
|
||||
'You already have the maximum quantity available for this product.',
|
||||
[],
|
||||
'Shop.Notifications.Error'
|
||||
);
|
||||
} elseif ($this->shouldAvailabilityErrorBeRaised($product, $qty_to_check)) {
|
||||
// check quantity after cart quantity update
|
||||
$this->{$ErrorKey}[] = $this->trans(
|
||||
'The product is no longer available in this quantity.',
|
||||
[],
|
||||
'Shop.Notifications.Error'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$removed = CartRule::autoRemoveFromCart();
|
||||
CartRule::autoAddToCart();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $productInCart
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function productInCartMatchesCriteria($productInCart)
|
||||
{
|
||||
return (
|
||||
!isset($this->id_product_attribute) ||
|
||||
(
|
||||
$productInCart['id_product_attribute'] == $this->id_product_attribute &&
|
||||
$productInCart['id_customization'] == $this->customization_id
|
||||
)
|
||||
) && isset($this->id_product) && $productInCart['id_product'] == $this->id_product;
|
||||
}
|
||||
|
||||
public function getTemplateVarPage()
|
||||
{
|
||||
$page = parent::getTemplateVarPage();
|
||||
$presenter = new CartPresenter();
|
||||
$presented_cart = $presenter->present($this->context->cart);
|
||||
|
||||
if (count($presented_cart['products']) == 0) {
|
||||
$page['body_classes']['cart-empty'] = true;
|
||||
}
|
||||
|
||||
return $page;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check product quantity availability to acknowledge whether
|
||||
* an availability error should be raised.
|
||||
*
|
||||
* If shop has been configured to oversell, answer is no.
|
||||
* If there is no items available (no stock), answer is yes.
|
||||
* If there is items available, but the Cart already contains more than the quantity,
|
||||
* answer is yes.
|
||||
*
|
||||
* @param Product $product
|
||||
* @param int $qtyToCheck
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function shouldAvailabilityErrorBeRaised($product, $qtyToCheck)
|
||||
{
|
||||
if (($this->id_product_attribute)) {
|
||||
return !Product::isAvailableWhenOutOfStock($product->out_of_stock)
|
||||
&& !Attribute::checkAttributeQty($this->id_product_attribute, $qtyToCheck);
|
||||
} elseif (Product::isAvailableWhenOutOfStock($product->out_of_stock)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if this product is out-of-stock
|
||||
$availableProductQuantity = StockAvailable::getQuantityAvailableByProduct(
|
||||
$this->id_product,
|
||||
$this->id_product_attribute
|
||||
);
|
||||
if ($availableProductQuantity <= 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check if this product is out-of-stock after cart quantities have been removed from stock
|
||||
// Be aware that Product::getQuantity() returns the available quantity after decreasing products in cart
|
||||
$productQuantityAvailableAfterCartItemsHaveBeenRemovedFromStock = Product::getQuantity(
|
||||
$this->id_product,
|
||||
$this->id_product_attribute,
|
||||
null,
|
||||
$this->context->cart,
|
||||
$this->customization_id
|
||||
);
|
||||
|
||||
return $productQuantityAvailableAfterCartItemsHaveBeenRemovedFromStock < 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the products in the cart are available.
|
||||
*
|
||||
* @return bool|string
|
||||
*/
|
||||
protected function areProductsAvailable()
|
||||
{
|
||||
$products = $this->context->cart->getProducts();
|
||||
|
||||
foreach ($products as $product) {
|
||||
$currentProduct = new Product();
|
||||
$currentProduct->hydrate($product);
|
||||
|
||||
if ($currentProduct->hasAttributes() && $product['id_product_attribute'] === '0') {
|
||||
return $this->trans(
|
||||
'The item %product% in your cart is now a product with attributes. Please delete it and choose one of its combinations to proceed with your order.',
|
||||
['%product%' => $product['name']],
|
||||
'Shop.Notifications.Error'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$product = $this->context->cart->checkQuantities(true);
|
||||
|
||||
if (true === $product || !is_array($product)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($product['active']) {
|
||||
return $this->trans(
|
||||
'The item %product% in your cart is no longer available in this quantity. You cannot proceed with your order until the quantity is adjusted.',
|
||||
['%product%' => $product['name']],
|
||||
'Shop.Notifications.Error'
|
||||
);
|
||||
}
|
||||
|
||||
return $this->trans(
|
||||
'This product (%product%) is no longer available.',
|
||||
['%product%' => $product['name']],
|
||||
'Shop.Notifications.Error'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that minimal quantity conditions are respected for each product in the cart
|
||||
*/
|
||||
private function checkCartProductsMinimalQuantities()
|
||||
{
|
||||
$productList = $this->context->cart->getProducts();
|
||||
|
||||
foreach ($productList as $product) {
|
||||
if ($product['minimal_quantity'] > $product['cart_quantity']) {
|
||||
// display minimal quantity warning error message
|
||||
$this->errors[] = $this->trans(
|
||||
'The minimum purchase order quantity for the product %product% is %quantity%.',
|
||||
[
|
||||
'%product%' => $product['name'],
|
||||
'%quantity%' => $product['minimal_quantity'],
|
||||
],
|
||||
'Shop.Notifications.Error'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
44
controllers/front/ChangeCurrencyController.php
Normal file
44
controllers/front/ChangeCurrencyController.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
class ChangeCurrencyControllerCore extends FrontController
|
||||
{
|
||||
/**
|
||||
* Assign template vars related to page content.
|
||||
*
|
||||
* @see FrontController::initContent()
|
||||
*/
|
||||
public function initContent()
|
||||
{
|
||||
$currency = new Currency((int) Tools::getValue('id_currency'));
|
||||
if (Validate::isLoadedObject($currency) && !$currency->deleted) {
|
||||
$this->context->cookie->id_currency = (int) $currency->id;
|
||||
$this->ajaxRender('1');
|
||||
|
||||
return;
|
||||
}
|
||||
$this->ajaxRender('0');
|
||||
}
|
||||
}
|
||||
236
controllers/front/CmsController.php
Normal file
236
controllers/front/CmsController.php
Normal file
@@ -0,0 +1,236 @@
|
||||
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
class CmsControllerCore extends FrontController
|
||||
{
|
||||
public $php_self = 'cms';
|
||||
public $assignCase;
|
||||
public $cms;
|
||||
|
||||
/** @var CMSCategory */
|
||||
public $cms_category;
|
||||
public $ssl = false;
|
||||
|
||||
public function canonicalRedirection($canonicalURL = '')
|
||||
{
|
||||
if (Validate::isLoadedObject($this->cms) && ($canonicalURL = $this->context->link->getCMSLink($this->cms, $this->cms->link_rewrite, $this->ssl))) {
|
||||
parent::canonicalRedirection($canonicalURL);
|
||||
} elseif (Validate::isLoadedObject($this->cms_category) && ($canonicalURL = $this->context->link->getCMSCategoryLink($this->cms_category))) {
|
||||
parent::canonicalRedirection($canonicalURL);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize cms controller.
|
||||
*
|
||||
* @see FrontController::init()
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
if ($id_cms = (int) Tools::getValue('id_cms')) {
|
||||
$this->cms = new CMS($id_cms, $this->context->language->id, $this->context->shop->id);
|
||||
} elseif ($id_cms_category = (int) Tools::getValue('id_cms_category')) {
|
||||
$this->cms_category = new CMSCategory($id_cms_category, $this->context->language->id, $this->context->shop->id);
|
||||
}
|
||||
|
||||
if (Configuration::get('PS_SSL_ENABLED') && Tools::getValue('content_only') && $id_cms && Validate::isLoadedObject($this->cms)
|
||||
&& in_array($id_cms, $this->getSSLCMSPageIds())) {
|
||||
$this->ssl = true;
|
||||
}
|
||||
|
||||
parent::init();
|
||||
|
||||
$this->canonicalRedirection();
|
||||
|
||||
// assignCase (1 = CMS page, 2 = CMS category)
|
||||
if (Validate::isLoadedObject($this->cms)) {
|
||||
$adtoken = Tools::getAdminToken('AdminCmsContent' . (int) Tab::getIdFromClassName('AdminCmsContent') . (int) Tools::getValue('id_employee'));
|
||||
if (!$this->cms->isAssociatedToShop() || !$this->cms->active && Tools::getValue('adtoken') != $adtoken) {
|
||||
$this->redirect_after = '404';
|
||||
$this->redirect();
|
||||
} else {
|
||||
$this->assignCase = 1;
|
||||
}
|
||||
} elseif (Validate::isLoadedObject($this->cms_category) && $this->cms_category->active) {
|
||||
$this->assignCase = 2;
|
||||
} else {
|
||||
$this->redirect_after = '404';
|
||||
$this->redirect();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign template vars related to page content.
|
||||
*
|
||||
* @see FrontController::initContent()
|
||||
*/
|
||||
public function initContent()
|
||||
{
|
||||
if ($this->assignCase == 1) {
|
||||
$cmsVar = $this->objectPresenter->present($this->cms);
|
||||
|
||||
$filteredCmsContent = Hook::exec(
|
||||
'filterCmsContent',
|
||||
['object' => $cmsVar],
|
||||
$id_module = null,
|
||||
$array_return = false,
|
||||
$check_exceptions = true,
|
||||
$use_push = false,
|
||||
$id_shop = null,
|
||||
$chain = true
|
||||
);
|
||||
if (!empty($filteredCmsContent['object'])) {
|
||||
$cmsVar = $filteredCmsContent['object'];
|
||||
}
|
||||
|
||||
$this->context->smarty->assign([
|
||||
'cms' => $cmsVar,
|
||||
]);
|
||||
|
||||
if ($this->cms->indexation == 0) {
|
||||
$this->context->smarty->assign('nobots', true);
|
||||
}
|
||||
|
||||
// TODO: add own page template
|
||||
if ($this->cms->id == 16) {
|
||||
$this->setTemplate(
|
||||
'custom_pages/architekci/page',
|
||||
['entity' => 'cms', 'id' => $this->cms->id]
|
||||
);
|
||||
} elseif ($this->cms->id == 17) {
|
||||
$this->setTemplate(
|
||||
'custom_pages/dystrybutorzy/page',
|
||||
['entity' => 'cms', 'id' => $this->cms->id]
|
||||
);
|
||||
} elseif ($this->cms->id == 18) {
|
||||
$this->setTemplate(
|
||||
'custom_pages/struktury/page',
|
||||
['entity' => 'cms', 'id' => $this->cms->id]
|
||||
);
|
||||
} else {
|
||||
$this->setTemplate(
|
||||
'cms/page',
|
||||
['entity' => 'cms', 'id' => $this->cms->id]
|
||||
);
|
||||
}
|
||||
} elseif ($this->assignCase == 2) {
|
||||
$cmsCategoryVar = $this->getTemplateVarCategoryCms();
|
||||
|
||||
$filteredCmsCategoryContent = Hook::exec(
|
||||
'filterCmsCategoryContent',
|
||||
['object' => $cmsCategoryVar],
|
||||
$id_module = null,
|
||||
$array_return = false,
|
||||
$check_exceptions = true,
|
||||
$use_push = false,
|
||||
$id_shop = null,
|
||||
$chain = true
|
||||
);
|
||||
if (!empty($filteredCmsCategoryContent['object'])) {
|
||||
$cmsCategoryVar = $filteredCmsCategoryContent['object'];
|
||||
}
|
||||
|
||||
$this->context->smarty->assign($cmsCategoryVar);
|
||||
$this->setTemplate('cms/category');
|
||||
}
|
||||
parent::initContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of IDs of CMS pages, which shouldn't be forwared to their canonical URLs in SSL environment.
|
||||
* Required for pages which are shown in iframes.
|
||||
*/
|
||||
protected function getSSLCMSPageIds()
|
||||
{
|
||||
return [(int) Configuration::get('PS_CONDITIONS_CMS_ID'), (int) Configuration::get('LEGAL_CMS_ID_REVOCATION')];
|
||||
}
|
||||
|
||||
public function getBreadcrumbLinks()
|
||||
{
|
||||
$breadcrumb = parent::getBreadcrumbLinks();
|
||||
|
||||
if ($this->assignCase == 2) {
|
||||
$cmsCategory = new CMSCategory($this->cms_category->id_cms_category);
|
||||
} else {
|
||||
$cmsCategory = new CMSCategory($this->cms->id_cms_category);
|
||||
}
|
||||
|
||||
if ($cmsCategory->id_parent != 0) {
|
||||
foreach (array_reverse($cmsCategory->getParentsCategories()) as $category) {
|
||||
$cmsSubCategory = new CMSCategory($category['id_cms_category']);
|
||||
$breadcrumb['links'][] = [
|
||||
'title' => $cmsSubCategory->getName(),
|
||||
'url' => $this->context->link->getCMSCategoryLink($cmsSubCategory),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->assignCase == 1) {
|
||||
$breadcrumb['links'][] = [
|
||||
'title' => $this->context->controller->cms->meta_title,
|
||||
'url' => $this->context->link->getCMSLink($this->context->controller->cms),
|
||||
];
|
||||
}
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
|
||||
public function getTemplateVarPage()
|
||||
{
|
||||
$page = parent::getTemplateVarPage();
|
||||
|
||||
if ($this->assignCase == 2) {
|
||||
$page['body_classes']['cms-id-' . $this->cms_category->id] = true;
|
||||
} else {
|
||||
$page['body_classes']['cms-id-' . $this->cms->id] = true;
|
||||
if (!$this->cms->indexation) {
|
||||
$page['meta']['robots'] = 'noindex';
|
||||
}
|
||||
}
|
||||
|
||||
return $page;
|
||||
}
|
||||
|
||||
public function getTemplateVarCategoryCms()
|
||||
{
|
||||
$categoryCms = [];
|
||||
|
||||
$categoryCms['cms_category'] = $this->objectPresenter->present($this->cms_category);
|
||||
$categoryCms['sub_categories'] = [];
|
||||
$categoryCms['cms_pages'] = [];
|
||||
|
||||
foreach ($this->cms_category->getSubCategories($this->context->language->id) as $subCategory) {
|
||||
$categoryCms['sub_categories'][$subCategory['id_cms_category']] = $subCategory;
|
||||
$categoryCms['sub_categories'][$subCategory['id_cms_category']]['link'] = $this->context->link->getCMSCategoryLink($subCategory['id_cms_category'], $subCategory['link_rewrite']);
|
||||
}
|
||||
|
||||
foreach (CMS::getCMSPages($this->context->language->id, (int) $this->cms_category->id, true, (int) $this->context->shop->id) as $cmsPages) {
|
||||
$categoryCms['cms_pages'][$cmsPages['id_cms']] = $cmsPages;
|
||||
$categoryCms['cms_pages'][$cmsPages['id_cms']]['link'] = $this->context->link->getCMSLink($cmsPages['id_cms'], $cmsPages['link_rewrite']);
|
||||
}
|
||||
|
||||
return $categoryCms;
|
||||
}
|
||||
}
|
||||
54
controllers/front/ContactController.php
Normal file
54
controllers/front/ContactController.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
class ContactControllerCore extends FrontController
|
||||
{
|
||||
public $php_self = 'contact';
|
||||
public $ssl = true;
|
||||
|
||||
/**
|
||||
* Assign template vars related to page content.
|
||||
*
|
||||
* @see FrontController::initContent()
|
||||
*/
|
||||
public function initContent()
|
||||
{
|
||||
parent::initContent();
|
||||
|
||||
$this->setTemplate('contact');
|
||||
}
|
||||
|
||||
public function getBreadcrumbLinks()
|
||||
{
|
||||
$breadcrumb = parent::getBreadcrumbLinks();
|
||||
|
||||
$breadcrumb['links'][] = [
|
||||
'title' => $this->getTranslator()->trans('Contact us', [], 'Shop.Theme.Global'),
|
||||
'url' => $this->context->link->getPageLink('contact', true),
|
||||
];
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
}
|
||||
212
controllers/front/DiscountController.php
Normal file
212
controllers/front/DiscountController.php
Normal file
@@ -0,0 +1,212 @@
|
||||
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
class DiscountControllerCore extends FrontController
|
||||
{
|
||||
public $auth = true;
|
||||
public $php_self = 'discount';
|
||||
public $authRedirection = 'discount';
|
||||
public $ssl = true;
|
||||
|
||||
/**
|
||||
* Assign template vars related to page content.
|
||||
*
|
||||
* @see FrontController::initContent()
|
||||
*/
|
||||
public function initContent()
|
||||
{
|
||||
if (Configuration::isCatalogMode()) {
|
||||
Tools::redirect('index.php');
|
||||
}
|
||||
|
||||
$cart_rules = $this->getTemplateVarCartRules();
|
||||
|
||||
if (count($cart_rules) <= 0) {
|
||||
$this->warning[] = $this->trans('You do not have any vouchers.', [], 'Shop.Notifications.Warning');
|
||||
}
|
||||
|
||||
$this->context->smarty->assign([
|
||||
'cart_rules' => $cart_rules,
|
||||
]);
|
||||
|
||||
parent::initContent();
|
||||
$this->setTemplate('customer/discount');
|
||||
}
|
||||
|
||||
public function getTemplateVarCartRules()
|
||||
{
|
||||
$cart_rules = [];
|
||||
$customerId = $this->context->customer->id;
|
||||
$languageId = $this->context->language->id;
|
||||
|
||||
$vouchers = CartRule::getCustomerCartRules(
|
||||
$languageId,
|
||||
$customerId,
|
||||
true,
|
||||
false
|
||||
);
|
||||
|
||||
foreach ($vouchers as $key => $voucher) {
|
||||
$voucherCustomerId = (int) $voucher['id_customer'];
|
||||
$voucherIsRestrictedToASingleCustomer = ($voucherCustomerId !== 0);
|
||||
|
||||
if ($voucherIsRestrictedToASingleCustomer && $customerId !== $voucherCustomerId) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$cart_rule = $this->buildCartRuleFromVoucher($voucher);
|
||||
$cart_rules[$key] = $cart_rule;
|
||||
}
|
||||
|
||||
return $cart_rules;
|
||||
}
|
||||
|
||||
public function getBreadcrumbLinks()
|
||||
{
|
||||
$breadcrumb = parent::getBreadcrumbLinks();
|
||||
|
||||
$breadcrumb['links'][] = $this->addMyAccountToBreadcrumb();
|
||||
|
||||
$breadcrumb['links'][] = [
|
||||
'title' => $this->trans('Your vouchers', [], 'Shop.Theme.Customeraccount'),
|
||||
'url' => $this->context->link->getPageLink('discount'),
|
||||
];
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $voucher
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getCombinableVoucherTranslation($voucher)
|
||||
{
|
||||
if ($voucher['cart_rule_restriction']) {
|
||||
$combinableVoucherTranslation = $this->trans('No', [], 'Shop.Theme.Global');
|
||||
} else {
|
||||
$combinableVoucherTranslation = $this->trans('Yes', [], 'Shop.Theme.Global');
|
||||
}
|
||||
|
||||
return $combinableVoucherTranslation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $hasTaxIncluded
|
||||
* @param $amount
|
||||
* @param $currencyId
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function formatReductionAmount($hasTaxIncluded, $amount, $currencyId)
|
||||
{
|
||||
if ($hasTaxIncluded) {
|
||||
$taxTranslation = $this->trans('Tax included', [], 'Shop.Theme.Checkout');
|
||||
} else {
|
||||
$taxTranslation = $this->trans('Tax excluded', [], 'Shop.Theme.Checkout');
|
||||
}
|
||||
|
||||
return sprintf(
|
||||
'%s ' . $taxTranslation,
|
||||
$this->context->getCurrentLocale()->formatPrice($amount, Currency::getIsoCodeById((int) $currencyId))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $percentage
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function formatReductionInPercentage($percentage)
|
||||
{
|
||||
return sprintf('%s%%', $percentage);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $voucher
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function accumulateCartRuleValue($voucher)
|
||||
{
|
||||
$cartRuleValue = [];
|
||||
|
||||
if ($voucher['reduction_percent'] > 0) {
|
||||
$cartRuleValue[] = $this->formatReductionInPercentage($voucher['reduction_percent']);
|
||||
}
|
||||
|
||||
if ($voucher['reduction_amount'] > 0) {
|
||||
$cartRuleValue[] = $this->formatReductionAmount(
|
||||
$voucher['reduction_tax'],
|
||||
$voucher['reduction_amount'],
|
||||
$voucher['reduction_currency']
|
||||
);
|
||||
}
|
||||
|
||||
if ($voucher['free_shipping']) {
|
||||
$cartRuleValue[] = $this->trans('Free shipping', [], 'Shop.Theme.Checkout');
|
||||
}
|
||||
|
||||
if ($voucher['gift_product'] > 0) {
|
||||
$cartRuleValue[] = Product::getProductName(
|
||||
$voucher['gift_product'],
|
||||
$voucher['gift_product_attribute']
|
||||
);
|
||||
}
|
||||
|
||||
return $cartRuleValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $voucher
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function buildCartRuleFromVoucher(array $voucher): array
|
||||
{
|
||||
$voucher['voucher_date'] = Tools::displayDate($voucher['date_to'], null, false);
|
||||
|
||||
if ((int) $voucher['minimum_amount'] === 0) {
|
||||
$voucher['voucher_minimal'] = $this->trans('None', [], 'Shop.Theme.Global');
|
||||
} else {
|
||||
$voucher['voucher_minimal'] = $this->context->getCurrentLocale()->formatPrice(
|
||||
$voucher['minimum_amount'],
|
||||
Currency::getIsoCodeById((int) $voucher['minimum_amount_currency'])
|
||||
);
|
||||
}
|
||||
|
||||
$voucher['voucher_cumulable'] = $this->getCombinableVoucherTranslation($voucher);
|
||||
|
||||
$cartRuleValues = $this->accumulateCartRuleValue($voucher);
|
||||
|
||||
if (0 === count($cartRuleValues)) {
|
||||
$voucher['value'] = '-';
|
||||
} else {
|
||||
$voucher['value'] = implode(' + ', $cartRuleValues);
|
||||
}
|
||||
|
||||
return $voucher;
|
||||
}
|
||||
}
|
||||
349
controllers/front/GetFileController.php
Normal file
349
controllers/front/GetFileController.php
Normal file
@@ -0,0 +1,349 @@
|
||||
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
class GetFileControllerCore extends FrontController
|
||||
{
|
||||
protected $display_header = false;
|
||||
protected $display_footer = false;
|
||||
|
||||
public function init()
|
||||
{
|
||||
if (isset($this->context->employee) && $this->context->employee->isLoggedBack() && Tools::getValue('file')) {
|
||||
// Admin can directly access to file
|
||||
$filename = Tools::getValue('file');
|
||||
if (!Validate::isSha1($filename)) {
|
||||
die(Tools::displayError());
|
||||
}
|
||||
$file = _PS_DOWNLOAD_DIR_ . (string) preg_replace('/\.{2,}/', '.', $filename);
|
||||
$filename = ProductDownload::getFilenameFromFilename(Tools::getValue('file'));
|
||||
if (empty($filename)) {
|
||||
$newFileName = Tools::getValue('filename');
|
||||
if (!empty($newFileName)) {
|
||||
$filename = Tools::getValue('filename');
|
||||
} else {
|
||||
$filename = 'file';
|
||||
}
|
||||
}
|
||||
|
||||
if (!file_exists($file)) {
|
||||
Tools::redirect('index.php');
|
||||
}
|
||||
} else {
|
||||
if (!($key = Tools::getValue('key'))) {
|
||||
$this->displayCustomError('Invalid key.');
|
||||
}
|
||||
|
||||
Tools::setCookieLanguage();
|
||||
if (!$this->context->customer->isLogged()) {
|
||||
if (!Tools::getValue('secure_key') && !Tools::getValue('id_order')) {
|
||||
Tools::redirect('index.php?controller=authentication&back=get-file.php%26key=' . $key);
|
||||
} elseif (Tools::getValue('secure_key') && Tools::getValue('id_order')) {
|
||||
$order = new Order((int) Tools::getValue('id_order'));
|
||||
if (!Validate::isLoadedObject($order)) {
|
||||
$this->displayCustomError('Invalid key.');
|
||||
}
|
||||
if ($order->secure_key != Tools::getValue('secure_key')) {
|
||||
$this->displayCustomError('Invalid key.');
|
||||
}
|
||||
} else {
|
||||
$this->displayCustomError('Invalid key.');
|
||||
}
|
||||
}
|
||||
|
||||
/* Key format: <sha1-filename>-<hashOrder> */
|
||||
$tmp = explode('-', $key);
|
||||
if (count($tmp) != 2) {
|
||||
$this->displayCustomError('Invalid key.');
|
||||
}
|
||||
|
||||
$filename = $tmp[0];
|
||||
$hash = $tmp[1];
|
||||
|
||||
if (!($info = OrderDetail::getDownloadFromHash($hash))) {
|
||||
$this->displayCustomError('This product does not exist in our store.');
|
||||
}
|
||||
|
||||
/* check whether order has been paid, which is required to download the product */
|
||||
$order = new Order((int) $info['id_order']);
|
||||
$state = $order->getCurrentOrderState();
|
||||
if (!$state || !$state->paid) {
|
||||
$this->displayCustomError('This order has not been paid.');
|
||||
}
|
||||
|
||||
// Check whether the order was made by the current user
|
||||
// If the order was made by a guest, skip this step
|
||||
$customer = new Customer((int) $order->id_customer);
|
||||
if (!$customer->is_guest && $order->secure_key !== $this->context->customer->secure_key) {
|
||||
Tools::redirect('index.php?controller=authentication&back=get-file.php%26key=' . $key);
|
||||
}
|
||||
|
||||
/* Product no more present in catalog */
|
||||
if (!isset($info['id_product_download']) || empty($info['id_product_download'])) {
|
||||
$this->displayCustomError('This product has been deleted.');
|
||||
}
|
||||
|
||||
if (!Validate::isFileName($info['filename']) || !file_exists(_PS_DOWNLOAD_DIR_ . $info['filename'])) {
|
||||
$this->displayCustomError('This file no longer exists.');
|
||||
}
|
||||
|
||||
if (isset($info['product_quantity_refunded'], $info['product_quantity_return']) &&
|
||||
($info['product_quantity_refunded'] > 0 || $info['product_quantity_return'] > 0)) {
|
||||
$this->displayCustomError('This product has been refunded.');
|
||||
}
|
||||
|
||||
$now = time();
|
||||
|
||||
$product_deadline = strtotime($info['download_deadline']);
|
||||
if ($now > $product_deadline && $info['download_deadline'] != '0000-00-00 00:00:00') {
|
||||
$this->displayCustomError('The product deadline is in the past.');
|
||||
}
|
||||
|
||||
$customer_deadline = strtotime($info['date_expiration']);
|
||||
if ($now > $customer_deadline && $info['date_expiration'] != '0000-00-00 00:00:00') {
|
||||
$this->displayCustomError('Expiration date has passed, you cannot download this product');
|
||||
}
|
||||
|
||||
if ($info['download_nb'] >= $info['nb_downloadable'] && $info['nb_downloadable']) {
|
||||
$this->displayCustomError('You have reached the maximum number of allowed downloads.');
|
||||
}
|
||||
|
||||
/* Access is authorized -> increment download value for the customer */
|
||||
OrderDetail::incrementDownload($info['id_order_detail']);
|
||||
|
||||
$file = _PS_DOWNLOAD_DIR_ . $info['filename'];
|
||||
$filename = $info['display_filename'];
|
||||
}
|
||||
|
||||
/* Detect mime content type */
|
||||
$mimeType = false;
|
||||
if (function_exists('finfo_open')) {
|
||||
$finfo = @finfo_open(FILEINFO_MIME);
|
||||
$mimeType = @finfo_file($finfo, $file);
|
||||
@finfo_close($finfo);
|
||||
} elseif (function_exists('mime_content_type')) {
|
||||
$mimeType = @mime_content_type($file);
|
||||
} elseif (function_exists('exec')) {
|
||||
$mimeType = trim(@exec('file -b --mime-type ' . escapeshellarg($file)));
|
||||
if (!$mimeType) {
|
||||
$mimeType = trim(@exec('file --mime ' . escapeshellarg($file)));
|
||||
}
|
||||
if (!$mimeType) {
|
||||
$mimeType = trim(@exec('file -bi ' . escapeshellarg($file)));
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($mimeType)) {
|
||||
$bName = basename($filename);
|
||||
$bName = explode('.', $bName);
|
||||
$bName = strtolower($bName[count($bName) - 1]);
|
||||
|
||||
$mimeTypes = [
|
||||
'ez' => 'application/andrew-inset',
|
||||
'hqx' => 'application/mac-binhex40',
|
||||
'cpt' => 'application/mac-compactpro',
|
||||
'doc' => 'application/msword',
|
||||
'oda' => 'application/oda',
|
||||
'pdf' => 'application/pdf',
|
||||
'ai' => 'application/postscript',
|
||||
'eps' => 'application/postscript',
|
||||
'ps' => 'application/postscript',
|
||||
'smi' => 'application/smil',
|
||||
'smil' => 'application/smil',
|
||||
'wbxml' => 'application/vnd.wap.wbxml',
|
||||
'wmlc' => 'application/vnd.wap.wmlc',
|
||||
'wmlsc' => 'application/vnd.wap.wmlscriptc',
|
||||
'bcpio' => 'application/x-bcpio',
|
||||
'vcd' => 'application/x-cdlink',
|
||||
'pgn' => 'application/x-chess-pgn',
|
||||
'cpio' => 'application/x-cpio',
|
||||
'csh' => 'application/x-csh',
|
||||
'dcr' => 'application/x-director',
|
||||
'dir' => 'application/x-director',
|
||||
'dxr' => 'application/x-director',
|
||||
'dvi' => 'application/x-dvi',
|
||||
'spl' => 'application/x-futuresplash',
|
||||
'gtar' => 'application/x-gtar',
|
||||
'hdf' => 'application/x-hdf',
|
||||
'js' => 'application/x-javascript',
|
||||
'skp' => 'application/x-koan',
|
||||
'skd' => 'application/x-koan',
|
||||
'skt' => 'application/x-koan',
|
||||
'skm' => 'application/x-koan',
|
||||
'latex' => 'application/x-latex',
|
||||
'nc' => 'application/x-netcdf',
|
||||
'cdf' => 'application/x-netcdf',
|
||||
'sh' => 'application/x-sh',
|
||||
'shar' => 'application/x-shar',
|
||||
'swf' => 'application/x-shockwave-flash',
|
||||
'sit' => 'application/x-stuffit',
|
||||
'sv4cpio' => 'application/x-sv4cpio',
|
||||
'sv4crc' => 'application/x-sv4crc',
|
||||
'tar' => 'application/x-tar',
|
||||
'tcl' => 'application/x-tcl',
|
||||
'tex' => 'application/x-tex',
|
||||
'texinfo' => 'application/x-texinfo',
|
||||
'texi' => 'application/x-texinfo',
|
||||
't' => 'application/x-troff',
|
||||
'tr' => 'application/x-troff',
|
||||
'roff' => 'application/x-troff',
|
||||
'man' => 'application/x-troff-man',
|
||||
'me' => 'application/x-troff-me',
|
||||
'ms' => 'application/x-troff-ms',
|
||||
'ustar' => 'application/x-ustar',
|
||||
'src' => 'application/x-wais-source',
|
||||
'xhtml' => 'application/xhtml+xml',
|
||||
'xht' => 'application/xhtml+xml',
|
||||
'zip' => 'application/zip',
|
||||
'au' => 'audio/basic',
|
||||
'snd' => 'audio/basic',
|
||||
'mid' => 'audio/midi',
|
||||
'midi' => 'audio/midi',
|
||||
'kar' => 'audio/midi',
|
||||
'mpga' => 'audio/mpeg',
|
||||
'mp2' => 'audio/mpeg',
|
||||
'mp3' => 'audio/mpeg',
|
||||
'aif' => 'audio/x-aiff',
|
||||
'aiff' => 'audio/x-aiff',
|
||||
'aifc' => 'audio/x-aiff',
|
||||
'm3u' => 'audio/x-mpegurl',
|
||||
'ram' => 'audio/x-pn-realaudio',
|
||||
'rm' => 'audio/x-pn-realaudio',
|
||||
'rpm' => 'audio/x-pn-realaudio-plugin',
|
||||
'ra' => 'audio/x-realaudio',
|
||||
'wav' => 'audio/x-wav',
|
||||
'pdb' => 'chemical/x-pdb',
|
||||
'xyz' => 'chemical/x-xyz',
|
||||
'bmp' => 'image/bmp',
|
||||
'gif' => 'image/gif',
|
||||
'ief' => 'image/ief',
|
||||
'jpeg' => 'image/jpeg',
|
||||
'jpg' => 'image/jpeg',
|
||||
'jpe' => 'image/jpeg',
|
||||
'png' => 'image/png',
|
||||
'tiff' => 'image/tiff',
|
||||
'tif' => 'image/tif',
|
||||
'djvu' => 'image/vnd.djvu',
|
||||
'djv' => 'image/vnd.djvu',
|
||||
'wbmp' => 'image/vnd.wap.wbmp',
|
||||
'ras' => 'image/x-cmu-raster',
|
||||
'pnm' => 'image/x-portable-anymap',
|
||||
'pbm' => 'image/x-portable-bitmap',
|
||||
'pgm' => 'image/x-portable-graymap',
|
||||
'ppm' => 'image/x-portable-pixmap',
|
||||
'rgb' => 'image/x-rgb',
|
||||
'xbm' => 'image/x-xbitmap',
|
||||
'xpm' => 'image/x-xpixmap',
|
||||
'xwd' => 'image/x-windowdump',
|
||||
'igs' => 'model/iges',
|
||||
'iges' => 'model/iges',
|
||||
'msh' => 'model/mesh',
|
||||
'mesh' => 'model/mesh',
|
||||
'silo' => 'model/mesh',
|
||||
'wrl' => 'model/vrml',
|
||||
'vrml' => 'model/vrml',
|
||||
'css' => 'text/css',
|
||||
'html' => 'text/html',
|
||||
'htm' => 'text/html',
|
||||
'asc' => 'text/plain',
|
||||
'txt' => 'text/plain',
|
||||
'rtx' => 'text/richtext',
|
||||
'rtf' => 'text/rtf',
|
||||
'sgml' => 'text/sgml',
|
||||
'sgm' => 'text/sgml',
|
||||
'tsv' => 'text/tab-seperated-values',
|
||||
'wml' => 'text/vnd.wap.wml',
|
||||
'wmls' => 'text/vnd.wap.wmlscript',
|
||||
'etx' => 'text/x-setext',
|
||||
'xml' => 'text/xml',
|
||||
'xsl' => 'text/xml',
|
||||
'mpeg' => 'video/mpeg',
|
||||
'mpg' => 'video/mpeg',
|
||||
'mpe' => 'video/mpeg',
|
||||
'qt' => 'video/quicktime',
|
||||
'mov' => 'video/quicktime',
|
||||
'mxu' => 'video/vnd.mpegurl',
|
||||
'avi' => 'video/x-msvideo',
|
||||
'movie' => 'video/x-sgi-movie',
|
||||
'ice' => 'x-conference-xcooltalk',
|
||||
];
|
||||
|
||||
if (isset($mimeTypes[$bName])) {
|
||||
$mimeType = $mimeTypes[$bName];
|
||||
} else {
|
||||
$mimeType = 'application/octet-stream';
|
||||
}
|
||||
}
|
||||
|
||||
if (ob_get_level() && ob_get_length() > 0) {
|
||||
ob_end_clean();
|
||||
}
|
||||
|
||||
/* Set headers for download */
|
||||
header('Content-Transfer-Encoding: binary');
|
||||
header('Content-Type: ' . $mimeType);
|
||||
header('Content-Length: ' . filesize($file));
|
||||
header('Content-Disposition: attachment; filename="' . $filename . '"');
|
||||
//prevents max execution timeout, when reading large files
|
||||
@set_time_limit(0);
|
||||
$fp = fopen($file, 'rb');
|
||||
|
||||
if ($fp && is_resource($fp)) {
|
||||
while (!feof($fp)) {
|
||||
echo fgets($fp, 16384);
|
||||
}
|
||||
}
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display an error message with js
|
||||
* and redirect using js function.
|
||||
*
|
||||
* @param string $msg
|
||||
*/
|
||||
protected function displayCustomError($msg)
|
||||
{
|
||||
$translations = [
|
||||
'Invalid key.' => $this->trans('Invalid key.', [], 'Shop.Notifications.Error'),
|
||||
'This product does not exist in our store.' => $this->trans('This product does not exist in our store.', [], 'Shop.Notifications.Error'),
|
||||
'This product has been deleted.' => $this->trans('This product has been deleted.', [], 'Shop.Notifications.Error'),
|
||||
'This file no longer exists.' => $this->trans('This file no longer exists.', [], 'Shop.Notifications.Error'),
|
||||
'This product has been refunded.' => $this->trans('This product has been refunded.', [], 'Shop.Notifications.Error'),
|
||||
'The product deadline is in the past.' => $this->trans('The product deadline is in the past.', [], 'Shop.Notifications.Error'),
|
||||
'Expiration date exceeded' => $this->trans('The product expiration date has passed, preventing you from download this product.', [], 'Shop.Notifications.Error'),
|
||||
'Expiration date has passed, you cannot download this product' => $this->trans('Expiration date has passed, you cannot download this product.', [], 'Shop.Notifications.Error'),
|
||||
'You have reached the maximum number of allowed downloads.' => $this->trans('You have reached the maximum number of downloads allowed.', [], 'Shop.Notifications.Error'),
|
||||
]; ?>
|
||||
<script type="text/javascript">
|
||||
//<![CDATA[
|
||||
alert("<?php echo isset($translations[$msg]) ? html_entity_decode($translations[$msg], ENT_QUOTES, 'utf-8') : html_entity_decode($msg, ENT_QUOTES, 'utf-8'); ?>");
|
||||
window.location.href = '<?php echo __PS_BASE_URI__; ?>';
|
||||
//]]>
|
||||
</script>
|
||||
<?php
|
||||
exit();
|
||||
}
|
||||
}
|
||||
166
controllers/front/GuestTrackingController.php
Normal file
166
controllers/front/GuestTrackingController.php
Normal file
@@ -0,0 +1,166 @@
|
||||
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
use PrestaShop\PrestaShop\Adapter\Presenter\Order\OrderPresenter;
|
||||
|
||||
class GuestTrackingControllerCore extends FrontController
|
||||
{
|
||||
public $ssl = true;
|
||||
public $auth = false;
|
||||
public $php_self = 'guest-tracking';
|
||||
protected $order;
|
||||
|
||||
/**
|
||||
* Initialize guest tracking controller.
|
||||
*
|
||||
* @see FrontController::init()
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
if ($this->context->customer->isLogged()) {
|
||||
Tools::redirect('history.php');
|
||||
}
|
||||
|
||||
parent::init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Start forms process.
|
||||
*
|
||||
* @see FrontController::postProcess()
|
||||
*/
|
||||
public function postProcess()
|
||||
{
|
||||
$order_reference = current(explode('#', Tools::getValue('order_reference')));
|
||||
$email = Tools::getValue('email');
|
||||
|
||||
if (!$email && !$order_reference) {
|
||||
return;
|
||||
} elseif (!$email || !$order_reference) {
|
||||
$this->errors[] = $this->getTranslator()->trans(
|
||||
'Please provide the required information',
|
||||
[],
|
||||
'Shop.Notifications.Error'
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$isCustomer = Customer::customerExists($email, false, true);
|
||||
if ($isCustomer) {
|
||||
$this->info[] = $this->trans(
|
||||
'Please log in to your customer account to view the order',
|
||||
[],
|
||||
'Shop.Notifications.Info'
|
||||
);
|
||||
$this->redirectWithNotifications($this->context->link->getPageLink('history'));
|
||||
} else {
|
||||
$this->order = Order::getByReferenceAndEmail($order_reference, $email);
|
||||
if (!Validate::isLoadedObject($this->order)) {
|
||||
$this->errors[] = $this->getTranslator()->trans(
|
||||
'We couldn\'t find your order with the information provided, please try again',
|
||||
[],
|
||||
'Shop.Notifications.Error'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (Tools::isSubmit('submitTransformGuestToCustomer') && Tools::getValue('password')) {
|
||||
$customer = new Customer((int) $this->order->id_customer);
|
||||
$password = Tools::getValue('password');
|
||||
|
||||
if (strlen($password) < Validate::PASSWORD_LENGTH) {
|
||||
$this->errors[] = $this->trans(
|
||||
'Your password must be at least %min% characters long.',
|
||||
['%min%' => Validate::PASSWORD_LENGTH],
|
||||
'Shop.Forms.Help'
|
||||
);
|
||||
} elseif ($customer->transformToCustomer($this->context->language->id, $password)) {
|
||||
$this->success[] = $this->trans(
|
||||
'Your guest account has been successfully transformed into a customer account. You can now log in as a registered shopper.',
|
||||
[],
|
||||
'Shop.Notifications.Success'
|
||||
);
|
||||
} else {
|
||||
$this->success[] = $this->trans(
|
||||
'An unexpected error occurred while creating your account.',
|
||||
[],
|
||||
'Shop.Notifications.Error'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign template vars related to page content.
|
||||
*
|
||||
* @see FrontController::initContent()
|
||||
*/
|
||||
public function initContent()
|
||||
{
|
||||
parent::initContent();
|
||||
|
||||
if (!Validate::isLoadedObject($this->order)) {
|
||||
return $this->setTemplate('customer/guest-login');
|
||||
}
|
||||
|
||||
if ((int) $this->order->isReturnable()) {
|
||||
$this->info[] = $this->trans(
|
||||
'You cannot return merchandise with a guest account.',
|
||||
[],
|
||||
'Shop.Notifications.Warning'
|
||||
);
|
||||
}
|
||||
|
||||
$presented_order = (new OrderPresenter())->present($this->order);
|
||||
|
||||
$this->context->smarty->assign([
|
||||
'order' => $presented_order,
|
||||
'guest_email' => Tools::getValue('email'),
|
||||
'HOOK_DISPLAYORDERDETAIL' => Hook::exec('displayOrderDetail', ['order' => $this->order]),
|
||||
]);
|
||||
|
||||
return $this->setTemplate('customer/guest-tracking');
|
||||
}
|
||||
|
||||
public function getBreadcrumbLinks()
|
||||
{
|
||||
$breadcrumbLinks = parent::getBreadcrumbLinks();
|
||||
|
||||
$breadcrumbLinks['links'][] = [
|
||||
'title' => $this->getTranslator()->trans('Guest order tracking', [], 'Shop.Theme.Checkout'),
|
||||
'url' => $this->context->link->getPageLink('guest-tracking'),
|
||||
];
|
||||
|
||||
if (Validate::isLoadedObject($this->order)) {
|
||||
$breadcrumbLinks['links'][] = [
|
||||
'title' => $this->order->reference,
|
||||
'url' => '#',
|
||||
];
|
||||
}
|
||||
|
||||
return $breadcrumbLinks;
|
||||
}
|
||||
}
|
||||
118
controllers/front/HistoryController.php
Normal file
118
controllers/front/HistoryController.php
Normal file
@@ -0,0 +1,118 @@
|
||||
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
use PrestaShop\PrestaShop\Adapter\Presenter\Order\OrderPresenter;
|
||||
|
||||
class HistoryControllerCore extends FrontController
|
||||
{
|
||||
public $auth = true;
|
||||
public $php_self = 'history';
|
||||
public $authRedirection = 'history';
|
||||
public $ssl = true;
|
||||
public $order_presenter;
|
||||
|
||||
/**
|
||||
* Assign template vars related to page content.
|
||||
*
|
||||
* @see FrontController::initContent()
|
||||
*/
|
||||
public function initContent()
|
||||
{
|
||||
if (Configuration::isCatalogMode()) {
|
||||
Tools::redirect('index.php');
|
||||
}
|
||||
|
||||
if ($this->order_presenter === null) {
|
||||
$this->order_presenter = new OrderPresenter();
|
||||
}
|
||||
|
||||
if (Tools::isSubmit('slowvalidation')) {
|
||||
$this->warning[] = $this->trans('If you have just placed an order, it may take a few minutes for it to be validated. Please refresh this page if your order is missing.', [], 'Shop.Notifications.Warning');
|
||||
}
|
||||
|
||||
$orders = $this->getTemplateVarOrders();
|
||||
|
||||
if (count($orders) <= 0) {
|
||||
$this->warning[] = $this->trans('You have not placed any orders.', [], 'Shop.Notifications.Warning');
|
||||
}
|
||||
|
||||
$this->context->smarty->assign([
|
||||
'orders' => $orders,
|
||||
]);
|
||||
|
||||
parent::initContent();
|
||||
$this->setTemplate('customer/history');
|
||||
}
|
||||
|
||||
public function getTemplateVarOrders()
|
||||
{
|
||||
$orders = [];
|
||||
$customer_orders = Order::getCustomerOrders($this->context->customer->id);
|
||||
foreach ($customer_orders as $customer_order) {
|
||||
$order = new Order((int) $customer_order['id_order']);
|
||||
$orders[$customer_order['id_order']] = $this->order_presenter->present($order);
|
||||
}
|
||||
|
||||
return $orders;
|
||||
}
|
||||
|
||||
public static function getUrlToInvoice($order, $context)
|
||||
{
|
||||
$url_to_invoice = '';
|
||||
|
||||
if ((bool) Configuration::get('PS_INVOICE') && OrderState::invoiceAvailable($order->current_state) && count($order->getInvoicesCollection())) {
|
||||
$url_to_invoice = $context->link->getPageLink('pdf-invoice', true, null, 'id_order=' . $order->id);
|
||||
if ($context->cookie->is_guest) {
|
||||
$url_to_invoice .= '&secure_key=' . $order->secure_key;
|
||||
}
|
||||
}
|
||||
|
||||
return $url_to_invoice;
|
||||
}
|
||||
|
||||
public static function getUrlToReorder($id_order, $context)
|
||||
{
|
||||
$url_to_reorder = '';
|
||||
if (!(bool) Configuration::get('PS_DISALLOW_HISTORY_REORDERING')) {
|
||||
$url_to_reorder = $context->link->getPageLink('order', true, null, 'submitReorder&id_order=' . (int) $id_order);
|
||||
}
|
||||
|
||||
return $url_to_reorder;
|
||||
}
|
||||
|
||||
public function getBreadcrumbLinks()
|
||||
{
|
||||
$breadcrumb = parent::getBreadcrumbLinks();
|
||||
|
||||
$breadcrumb['links'][] = $this->addMyAccountToBreadcrumb();
|
||||
|
||||
$breadcrumb['links'][] = [
|
||||
'title' => $this->trans('Order history', [], 'Shop.Theme.Customeraccount'),
|
||||
'url' => $this->context->link->getPageLink('history'),
|
||||
];
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
}
|
||||
92
controllers/front/IdentityController.php
Normal file
92
controllers/front/IdentityController.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
class IdentityControllerCore extends FrontController
|
||||
{
|
||||
public $auth = true;
|
||||
public $php_self = 'identity';
|
||||
public $authRedirection = 'identity';
|
||||
public $ssl = true;
|
||||
|
||||
public $passwordRequired = true;
|
||||
|
||||
/**
|
||||
* Assign template vars related to page content.
|
||||
*
|
||||
* @see FrontController::initContent()
|
||||
*/
|
||||
public function initContent()
|
||||
{
|
||||
$should_redirect = false;
|
||||
|
||||
$customer_form = $this->makeCustomerForm()->setPasswordRequired($this->passwordRequired);
|
||||
$customer = new Customer();
|
||||
|
||||
$customer_form->getFormatter()
|
||||
->setAskForNewPassword(true)
|
||||
->setAskForPassword($this->passwordRequired)
|
||||
->setPasswordRequired($this->passwordRequired)
|
||||
->setPartnerOptinRequired($customer->isFieldRequired('optin'));
|
||||
|
||||
if (Tools::isSubmit('submitCreate')) {
|
||||
$customer_form->fillWith(Tools::getAllValues());
|
||||
if ($customer_form->submit()) {
|
||||
$this->success[] = $this->trans('Information successfully updated.', [], 'Shop.Notifications.Success');
|
||||
$should_redirect = true;
|
||||
} else {
|
||||
$this->errors[] = $this->trans('Could not update your information, please check your data.', [], 'Shop.Notifications.Error');
|
||||
}
|
||||
} else {
|
||||
$customer_form->fillFromCustomer(
|
||||
$this->context->customer
|
||||
);
|
||||
}
|
||||
|
||||
$this->context->smarty->assign([
|
||||
'customer_form' => $customer_form->getProxy(),
|
||||
]);
|
||||
|
||||
if ($should_redirect) {
|
||||
$this->redirectWithNotifications($this->getCurrentURL());
|
||||
}
|
||||
|
||||
parent::initContent();
|
||||
$this->setTemplate('customer/identity');
|
||||
}
|
||||
|
||||
public function getBreadcrumbLinks()
|
||||
{
|
||||
$breadcrumb = parent::getBreadcrumbLinks();
|
||||
|
||||
$breadcrumb['links'][] = $this->addMyAccountToBreadcrumb();
|
||||
|
||||
$breadcrumb['links'][] = [
|
||||
'title' => $this->trans('Your personal information', [], 'Shop.Theme.Customeraccount'),
|
||||
'url' => $this->context->link->getPageLink('identity'),
|
||||
];
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
}
|
||||
43
controllers/front/IndexController.php
Normal file
43
controllers/front/IndexController.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
class IndexControllerCore extends FrontController
|
||||
{
|
||||
public $php_self = 'index';
|
||||
|
||||
/**
|
||||
* Assign template vars related to page content.
|
||||
*
|
||||
* @see FrontController::initContent()
|
||||
*/
|
||||
public function initContent()
|
||||
{
|
||||
parent::initContent();
|
||||
$this->context->smarty->assign([
|
||||
'HOOK_HOME' => Hook::exec('displayHome'),
|
||||
]);
|
||||
$this->setTemplate('index');
|
||||
}
|
||||
}
|
||||
56
controllers/front/MyAccountController.php
Normal file
56
controllers/front/MyAccountController.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
class MyAccountControllerCore extends FrontController
|
||||
{
|
||||
public $auth = true;
|
||||
public $php_self = 'my-account';
|
||||
public $authRedirection = 'my-account';
|
||||
public $ssl = true;
|
||||
|
||||
/**
|
||||
* Assign template vars related to page content.
|
||||
*
|
||||
* @see FrontController::initContent()
|
||||
*/
|
||||
public function initContent()
|
||||
{
|
||||
$this->context->smarty->assign([
|
||||
'logout_url' => $this->context->link->getPageLink('index', true, null, 'mylogout'),
|
||||
]);
|
||||
|
||||
parent::initContent();
|
||||
$this->setTemplate('customer/my-account');
|
||||
}
|
||||
|
||||
public function getBreadcrumbLinks()
|
||||
{
|
||||
$breadcrumb = parent::getBreadcrumbLinks();
|
||||
|
||||
$breadcrumb['links'][] = $this->addMyAccountToBreadcrumb();
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
}
|
||||
166
controllers/front/OrderConfirmationController.php
Normal file
166
controllers/front/OrderConfirmationController.php
Normal file
@@ -0,0 +1,166 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2019 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 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/OSL-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://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2019 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
use PrestaShop\PrestaShop\Adapter\Presenter\Order\OrderPresenter;
|
||||
|
||||
class OrderConfirmationControllerCore extends FrontController
|
||||
{
|
||||
public $ssl = true;
|
||||
public $php_self = 'order-confirmation';
|
||||
public $id_cart;
|
||||
public $id_module;
|
||||
public $id_order;
|
||||
public $reference;
|
||||
public $secure_key;
|
||||
public $order_presenter;
|
||||
|
||||
/**
|
||||
* Initialize order confirmation controller.
|
||||
*
|
||||
* @see FrontController::init()
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
|
||||
if (true === (bool) Tools::getValue('free_order')) {
|
||||
$this->checkFreeOrder();
|
||||
}
|
||||
|
||||
$this->id_cart = (int) (Tools::getValue('id_cart', 0));
|
||||
|
||||
$redirectLink = 'index.php?controller=history';
|
||||
|
||||
$this->id_module = (int) (Tools::getValue('id_module', 0));
|
||||
$this->id_order = Order::getIdByCartId((int) ($this->id_cart));
|
||||
$this->secure_key = Tools::getValue('key', false);
|
||||
$order = new Order((int) ($this->id_order));
|
||||
|
||||
if (!$this->id_order || !$this->id_module || !$this->secure_key || empty($this->secure_key)) {
|
||||
Tools::redirect($redirectLink . (Tools::isSubmit('slowvalidation') ? '&slowvalidation' : ''));
|
||||
}
|
||||
$this->reference = $order->reference;
|
||||
if (!Validate::isLoadedObject($order) || $order->id_customer != $this->context->customer->id || $this->secure_key != $order->secure_key) {
|
||||
Tools::redirect($redirectLink);
|
||||
}
|
||||
$module = Module::getInstanceById((int) ($this->id_module));
|
||||
if ($order->module != $module->name) {
|
||||
Tools::redirect($redirectLink);
|
||||
}
|
||||
$this->order_presenter = new OrderPresenter();
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign template vars related to page content.
|
||||
*
|
||||
* @see FrontController::initContent()
|
||||
*/
|
||||
public function initContent()
|
||||
{
|
||||
if (Configuration::isCatalogMode()) {
|
||||
Tools::redirect('index.php');
|
||||
}
|
||||
|
||||
$order = new Order(Order::getIdByCartId((int) ($this->id_cart)));
|
||||
$presentedOrder = $this->order_presenter->present($order);
|
||||
$register_form = $this
|
||||
->makeCustomerForm()
|
||||
->setGuestAllowed(false)
|
||||
->fillWith(Tools::getAllValues());
|
||||
|
||||
parent::initContent();
|
||||
|
||||
$this->context->smarty->assign(array(
|
||||
'HOOK_ORDER_CONFIRMATION' => $this->displayOrderConfirmation($order),
|
||||
'HOOK_PAYMENT_RETURN' => $this->displayPaymentReturn($order),
|
||||
'order' => $presentedOrder,
|
||||
'register_form' => $register_form,
|
||||
));
|
||||
|
||||
if ($this->context->customer->is_guest) {
|
||||
/* If guest we clear the cookie for security reason */
|
||||
$this->context->customer->mylogout();
|
||||
}
|
||||
|
||||
if ($this->context->customer->isLogged())
|
||||
$this->context->customer->id_default_group;
|
||||
|
||||
$this->setTemplate('checkout/order-confirmation');
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the hook displayPaymentReturn.
|
||||
*/
|
||||
public function displayPaymentReturn($order)
|
||||
{
|
||||
if (!Validate::isUnsignedId($this->id_module)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return Hook::exec('displayPaymentReturn', array('order' => $order), $this->id_module);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the hook displayOrderConfirmation.
|
||||
*/
|
||||
public function displayOrderConfirmation($order)
|
||||
{
|
||||
return Hook::exec('displayOrderConfirmation', array('order' => $order));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an order is free and create it.
|
||||
*/
|
||||
protected function checkFreeOrder()
|
||||
{
|
||||
$cart = $this->context->cart;
|
||||
if ($cart->id_customer == 0 || $cart->id_address_delivery == 0 || $cart->id_address_invoice == 0) {
|
||||
Tools::redirect($this->context->link->getPageLink('order'));
|
||||
}
|
||||
|
||||
$customer = new Customer($cart->id_customer);
|
||||
if (!Validate::isLoadedObject($customer)) {
|
||||
Tools::redirect($this->context->link->getPageLink('order'));
|
||||
}
|
||||
|
||||
$total = (float) $cart->getOrderTotal(true, Cart::BOTH);
|
||||
if ($total > 0) {
|
||||
Tools::redirect($this->context->link->getPageLink('order'));
|
||||
}
|
||||
|
||||
$order = new PaymentFree();
|
||||
$order->validateOrder(
|
||||
$cart->id,
|
||||
Configuration::get('PS_OS_PAYMENT'),
|
||||
0,
|
||||
$this->trans('Free order', array(), 'Admin.Orderscustomers.Feature'),
|
||||
null,
|
||||
array(),
|
||||
null,
|
||||
false,
|
||||
$cart->secure_key
|
||||
);
|
||||
}
|
||||
}
|
||||
360
controllers/front/OrderController.php
Normal file
360
controllers/front/OrderController.php
Normal file
@@ -0,0 +1,360 @@
|
||||
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
use PrestaShop\PrestaShop\Adapter\Product\PriceFormatter;
|
||||
use PrestaShop\PrestaShop\Core\Foundation\Templating\RenderableProxy;
|
||||
|
||||
class OrderControllerCore extends FrontController
|
||||
{
|
||||
public $ssl = true;
|
||||
public $php_self = 'order';
|
||||
public $page_name = 'checkout';
|
||||
public $checkoutWarning = false;
|
||||
|
||||
/**
|
||||
* @var CheckoutProcess
|
||||
*/
|
||||
protected $checkoutProcess;
|
||||
|
||||
/**
|
||||
* @var CartChecksum
|
||||
*/
|
||||
protected $cartChecksum;
|
||||
|
||||
/**
|
||||
* Initialize order controller.
|
||||
*
|
||||
* @see FrontController::init()
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
$this->cartChecksum = new CartChecksum(new AddressChecksum());
|
||||
}
|
||||
|
||||
public function postProcess()
|
||||
{
|
||||
parent::postProcess();
|
||||
|
||||
if (Tools::isSubmit('submitReorder')
|
||||
&& $this->context->customer->isLogged()
|
||||
&& $id_order = (int) Tools::getValue('id_order')
|
||||
) {
|
||||
$oldCart = new Cart(Order::getCartIdStatic($id_order, $this->context->customer->id));
|
||||
$duplication = $oldCart->duplicate();
|
||||
if (!$duplication || !Validate::isLoadedObject($duplication['cart'])) {
|
||||
$this->errors[] = $this->trans('Sorry. We cannot renew your order.', [], 'Shop.Notifications.Error');
|
||||
} elseif (!$duplication['success']) {
|
||||
$this->errors[] = $this->trans(
|
||||
'Some items are no longer available, and we are unable to renew your order.',
|
||||
[],
|
||||
'Shop.Notifications.Error'
|
||||
);
|
||||
} else {
|
||||
$this->context->cookie->id_cart = $duplication['cart']->id;
|
||||
$context = $this->context;
|
||||
$context->cart = $duplication['cart'];
|
||||
CartRule::autoAddToCart($context);
|
||||
$this->context->cookie->write();
|
||||
Tools::redirect('index.php?controller=order');
|
||||
}
|
||||
}
|
||||
|
||||
$this->bootstrap();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return CheckoutProcess
|
||||
*/
|
||||
public function getCheckoutProcess()
|
||||
{
|
||||
return $this->checkoutProcess;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return CheckoutSession
|
||||
*/
|
||||
public function getCheckoutSession()
|
||||
{
|
||||
$deliveryOptionsFinder = new DeliveryOptionsFinder(
|
||||
$this->context,
|
||||
$this->getTranslator(),
|
||||
$this->objectPresenter,
|
||||
new PriceFormatter()
|
||||
);
|
||||
|
||||
$session = new CheckoutSession(
|
||||
$this->context,
|
||||
$deliveryOptionsFinder
|
||||
);
|
||||
|
||||
return $session;
|
||||
}
|
||||
|
||||
protected function bootstrap()
|
||||
{
|
||||
$translator = $this->getTranslator();
|
||||
|
||||
$session = $this->getCheckoutSession();
|
||||
|
||||
$this->checkoutProcess = new CheckoutProcess(
|
||||
$this->context,
|
||||
$session
|
||||
);
|
||||
|
||||
$this->checkoutProcess
|
||||
->addStep(new CheckoutPersonalInformationStep(
|
||||
$this->context,
|
||||
$translator,
|
||||
$this->makeLoginForm(),
|
||||
$this->makeCustomerForm()
|
||||
))
|
||||
->addStep(new CheckoutAddressesStep(
|
||||
$this->context,
|
||||
$translator,
|
||||
$this->makeAddressForm()
|
||||
));
|
||||
|
||||
if (!$this->context->cart->isVirtualCart()) {
|
||||
$checkoutDeliveryStep = new CheckoutDeliveryStep(
|
||||
$this->context,
|
||||
$translator
|
||||
);
|
||||
|
||||
$checkoutDeliveryStep
|
||||
->setRecyclablePackAllowed((bool) Configuration::get('PS_RECYCLABLE_PACK'))
|
||||
->setGiftAllowed((bool) Configuration::get('PS_GIFT_WRAPPING'))
|
||||
->setIncludeTaxes(
|
||||
!Product::getTaxCalculationMethod((int) $this->context->cart->id_customer)
|
||||
&& (int) Configuration::get('PS_TAX')
|
||||
)
|
||||
->setDisplayTaxesLabel((Configuration::get('PS_TAX') && !Configuration::get('AEUC_LABEL_TAX_INC_EXC')))
|
||||
->setGiftCost(
|
||||
$this->context->cart->getGiftWrappingPrice(
|
||||
$checkoutDeliveryStep->getIncludeTaxes()
|
||||
)
|
||||
);
|
||||
|
||||
$this->checkoutProcess->addStep($checkoutDeliveryStep);
|
||||
}
|
||||
|
||||
$this->checkoutProcess
|
||||
->addStep(new CheckoutPaymentStep(
|
||||
$this->context,
|
||||
$translator,
|
||||
new PaymentOptionsFinder(),
|
||||
new ConditionsToApproveFinder(
|
||||
$this->context,
|
||||
$translator
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Persists cart-related data in checkout session.
|
||||
*
|
||||
* @param CheckoutProcess $process
|
||||
*/
|
||||
protected function saveDataToPersist(CheckoutProcess $process)
|
||||
{
|
||||
$data = $process->getDataToPersist();
|
||||
$addressValidator = new AddressValidator($this->context);
|
||||
$customer = $this->context->customer;
|
||||
$cart = $this->context->cart;
|
||||
|
||||
$shouldGenerateChecksum = false;
|
||||
|
||||
if ($customer->isGuest()) {
|
||||
$shouldGenerateChecksum = true;
|
||||
} else {
|
||||
$invalidAddressIds = $addressValidator->validateCartAddresses($cart);
|
||||
if (empty($invalidAddressIds)) {
|
||||
$shouldGenerateChecksum = true;
|
||||
}
|
||||
}
|
||||
|
||||
$data['checksum'] = $shouldGenerateChecksum
|
||||
? $this->cartChecksum->generateChecksum($cart)
|
||||
: null;
|
||||
|
||||
Db::getInstance()->execute(
|
||||
'UPDATE ' . _DB_PREFIX_ . 'cart SET checkout_session_data = "' . pSQL(json_encode($data)) . '"
|
||||
WHERE id_cart = ' . (int) $cart->id
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Restores from checkout session some previously persisted cart-related data.
|
||||
*
|
||||
* @param CheckoutProcess $process
|
||||
*/
|
||||
protected function restorePersistedData(CheckoutProcess $process)
|
||||
{
|
||||
$cart = $this->context->cart;
|
||||
$customer = $this->context->customer;
|
||||
$rawData = Db::getInstance()->getValue(
|
||||
'SELECT checkout_session_data FROM ' . _DB_PREFIX_ . 'cart WHERE id_cart = ' . (int) $cart->id
|
||||
);
|
||||
$data = json_decode($rawData, true);
|
||||
if (!is_array($data)) {
|
||||
$data = [];
|
||||
}
|
||||
|
||||
$addressValidator = new AddressValidator();
|
||||
$invalidAddressIds = $addressValidator->validateCartAddresses($cart);
|
||||
|
||||
// Build the currently selected address' warning message (if relevant)
|
||||
if (!$customer->isGuest() && !empty($invalidAddressIds)) {
|
||||
$this->checkoutWarning['address'] = [
|
||||
'id_address' => (int) reset($invalidAddressIds),
|
||||
'exception' => $this->trans(
|
||||
'Your address is incomplete, please update it.',
|
||||
[],
|
||||
'Shop.Notifications.Error'
|
||||
),
|
||||
];
|
||||
|
||||
$checksum = null;
|
||||
} else {
|
||||
$checksum = $this->cartChecksum->generateChecksum($cart);
|
||||
}
|
||||
|
||||
// Prepare all other addresses' warning messages (if relevant).
|
||||
// These messages are displayed when changing the selected address.
|
||||
$allInvalidAddressIds = $addressValidator->validateCustomerAddresses($customer, $this->context->language);
|
||||
$this->checkoutWarning['invalid_addresses'] = $allInvalidAddressIds;
|
||||
|
||||
if (isset($data['checksum']) && $data['checksum'] === $checksum) {
|
||||
$process->restorePersistedData($data);
|
||||
}
|
||||
}
|
||||
|
||||
public function displayAjaxselectDeliveryOption()
|
||||
{
|
||||
$cart = $this->cart_presenter->present(
|
||||
$this->context->cart,
|
||||
true
|
||||
);
|
||||
|
||||
ob_end_clean();
|
||||
header('Content-Type: application/json');
|
||||
$this->ajaxRender(Tools::jsonEncode([
|
||||
'preview' => $this->render('checkout/_partials/cart-summary', [
|
||||
'cart' => $cart,
|
||||
'static_token' => Tools::getToken(false),
|
||||
]),
|
||||
]));
|
||||
}
|
||||
|
||||
public function initContent()
|
||||
{
|
||||
if (Configuration::isCatalogMode()) {
|
||||
Tools::redirect('index.php');
|
||||
}
|
||||
|
||||
$this->restorePersistedData($this->checkoutProcess);
|
||||
$this->checkoutProcess->handleRequest(
|
||||
Tools::getAllValues()
|
||||
);
|
||||
|
||||
$presentedCart = $this->cart_presenter->present($this->context->cart, true);
|
||||
|
||||
if (count($presentedCart['products']) <= 0 || $presentedCart['minimalPurchaseRequired']) {
|
||||
// if there is no product in current cart, redirect to cart page
|
||||
$cartLink = $this->context->link->getPageLink('cart');
|
||||
Tools::redirect($cartLink);
|
||||
}
|
||||
|
||||
$product = $this->context->cart->checkQuantities(true);
|
||||
if (is_array($product)) {
|
||||
// if there is an issue with product quantities, redirect to cart page
|
||||
$cartLink = $this->context->link->getPageLink('cart', null, null, ['action' => 'show']);
|
||||
Tools::redirect($cartLink);
|
||||
}
|
||||
|
||||
$this->checkoutProcess
|
||||
->setNextStepReachable()
|
||||
->markCurrentStep()
|
||||
->invalidateAllStepsAfterCurrent();
|
||||
|
||||
$this->saveDataToPersist($this->checkoutProcess);
|
||||
|
||||
if (!$this->checkoutProcess->hasErrors()) {
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'GET' && !$this->ajax) {
|
||||
return $this->redirectWithNotifications(
|
||||
$this->checkoutProcess->getCheckoutSession()->getCheckoutURL()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$this->context->smarty->assign([
|
||||
'checkout_process' => new RenderableProxy($this->checkoutProcess),
|
||||
'cart' => $presentedCart,
|
||||
]);
|
||||
|
||||
$this->context->smarty->assign([
|
||||
'display_transaction_updated_info' => Tools::getIsset('updatedTransaction'),
|
||||
]);
|
||||
|
||||
parent::initContent();
|
||||
$this->setTemplate('checkout/checkout');
|
||||
}
|
||||
|
||||
public function displayAjaxAddressForm()
|
||||
{
|
||||
$addressForm = $this->makeAddressForm();
|
||||
|
||||
if (Tools::getIsset('id_address') && ($id_address = (int) Tools::getValue('id_address'))) {
|
||||
$addressForm->loadAddressById($id_address);
|
||||
}
|
||||
|
||||
if (Tools::getIsset('id_country')) {
|
||||
$addressForm->fillWith(['id_country' => Tools::getValue('id_country')]);
|
||||
}
|
||||
|
||||
$stepTemplateParameters = [];
|
||||
foreach ($this->checkoutProcess->getSteps() as $step) {
|
||||
if ($step instanceof CheckoutAddressesStep) {
|
||||
$stepTemplateParameters = $step->getTemplateParameters();
|
||||
}
|
||||
}
|
||||
|
||||
$templateParams = array_merge(
|
||||
$addressForm->getTemplateVariables(),
|
||||
$stepTemplateParameters,
|
||||
['type' => 'delivery']
|
||||
);
|
||||
|
||||
ob_end_clean();
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$this->ajaxRender(Tools::jsonEncode([
|
||||
'address_form' => $this->render(
|
||||
'checkout/_partials/address-form',
|
||||
$templateParams
|
||||
),
|
||||
]));
|
||||
}
|
||||
}
|
||||
225
controllers/front/OrderDetailController.php
Normal file
225
controllers/front/OrderDetailController.php
Normal file
@@ -0,0 +1,225 @@
|
||||
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
use PrestaShop\PrestaShop\Adapter\Presenter\Order\OrderPresenter;
|
||||
|
||||
class OrderDetailControllerCore extends FrontController
|
||||
{
|
||||
public $php_self = 'order-detail';
|
||||
public $auth = true;
|
||||
public $authRedirection = 'history';
|
||||
public $ssl = true;
|
||||
|
||||
protected $order_to_display;
|
||||
|
||||
protected $reference;
|
||||
|
||||
/**
|
||||
* Start forms process.
|
||||
*
|
||||
* @see FrontController::postProcess()
|
||||
*/
|
||||
public function postProcess()
|
||||
{
|
||||
if (Tools::isSubmit('submitMessage')) {
|
||||
$idOrder = (int) Tools::getValue('id_order');
|
||||
$msgText = Tools::getValue('msgText');
|
||||
|
||||
if (!$idOrder || !Validate::isUnsignedId($idOrder)) {
|
||||
$this->errors[] = $this->trans('The order is no longer valid.', [], 'Shop.Notifications.Error');
|
||||
} elseif (empty($msgText)) {
|
||||
$this->errors[] = $this->trans('The message cannot be blank.', [], 'Shop.Notifications.Error');
|
||||
} elseif (!Validate::isMessage($msgText)) {
|
||||
$this->errors[] = $this->trans('This message is invalid (HTML is not allowed).', [], 'Shop.Notifications.Error');
|
||||
}
|
||||
if (!count($this->errors)) {
|
||||
$order = new Order($idOrder);
|
||||
if (Validate::isLoadedObject($order) && $order->id_customer == $this->context->customer->id) {
|
||||
//check if a thread already exist
|
||||
$id_customer_thread = CustomerThread::getIdCustomerThreadByEmailAndIdOrder($this->context->customer->email, $order->id);
|
||||
$id_product = (int) Tools::getValue('id_product');
|
||||
$cm = new CustomerMessage();
|
||||
if (!$id_customer_thread) {
|
||||
$ct = new CustomerThread();
|
||||
$ct->id_contact = 0;
|
||||
$ct->id_customer = (int) $order->id_customer;
|
||||
$ct->id_shop = (int) $this->context->shop->id;
|
||||
if ($id_product && $order->orderContainProduct($id_product)) {
|
||||
$ct->id_product = $id_product;
|
||||
}
|
||||
$ct->id_order = (int) $order->id;
|
||||
$ct->id_lang = (int) $this->context->language->id;
|
||||
$ct->email = $this->context->customer->email;
|
||||
$ct->status = 'open';
|
||||
$ct->token = Tools::passwdGen(12);
|
||||
$ct->add();
|
||||
} else {
|
||||
$ct = new CustomerThread((int) $id_customer_thread);
|
||||
$ct->status = 'open';
|
||||
$ct->update();
|
||||
}
|
||||
|
||||
$cm->id_customer_thread = $ct->id;
|
||||
$cm->message = $msgText;
|
||||
$client_ip_address = Tools::getRemoteAddr();
|
||||
$cm->ip_address = (int) ip2long($client_ip_address);
|
||||
$cm->add();
|
||||
|
||||
if (!Configuration::get('PS_MAIL_EMAIL_MESSAGE')) {
|
||||
$to = (string) Configuration::get('PS_SHOP_EMAIL');
|
||||
} else {
|
||||
$to = new Contact((int) Configuration::get('PS_MAIL_EMAIL_MESSAGE'));
|
||||
$to = (string) $to->email;
|
||||
}
|
||||
$toName = (string) Configuration::get('PS_SHOP_NAME');
|
||||
$customer = $this->context->customer;
|
||||
|
||||
$product = new Product($id_product);
|
||||
$product_name = '';
|
||||
if (Validate::isLoadedObject($product) && isset($product->name[(int) $this->context->language->id])) {
|
||||
$product_name = $product->name[(int) $this->context->language->id];
|
||||
}
|
||||
|
||||
if (Validate::isLoadedObject($customer)) {
|
||||
Mail::Send(
|
||||
$this->context->language->id,
|
||||
'order_customer_comment',
|
||||
$this->trans(
|
||||
'Message from a customer',
|
||||
[],
|
||||
'Emails.Subject'
|
||||
),
|
||||
[
|
||||
'{lastname}' => $customer->lastname,
|
||||
'{firstname}' => $customer->firstname,
|
||||
'{email}' => $customer->email,
|
||||
'{id_order}' => (int) $order->id,
|
||||
'{order_name}' => $order->getUniqReference(),
|
||||
'{message}' => Tools::nl2br(Tools::htmlentitiesUTF8($msgText)),
|
||||
'{product_name}' => $product_name,
|
||||
],
|
||||
$to,
|
||||
$toName,
|
||||
(string) Configuration::get('PS_SHOP_EMAIL'),
|
||||
$customer->firstname . ' ' . $customer->lastname,
|
||||
null,
|
||||
null,
|
||||
_PS_MAIL_DIR_,
|
||||
false,
|
||||
null,
|
||||
null,
|
||||
$customer->email
|
||||
);
|
||||
}
|
||||
|
||||
Tools::redirect('index.php?controller=order-detail&id_order=' . $idOrder . '&messagesent');
|
||||
} else {
|
||||
$this->redirect_after = '404';
|
||||
$this->redirect();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign template vars related to page content.
|
||||
*
|
||||
* @see FrontController::initContent()
|
||||
*/
|
||||
public function initContent()
|
||||
{
|
||||
if (Configuration::isCatalogMode()) {
|
||||
Tools::redirect('index.php');
|
||||
}
|
||||
|
||||
$id_order = (int) Tools::getValue('id_order');
|
||||
$id_order = $id_order && Validate::isUnsignedId($id_order) ? $id_order : false;
|
||||
|
||||
if (!$id_order) {
|
||||
$reference = Tools::getValue('reference');
|
||||
$reference = $reference && Validate::isReference($reference) ? $reference : false;
|
||||
$order = $reference ? Order::getByReference($reference)->getFirst() : false;
|
||||
$id_order = $order ? $order->id : false;
|
||||
}
|
||||
|
||||
if (!$id_order) {
|
||||
$this->redirect_after = '404';
|
||||
$this->redirect();
|
||||
} else {
|
||||
if (Tools::getIsset('errorQuantity')) {
|
||||
$this->errors[] = $this->trans('You do not have enough products to request an additional merchandise return.', [], 'Shop.Notifications.Error');
|
||||
} elseif (Tools::getIsset('errorMsg')) {
|
||||
$this->errors[] = $this->trans('Please provide an explanation for your RMA.', [], 'Shop.Notifications.Error');
|
||||
} elseif (Tools::getIsset('errorDetail1')) {
|
||||
$this->errors[] = $this->trans('Please check at least one product you would like to return.', [], 'Shop.Notifications.Error');
|
||||
} elseif (Tools::getIsset('errorDetail2')) {
|
||||
$this->errors[] = $this->trans('For each product you wish to add, please specify the desired quantity.', [], 'Shop.Notifications.Error');
|
||||
} elseif (Tools::getIsset('errorNotReturnable')) {
|
||||
$this->errors[] = $this->trans('This order cannot be returned', [], 'Shop.Notifications.Error');
|
||||
} elseif (Tools::getIsset('messagesent')) {
|
||||
$this->success[] = $this->trans('Message successfully sent', [], 'Shop.Notifications.Success');
|
||||
}
|
||||
|
||||
$order = new Order($id_order);
|
||||
if (Validate::isLoadedObject($order) && $order->id_customer == $this->context->customer->id) {
|
||||
$this->order_to_display = (new OrderPresenter())->present($order);
|
||||
|
||||
$this->reference = $order->reference;
|
||||
|
||||
$this->context->smarty->assign([
|
||||
'order' => $this->order_to_display,
|
||||
'HOOK_DISPLAYORDERDETAIL' => Hook::exec('displayOrderDetail', ['order' => $order]),
|
||||
]);
|
||||
} else {
|
||||
$this->redirect_after = '404';
|
||||
$this->redirect();
|
||||
}
|
||||
unset($order);
|
||||
}
|
||||
|
||||
parent::initContent();
|
||||
$this->setTemplate('customer/order-detail');
|
||||
}
|
||||
|
||||
public function getBreadcrumbLinks()
|
||||
{
|
||||
$breadcrumb = parent::getBreadcrumbLinks();
|
||||
|
||||
$breadcrumb['links'][] = $this->addMyAccountToBreadcrumb();
|
||||
$breadcrumb['links'][] = [
|
||||
'title' => $this->trans('Order history', [], 'Shop.Theme.Customeraccount'),
|
||||
'url' => $this->context->link->getPageLink('history'),
|
||||
];
|
||||
|
||||
if (!empty($this->reference)) {
|
||||
$breadcrumb['links'][] = [
|
||||
'title' => $this->reference,
|
||||
'url' => '#',
|
||||
];
|
||||
}
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
}
|
||||
145
controllers/front/OrderFollowController.php
Normal file
145
controllers/front/OrderFollowController.php
Normal file
@@ -0,0 +1,145 @@
|
||||
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
use PrestaShop\PrestaShop\Adapter\Presenter\Order\OrderReturnPresenter;
|
||||
|
||||
class OrderFollowControllerCore extends FrontController
|
||||
{
|
||||
public $auth = true;
|
||||
public $php_self = 'order-follow';
|
||||
public $authRedirection = 'order-follow';
|
||||
public $ssl = true;
|
||||
|
||||
/**
|
||||
* Start forms process.
|
||||
*
|
||||
* @see FrontController::postProcess()
|
||||
*/
|
||||
public function postProcess()
|
||||
{
|
||||
if (Tools::isSubmit('submitReturnMerchandise')) {
|
||||
$customizationQtyInput = Tools::getValue('customization_qty_input');
|
||||
$order_qte_input = Tools::getValue('order_qte_input');
|
||||
$customizationIds = Tools::getValue('customization_ids');
|
||||
|
||||
if (!$id_order = (int) Tools::getValue('id_order')) {
|
||||
Tools::redirect('index.php?controller=history');
|
||||
}
|
||||
if (!($ids_order_detail = Tools::getValue('ids_order_detail')) && !$customizationQtyInput && !$customizationIds) {
|
||||
Tools::redirect('index.php?controller=order-detail&id_order=' . $id_order . '&errorDetail1');
|
||||
}
|
||||
if (!$customizationIds && !$order_qte_input) {
|
||||
Tools::redirect('index.php?controller=order-detail&id_order=' . $id_order . '&errorDetail2');
|
||||
}
|
||||
|
||||
$order = new Order((int) $id_order);
|
||||
if (!$order->isReturnable()) {
|
||||
Tools::redirect('index.php?controller=order-detail&id_order=' . $id_order . '&errorNotReturnable');
|
||||
}
|
||||
if ($order->id_customer != $this->context->customer->id) {
|
||||
die(Tools::displayError());
|
||||
}
|
||||
$orderReturn = new OrderReturn();
|
||||
$orderReturn->id_customer = (int) $this->context->customer->id;
|
||||
$orderReturn->id_order = $id_order;
|
||||
$orderReturn->question = htmlspecialchars(Tools::getValue('returnText'));
|
||||
if (empty($orderReturn->question)) {
|
||||
Tools::redirect('index.php?controller=order-detail&id_order=' . $id_order . '&errorMsg&' .
|
||||
http_build_query([
|
||||
'ids_order_detail' => $ids_order_detail,
|
||||
'order_qte_input' => $order_qte_input,
|
||||
'id_order' => Tools::getValue('id_order'),
|
||||
]));
|
||||
}
|
||||
|
||||
if (!$orderReturn->checkEnoughProduct($ids_order_detail, $order_qte_input, $customizationIds, $customizationQtyInput)) {
|
||||
Tools::redirect('index.php?controller=order-detail&id_order=' . $id_order . '&errorQuantity');
|
||||
}
|
||||
|
||||
$orderReturn->state = 1;
|
||||
$orderReturn->add();
|
||||
$orderReturn->addReturnDetail($ids_order_detail, $order_qte_input, $customizationIds, $customizationQtyInput);
|
||||
Hook::exec('actionOrderReturn', ['orderReturn' => $orderReturn]);
|
||||
Tools::redirect('index.php?controller=order-follow');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign template vars related to page content.
|
||||
*
|
||||
* @see FrontController::initContent()
|
||||
*/
|
||||
public function initContent()
|
||||
{
|
||||
if ((bool) Configuration::get('PS_ORDER_RETURN') === false) {
|
||||
$this->redirect_after = '404';
|
||||
$this->redirect();
|
||||
}
|
||||
|
||||
if (Configuration::isCatalogMode()) {
|
||||
Tools::redirect('index.php');
|
||||
}
|
||||
|
||||
$ordersReturn = $this->getTemplateVarOrdersReturns();
|
||||
if (count($ordersReturn) <= 0) {
|
||||
$this->warning[] = $this->trans(
|
||||
'You have no merchandise return authorizations.',
|
||||
[],
|
||||
'Shop.Notifications.Error'
|
||||
);
|
||||
}
|
||||
|
||||
$this->context->smarty->assign('ordersReturn', $ordersReturn);
|
||||
|
||||
parent::initContent();
|
||||
$this->setTemplate('customer/order-follow');
|
||||
}
|
||||
|
||||
public function getTemplateVarOrdersReturns()
|
||||
{
|
||||
$orders_returns = [];
|
||||
$orders_return = OrderReturn::getOrdersReturn($this->context->customer->id);
|
||||
|
||||
$orderReturnPresenter = new OrderReturnPresenter(
|
||||
Configuration::get('PS_RETURN_PREFIX', $this->context->language->id),
|
||||
$this->context->link
|
||||
);
|
||||
|
||||
foreach ($orders_return as $id_order_return => $order_return) {
|
||||
$orders_returns[$id_order_return] = $orderReturnPresenter->present($order_return);
|
||||
}
|
||||
|
||||
return $orders_returns;
|
||||
}
|
||||
|
||||
public function getBreadcrumbLinks()
|
||||
{
|
||||
$breadcrumb = parent::getBreadcrumbLinks();
|
||||
|
||||
$breadcrumb['links'][] = $this->addMyAccountToBreadcrumb();
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
}
|
||||
183
controllers/front/OrderReturnController.php
Normal file
183
controllers/front/OrderReturnController.php
Normal file
@@ -0,0 +1,183 @@
|
||||
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
use PrestaShop\PrestaShop\Adapter\Image\ImageRetriever;
|
||||
use PrestaShop\PrestaShop\Adapter\Presenter\Order\OrderReturnPresenter;
|
||||
|
||||
class OrderReturnControllerCore extends FrontController
|
||||
{
|
||||
public $auth = true;
|
||||
public $php_self = 'order-return';
|
||||
public $authRedirection = 'order-follow';
|
||||
public $ssl = true;
|
||||
|
||||
/**
|
||||
* Initialize order return controller.
|
||||
*
|
||||
* @see FrontController::init()
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
|
||||
$id_order_return = (int) Tools::getValue('id_order_return');
|
||||
|
||||
if (!isset($id_order_return) || !Validate::isUnsignedId($id_order_return)) {
|
||||
$this->redirect_after = '404';
|
||||
$this->redirect();
|
||||
} else {
|
||||
$order_return = new OrderReturn((int) $id_order_return);
|
||||
if (Validate::isLoadedObject($order_return) && $order_return->id_customer == $this->context->cookie->id_customer) {
|
||||
$order = new Order((int) ($order_return->id_order));
|
||||
if (Validate::isLoadedObject($order)) {
|
||||
if ($order_return->state == 1) {
|
||||
$this->warning[] = $this->trans('You must wait for confirmation before returning any merchandise.', [], 'Shop.Notifications.Warning');
|
||||
}
|
||||
|
||||
// StarterTheme: Use presenters!
|
||||
$this->context->smarty->assign([
|
||||
'return' => $this->getTemplateVarOrderReturn($order_return),
|
||||
'products' => $this->getTemplateVarProducts((int) $order_return->id, $order),
|
||||
]);
|
||||
} else {
|
||||
$this->redirect_after = '404';
|
||||
$this->redirect();
|
||||
}
|
||||
} else {
|
||||
$this->redirect_after = '404';
|
||||
$this->redirect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign template vars related to page content.
|
||||
*
|
||||
* @see FrontController::initContent()
|
||||
*/
|
||||
public function initContent()
|
||||
{
|
||||
if (Configuration::isCatalogMode()) {
|
||||
Tools::redirect('index.php');
|
||||
}
|
||||
|
||||
parent::initContent();
|
||||
$this->setTemplate('customer/order-return');
|
||||
}
|
||||
|
||||
public function getTemplateVarOrderReturn($orderReturn)
|
||||
{
|
||||
$orderReturns = OrderReturn::getOrdersReturn($orderReturn->id_customer, $orderReturn->id_order);
|
||||
foreach ($orderReturns as $return) {
|
||||
if ($orderReturn->id_order == $return['id_order']) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$orderReturnPresenter = new OrderReturnPresenter(
|
||||
Configuration::get('PS_RETURN_PREFIX', $this->context->language->id),
|
||||
$this->context->link
|
||||
);
|
||||
|
||||
return $orderReturnPresenter->present($return);
|
||||
}
|
||||
|
||||
public function getTemplateVarProducts($order_return_id, $order)
|
||||
{
|
||||
$products = [];
|
||||
$return_products = OrderReturn::getOrdersReturnProducts((int) $order_return_id, $order);
|
||||
|
||||
foreach ($return_products as $id_return_product => $return_product) {
|
||||
if (!isset($return_product['deleted'])) {
|
||||
$products[$id_return_product] = $return_product;
|
||||
$products[$id_return_product]['customizations'] = ($return_product['customizedDatas']) ? $this->getTemplateVarCustomization($return_product) : [];
|
||||
}
|
||||
}
|
||||
|
||||
return $products;
|
||||
}
|
||||
|
||||
public function getTemplateVarCustomization(array $product)
|
||||
{
|
||||
$product_customizations = [];
|
||||
$imageRetriever = new ImageRetriever($this->context->link);
|
||||
|
||||
foreach ($product['customizedDatas'] as $byAddress) {
|
||||
foreach ($byAddress as $customization) {
|
||||
$presentedCustomization = [
|
||||
'quantity' => $customization['quantity'],
|
||||
'fields' => [],
|
||||
'id_customization' => null,
|
||||
];
|
||||
|
||||
foreach ($customization['datas'] as $byType) {
|
||||
$field = [];
|
||||
foreach ($byType as $data) {
|
||||
switch ($data['type']) {
|
||||
case Product::CUSTOMIZE_FILE:
|
||||
$field['type'] = 'image';
|
||||
$field['image'] = $imageRetriever->getCustomizationImage(
|
||||
$data['value']
|
||||
);
|
||||
|
||||
break;
|
||||
case Product::CUSTOMIZE_TEXTFIELD:
|
||||
$field['type'] = 'text';
|
||||
$field['text'] = $data['value'];
|
||||
|
||||
break;
|
||||
default:
|
||||
$field['type'] = null;
|
||||
}
|
||||
$field['label'] = $data['name'];
|
||||
$field['id_module'] = $data['id_module'];
|
||||
$presentedCustomization['id_customization'] = $data['id_customization'];
|
||||
}
|
||||
$presentedCustomization['fields'][] = $field;
|
||||
}
|
||||
|
||||
$product_customizations[] = $presentedCustomization;
|
||||
}
|
||||
}
|
||||
|
||||
return $product_customizations;
|
||||
}
|
||||
|
||||
public function getBreadcrumbLinks()
|
||||
{
|
||||
$breadcrumb = parent::getBreadcrumbLinks();
|
||||
|
||||
$breadcrumb['links'][] = $this->addMyAccountToBreadcrumb();
|
||||
|
||||
if (($id_order_return = (int) Tools::getValue('id_order_return')) && Validate::isUnsignedId($id_order_return)) {
|
||||
$breadcrumb['links'][] = [
|
||||
'title' => $this->trans('Merchandise returns', [], 'Shop.Theme.Global'),
|
||||
'url' => $this->context->link->getPageLink('order-follow'),
|
||||
];
|
||||
}
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
}
|
||||
90
controllers/front/OrderSlipController.php
Normal file
90
controllers/front/OrderSlipController.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
class OrderSlipControllerCore extends FrontController
|
||||
{
|
||||
public $auth = true;
|
||||
public $php_self = 'order-slip';
|
||||
public $authRedirection = 'order-slip';
|
||||
public $ssl = true;
|
||||
|
||||
/**
|
||||
* Assign template vars related to page content.
|
||||
*
|
||||
* @see FrontController::initContent()
|
||||
*/
|
||||
public function initContent()
|
||||
{
|
||||
if (Configuration::isCatalogMode()) {
|
||||
Tools::redirect('index.php');
|
||||
}
|
||||
|
||||
$credit_slips = $this->getTemplateVarCreditSlips();
|
||||
|
||||
if (count($credit_slips) <= 0) {
|
||||
$this->warning[] = $this->trans('You have not received any credit slips.', [], 'Shop.Notifications.Warning');
|
||||
}
|
||||
|
||||
$this->context->smarty->assign([
|
||||
'credit_slips' => $credit_slips,
|
||||
]);
|
||||
|
||||
parent::initContent();
|
||||
$this->setTemplate('customer/order-slip');
|
||||
}
|
||||
|
||||
public function getTemplateVarCreditSlips()
|
||||
{
|
||||
$credit_slips = [];
|
||||
$orders_slip = OrderSlip::getOrdersSlip(((int) $this->context->cookie->id_customer));
|
||||
|
||||
foreach ($orders_slip as $order_slip) {
|
||||
$order = new Order($order_slip['id_order']);
|
||||
$credit_slips[$order_slip['id_order_slip']] = $order_slip;
|
||||
$credit_slips[$order_slip['id_order_slip']]['credit_slip_number'] = $this->trans('#%id%', ['%id%' => $order_slip['id_order_slip']], 'Shop.Theme.Customeraccount');
|
||||
$credit_slips[$order_slip['id_order_slip']]['order_number'] = $this->trans('#%id%', ['%id%' => $order_slip['id_order']], 'Shop.Theme.Customeraccount');
|
||||
$credit_slips[$order_slip['id_order_slip']]['order_reference'] = $order->reference;
|
||||
$credit_slips[$order_slip['id_order_slip']]['credit_slip_date'] = Tools::displayDate($order_slip['date_add'], null, false);
|
||||
$credit_slips[$order_slip['id_order_slip']]['url'] = $this->context->link->getPageLink('pdf-order-slip', true, null, 'id_order_slip=' . (int) $order_slip['id_order_slip']);
|
||||
$credit_slips[$order_slip['id_order_slip']]['order_url_details'] = $this->context->link->getPageLink('order-detail', true, null, 'id_order=' . (int) $order_slip['id_order']);
|
||||
}
|
||||
|
||||
return $credit_slips;
|
||||
}
|
||||
|
||||
public function getBreadcrumbLinks()
|
||||
{
|
||||
$breadcrumb = parent::getBreadcrumbLinks();
|
||||
|
||||
$breadcrumb['links'][] = $this->addMyAccountToBreadcrumb();
|
||||
|
||||
$breadcrumb['links'][] = [
|
||||
'title' => $this->trans('Credit slips', [], 'Shop.Theme.Customeraccount'),
|
||||
'url' => $this->context->link->getPageLink('order-slip'),
|
||||
];
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
}
|
||||
63
controllers/front/PageNotFoundController.php
Normal file
63
controllers/front/PageNotFoundController.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
class PageNotFoundControllerCore extends FrontController
|
||||
{
|
||||
public $php_self = 'pagenotfound';
|
||||
public $page_name = 'pagenotfound';
|
||||
public $ssl = true;
|
||||
|
||||
/**
|
||||
* Assign template vars related to page content.
|
||||
*
|
||||
* @see FrontController::initContent()
|
||||
*/
|
||||
public function initContent()
|
||||
{
|
||||
header('HTTP/1.1 404 Not Found');
|
||||
header('Status: 404 Not Found');
|
||||
$this->context->cookie->disallowWriting();
|
||||
parent::initContent();
|
||||
$this->setTemplate('errors/404');
|
||||
}
|
||||
|
||||
protected function canonicalRedirection($canonical_url = '')
|
||||
{
|
||||
// 404 - no need to redirect to the canonical url
|
||||
}
|
||||
|
||||
protected function sslRedirection()
|
||||
{
|
||||
// 404 - no need to redirect
|
||||
}
|
||||
|
||||
public function getTemplateVarPage()
|
||||
{
|
||||
$page = parent::getTemplateVarPage();
|
||||
$page['title'] = $this->trans('The page you are looking for was not found.', [], 'Shop.Theme.Global');
|
||||
|
||||
return $page;
|
||||
}
|
||||
}
|
||||
291
controllers/front/PasswordController.php
Normal file
291
controllers/front/PasswordController.php
Normal file
@@ -0,0 +1,291 @@
|
||||
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
use PrestaShop\PrestaShop\Core\Util\InternationalizedDomainNameConverter;
|
||||
|
||||
class PasswordControllerCore extends FrontController
|
||||
{
|
||||
public $php_self = 'password';
|
||||
public $auth = false;
|
||||
public $ssl = true;
|
||||
|
||||
/**
|
||||
* @var InternationalizedDomainNameConverter
|
||||
*/
|
||||
private $IDNConverter;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->IDNConverter = new InternationalizedDomainNameConverter();
|
||||
}
|
||||
|
||||
/**
|
||||
* Start forms process.
|
||||
*
|
||||
* @see FrontController::postProcess()
|
||||
*/
|
||||
public function postProcess()
|
||||
{
|
||||
$this->setTemplate('customer/password-email');
|
||||
|
||||
if (Tools::isSubmit('email')) {
|
||||
$this->sendRenewPasswordLink();
|
||||
} elseif (Tools::getValue('token') && ($id_customer = (int) Tools::getValue('id_customer'))) {
|
||||
$this->changePassword();
|
||||
} elseif (Tools::getValue('token') || Tools::getValue('id_customer')) {
|
||||
$this->errors[] = $this->trans('We cannot regenerate your password with the data you\'ve submitted', [], 'Shop.Notifications.Error');
|
||||
}
|
||||
}
|
||||
|
||||
protected function sendRenewPasswordLink()
|
||||
{
|
||||
if (!($email = $this->IDNConverter->emailToUtf8(trim(Tools::getValue('email')))) || !Validate::isEmail($email)) {
|
||||
$this->errors[] = $this->trans('Invalid email address.', [], 'Shop.Notifications.Error');
|
||||
} else {
|
||||
$customer = new Customer();
|
||||
$customer->getByEmail($email);
|
||||
if (null === $customer->email) {
|
||||
$customer->email = Tools::getValue('email');
|
||||
}
|
||||
|
||||
if (!Validate::isLoadedObject($customer)) {
|
||||
$this->success[] = $this->trans(
|
||||
'If this email address has been registered in our shop, you will receive a link to reset your password at %email%.',
|
||||
['%email%' => $customer->email],
|
||||
'Shop.Notifications.Success'
|
||||
);
|
||||
$this->setTemplate('customer/password-infos');
|
||||
} elseif (!$customer->active) {
|
||||
$this->errors[] = $this->trans('You cannot regenerate the password for this account.', [], 'Shop.Notifications.Error');
|
||||
} elseif ((strtotime($customer->last_passwd_gen . '+' . ($minTime = (int) Configuration::get('PS_PASSWD_TIME_FRONT')) . ' minutes') - time()) > 0) {
|
||||
$this->errors[] = $this->trans('You can regenerate your password only every %d minute(s)', [(int) $minTime], 'Shop.Notifications.Error');
|
||||
} else {
|
||||
if (!$customer->hasRecentResetPasswordToken()) {
|
||||
$customer->stampResetPasswordToken();
|
||||
$customer->update();
|
||||
}
|
||||
|
||||
$mailParams = [
|
||||
'{email}' => $customer->email,
|
||||
'{lastname}' => $customer->lastname,
|
||||
'{firstname}' => $customer->firstname,
|
||||
'{url}' => $this->context->link->getPageLink('password', true, null, 'token=' . $customer->secure_key . '&id_customer=' . (int) $customer->id . '&reset_token=' . $customer->reset_password_token),
|
||||
];
|
||||
|
||||
if (
|
||||
Mail::Send(
|
||||
$this->context->language->id,
|
||||
'password_query',
|
||||
$this->trans(
|
||||
'Password query confirmation',
|
||||
[],
|
||||
'Emails.Subject'
|
||||
),
|
||||
$mailParams,
|
||||
$customer->email,
|
||||
$customer->firstname . ' ' . $customer->lastname
|
||||
)
|
||||
) {
|
||||
$this->success[] = $this->trans('If this email address has been registered in our shop, you will receive a link to reset your password at %email%.', ['%email%' => $customer->email], 'Shop.Notifications.Success');
|
||||
$this->setTemplate('customer/password-infos');
|
||||
} else {
|
||||
$this->errors[] = $this->trans('An error occurred while sending the email.', [], 'Shop.Notifications.Error');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function changePassword()
|
||||
{
|
||||
$token = Tools::getValue('token');
|
||||
$id_customer = (int) Tools::getValue('id_customer');
|
||||
$reset_token = Tools::getValue('reset_token');
|
||||
$email = Db::getInstance()->getValue(
|
||||
'SELECT `email` FROM ' . _DB_PREFIX_ . 'customer c WHERE c.`secure_key` = \'' . pSQL($token) . '\' AND c.id_customer = ' . $id_customer
|
||||
);
|
||||
if ($email) {
|
||||
$customer = new Customer();
|
||||
$customer->getByEmail($email);
|
||||
|
||||
if (!Validate::isLoadedObject($customer)) {
|
||||
$this->errors[] = $this->trans('Customer account not found', [], 'Shop.Notifications.Error');
|
||||
} elseif (!$customer->active) {
|
||||
$this->errors[] = $this->trans('You cannot regenerate the password for this account.', [], 'Shop.Notifications.Error');
|
||||
} elseif ($customer->getValidResetPasswordToken() !== $reset_token) {
|
||||
$this->errors[] = $this->trans('The password change request expired. You should ask for a new one.', [], 'Shop.Notifications.Error');
|
||||
}
|
||||
|
||||
if ($this->errors) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($isSubmit = Tools::isSubmit('passwd')) {
|
||||
// If password is submitted validate pass and confirmation
|
||||
if (!$passwd = Tools::getValue('passwd')) {
|
||||
$this->errors[] = $this->trans('The password is missing: please enter your new password.', [], 'Shop.Notifications.Error');
|
||||
}
|
||||
|
||||
if (!$confirmation = Tools::getValue('confirmation')) {
|
||||
$this->errors[] = $this->trans('The confirmation is empty: please fill in the password confirmation as well', [], 'Shop.Notifications.Error');
|
||||
}
|
||||
|
||||
if ($passwd && $confirmation) {
|
||||
if ($passwd !== $confirmation) {
|
||||
$this->errors[] = $this->trans('The password and its confirmation do not match.', [], 'Shop.Notifications.Error');
|
||||
}
|
||||
|
||||
if (!Validate::isPasswd($passwd)) {
|
||||
$this->errors[] = $this->trans('The password is not in a valid format.', [], 'Shop.Notifications.Error');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$isSubmit || $this->errors) {
|
||||
// If password is NOT submitted OR there are errors, shows the form (and errors)
|
||||
$this->context->smarty->assign([
|
||||
'customer_email' => $customer->email,
|
||||
'customer_token' => $token,
|
||||
'id_customer' => $id_customer,
|
||||
'reset_token' => $reset_token,
|
||||
]);
|
||||
|
||||
$this->setTemplate('customer/password-new');
|
||||
} else {
|
||||
// Both password fields posted. Check if all is right and store new password properly.
|
||||
if (!$reset_token || (strtotime($customer->last_passwd_gen . '+' . (int) Configuration::get('PS_PASSWD_TIME_FRONT') . ' minutes') - time()) > 0) {
|
||||
Tools::redirect('index.php?controller=authentication&error_regen_pwd');
|
||||
} else {
|
||||
$customer->passwd = $this->get('hashing')->hash($password = Tools::getValue('passwd'), _COOKIE_KEY_);
|
||||
$customer->last_passwd_gen = date('Y-m-d H:i:s', time());
|
||||
|
||||
if ($customer->update()) {
|
||||
Hook::exec('actionPasswordRenew', ['customer' => $customer, 'password' => $password]);
|
||||
$customer->removeResetPasswordToken();
|
||||
$customer->update();
|
||||
|
||||
$mail_params = [
|
||||
'{email}' => $customer->email,
|
||||
'{lastname}' => $customer->lastname,
|
||||
'{firstname}' => $customer->firstname,
|
||||
];
|
||||
|
||||
if (
|
||||
Mail::Send(
|
||||
$this->context->language->id,
|
||||
'password',
|
||||
$this->trans(
|
||||
'Your new password',
|
||||
[],
|
||||
'Emails.Subject'
|
||||
),
|
||||
$mail_params,
|
||||
$customer->email,
|
||||
$customer->firstname . ' ' . $customer->lastname
|
||||
)
|
||||
) {
|
||||
$this->context->smarty->assign([
|
||||
'customer_email' => $customer->email,
|
||||
]);
|
||||
$this->success[] = $this->trans('Your password has been successfully reset and a confirmation has been sent to your email address: %s', [$customer->email], 'Shop.Notifications.Success');
|
||||
$this->context->updateCustomer($customer);
|
||||
$this->redirectWithNotifications('index.php?controller=my-account');
|
||||
} else {
|
||||
$this->errors[] = $this->trans('An error occurred while sending the email.', [], 'Shop.Notifications.Error');
|
||||
}
|
||||
} else {
|
||||
$this->errors[] = $this->trans('An error occurred with your account, which prevents us from updating the new password. Please report this issue using the contact form.', [], 'Shop.Notifications.Error');
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->errors[] = $this->trans('We cannot regenerate your password with the data you\'ve submitted', [], 'Shop.Notifications.Error');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function display()
|
||||
{
|
||||
$this->context->smarty->assign(
|
||||
[
|
||||
'layout' => $this->getLayout(),
|
||||
'stylesheets' => $this->getStylesheets(),
|
||||
'javascript' => $this->getJavascript(),
|
||||
'js_custom_vars' => Media::getJsDef(),
|
||||
'errors' => $this->getErrors(),
|
||||
'successes' => $this->getSuccesses(),
|
||||
]
|
||||
);
|
||||
|
||||
$this->smartyOutputContent($this->template);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function getErrors()
|
||||
{
|
||||
$notifications = $this->prepareNotifications();
|
||||
|
||||
$errors = [];
|
||||
if (array_key_exists('error', $notifications)) {
|
||||
$errors = $notifications['error'];
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function getSuccesses()
|
||||
{
|
||||
$notifications = $this->prepareNotifications();
|
||||
|
||||
$successes = [];
|
||||
|
||||
if (array_key_exists('success', $notifications)) {
|
||||
$successes = $notifications['success'];
|
||||
}
|
||||
|
||||
return $successes;
|
||||
}
|
||||
|
||||
public function getBreadcrumbLinks()
|
||||
{
|
||||
$breadcrumb = parent::getBreadcrumbLinks();
|
||||
|
||||
$breadcrumb['links'][] = [
|
||||
'title' => $this->trans('Reset your password', [], 'Shop.Theme.Customeraccount'),
|
||||
'url' => $this->context->link->getPageLink('password'),
|
||||
];
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
}
|
||||
75
controllers/front/PdfInvoiceController.php
Normal file
75
controllers/front/PdfInvoiceController.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
class PdfInvoiceControllerCore extends FrontController
|
||||
{
|
||||
public $php_self = 'pdf-invoice';
|
||||
protected $display_header = false;
|
||||
protected $display_footer = false;
|
||||
|
||||
public $content_only = true;
|
||||
|
||||
protected $template;
|
||||
public $filename;
|
||||
|
||||
public function postProcess()
|
||||
{
|
||||
if (!$this->context->customer->isLogged() && !Tools::getValue('secure_key')) {
|
||||
Tools::redirect('index.php?controller=authentication&back=pdf-invoice');
|
||||
}
|
||||
|
||||
if (!(int) Configuration::get('PS_INVOICE')) {
|
||||
die($this->trans('Invoices are disabled in this shop.', [], 'Shop.Notifications.Error'));
|
||||
}
|
||||
|
||||
$id_order = (int) Tools::getValue('id_order');
|
||||
if (Validate::isUnsignedId($id_order)) {
|
||||
$order = new Order((int) $id_order);
|
||||
}
|
||||
|
||||
if (!isset($order) || !Validate::isLoadedObject($order)) {
|
||||
die($this->trans('The invoice was not found.', [], 'Shop.Notifications.Error'));
|
||||
}
|
||||
|
||||
if ((isset($this->context->customer->id) && $order->id_customer != $this->context->customer->id) || (Tools::isSubmit('secure_key') && $order->secure_key != Tools::getValue('secure_key'))) {
|
||||
die($this->trans('The invoice was not found.', [], 'Shop.Notifications.Error'));
|
||||
}
|
||||
|
||||
if (!OrderState::invoiceAvailable($order->getCurrentState()) && !$order->invoice_number) {
|
||||
die($this->trans('No invoice is available.', [], 'Shop.Notifications.Error'));
|
||||
}
|
||||
|
||||
$this->order = $order;
|
||||
}
|
||||
|
||||
public function display()
|
||||
{
|
||||
$order_invoice_list = $this->order->getInvoicesCollection();
|
||||
Hook::exec('actionPDFInvoiceRender', ['order_invoice_list' => $order_invoice_list]);
|
||||
|
||||
$pdf = new PDF($order_invoice_list, PDF::TEMPLATE_INVOICE, $this->context->smarty);
|
||||
$pdf->render();
|
||||
}
|
||||
}
|
||||
58
controllers/front/PdfOrderReturnController.php
Normal file
58
controllers/front/PdfOrderReturnController.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
class PdfOrderReturnControllerCore extends FrontController
|
||||
{
|
||||
public $php_self = 'pdf-order-return';
|
||||
protected $display_header = false;
|
||||
protected $display_footer = false;
|
||||
|
||||
public function postProcess()
|
||||
{
|
||||
$from_admin = (Tools::getValue('adtoken') == Tools::getAdminToken('AdminReturn' . (int) Tab::getIdFromClassName('AdminReturn') . (int) Tools::getValue('id_employee')));
|
||||
|
||||
if (!$from_admin && !$this->context->customer->isLogged()) {
|
||||
Tools::redirect('index.php?controller=authentication&back=order-follow');
|
||||
}
|
||||
|
||||
if (Tools::getValue('id_order_return') && Validate::isUnsignedId(Tools::getValue('id_order_return'))) {
|
||||
$this->orderReturn = new OrderReturn(Tools::getValue('id_order_return'));
|
||||
}
|
||||
|
||||
if (!isset($this->orderReturn) || !Validate::isLoadedObject($this->orderReturn)) {
|
||||
die($this->trans('Order return not found.', [], 'Shop.Notifications.Error'));
|
||||
} elseif (!$from_admin && $this->orderReturn->id_customer != $this->context->customer->id) {
|
||||
die($this->trans('Order return not found.', [], 'Shop.Notifications.Error'));
|
||||
} elseif ($this->orderReturn->state < 2) {
|
||||
die($this->trans('Order return not confirmed.', [], 'Shop.Notifications.Error'));
|
||||
}
|
||||
}
|
||||
|
||||
public function display()
|
||||
{
|
||||
$pdf = new PDF($this->orderReturn, PDF::TEMPLATE_ORDER_RETURN, $this->context->smarty);
|
||||
$pdf->render();
|
||||
}
|
||||
}
|
||||
56
controllers/front/PdfOrderSlipController.php
Normal file
56
controllers/front/PdfOrderSlipController.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
class PdfOrderSlipControllerCore extends FrontController
|
||||
{
|
||||
public $php_self = 'pdf-order-slip';
|
||||
protected $display_header = false;
|
||||
protected $display_footer = false;
|
||||
|
||||
protected $order_slip;
|
||||
|
||||
public function postProcess()
|
||||
{
|
||||
if (!$this->context->customer->isLogged()) {
|
||||
Tools::redirect('index.php?controller=authentication&back=order-follow');
|
||||
}
|
||||
|
||||
if (isset($_GET['id_order_slip']) && Validate::isUnsignedId($_GET['id_order_slip'])) {
|
||||
$this->order_slip = new OrderSlip($_GET['id_order_slip']);
|
||||
}
|
||||
|
||||
if (!isset($this->order_slip) || !Validate::isLoadedObject($this->order_slip)) {
|
||||
die($this->trans('Order return not found.', [], 'Shop.Notifications.Error'));
|
||||
} elseif ($this->order_slip->id_customer != $this->context->customer->id) {
|
||||
die($this->trans('Order return not found.', [], 'Shop.Notifications.Error'));
|
||||
}
|
||||
}
|
||||
|
||||
public function display()
|
||||
{
|
||||
$pdf = new PDF($this->order_slip, PDF::TEMPLATE_ORDER_SLIP, $this->context->smarty);
|
||||
$pdf->render();
|
||||
}
|
||||
}
|
||||
1349
controllers/front/ProductController.php
Normal file
1349
controllers/front/ProductController.php
Normal file
File diff suppressed because it is too large
Load Diff
189
controllers/front/SitemapController.php
Normal file
189
controllers/front/SitemapController.php
Normal file
@@ -0,0 +1,189 @@
|
||||
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
class SitemapControllerCore extends FrontController
|
||||
{
|
||||
public $php_self = 'sitemap';
|
||||
|
||||
/**
|
||||
* Assign template vars related to page content.
|
||||
*
|
||||
* @see FrontController::initContent()
|
||||
*/
|
||||
public function initContent()
|
||||
{
|
||||
$this->context->smarty->assign(
|
||||
[
|
||||
'our_offers' => $this->trans('Our Offers', [], 'Shop.Theme.Global'),
|
||||
'categories' => $this->trans('Categories', [], 'Shop.Theme.Catalog'),
|
||||
'your_account' => $this->trans('Your account', [], 'Shop.Theme.Customeraccount'),
|
||||
'pages' => $this->trans('Pages', [], 'Shop.Theme.Catalog'),
|
||||
'links' => [
|
||||
'offers' => $this->getOffersLinks(),
|
||||
'pages' => $this->getPagesLinks(),
|
||||
'user_account' => $this->getUserAccountLinks(),
|
||||
'categories' => $this->getCategoriesLinks(),
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
parent::initContent();
|
||||
$this->setTemplate('cms/sitemap');
|
||||
}
|
||||
|
||||
public function getCategoriesLinks()
|
||||
{
|
||||
return [Category::getRootCategory()->recurseLiteCategTree(0, 0, null, null, 'sitemap')];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function getPagesLinks()
|
||||
{
|
||||
$cms = CMSCategory::getRecurseCategory($this->context->language->id, 1, 1, 1);
|
||||
$links = $this->getCmsTree($cms);
|
||||
|
||||
$links[] = [
|
||||
'id' => 'stores-page',
|
||||
'label' => $this->trans('Our stores', [], 'Shop.Theme.Global'),
|
||||
'url' => $this->context->link->getPageLink('stores'),
|
||||
];
|
||||
|
||||
$links[] = [
|
||||
'id' => 'contact-page',
|
||||
'label' => $this->trans('Contact us', [], 'Shop.Theme.Global'),
|
||||
'url' => $this->context->link->getPageLink('contact'),
|
||||
];
|
||||
|
||||
$links[] = [
|
||||
'id' => 'sitemap-page',
|
||||
'label' => $this->trans('Sitemap', [], 'Shop.Theme.Global'),
|
||||
'url' => $this->context->link->getPageLink('sitemap'),
|
||||
];
|
||||
|
||||
return $links;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function getCmsTree($cms)
|
||||
{
|
||||
$links = [];
|
||||
|
||||
foreach ($cms['cms'] as $p) {
|
||||
$links[] = [
|
||||
'id' => 'cms-page-' . $p['id_cms'],
|
||||
'label' => $p['meta_title'],
|
||||
'url' => $p['link'],
|
||||
];
|
||||
}
|
||||
|
||||
if (isset($cms['children'])) {
|
||||
foreach ($cms['children'] as $c) {
|
||||
$links[] = [
|
||||
'id' => 'cms-category-' . $c['id_cms_category'],
|
||||
'label' => $c['name'],
|
||||
'url' => $c['link'],
|
||||
'children' => $this->getCmsTree($c),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $links;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function getUserAccountLinks()
|
||||
{
|
||||
$links = [];
|
||||
|
||||
$links[] = [
|
||||
'id' => 'login-page',
|
||||
'label' => $this->trans('Log in', [], 'Shop.Theme.Global'),
|
||||
'url' => $this->context->link->getPageLink('authentication'),
|
||||
];
|
||||
|
||||
$links[] = [
|
||||
'id' => 'register-page',
|
||||
'label' => $this->trans('Create new account', [], 'Shop.Theme.Global'),
|
||||
'url' => $this->context->link->getPageLink('authentication', null, null, ['create_account' => 1]),
|
||||
];
|
||||
|
||||
return $links;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function getOffersLinks()
|
||||
{
|
||||
$links = [
|
||||
[
|
||||
'id' => 'new-product-page',
|
||||
'label' => $this->trans('New products', [], 'Shop.Theme.Catalog'),
|
||||
'url' => $this->context->link->getPageLink('new-products'),
|
||||
],
|
||||
];
|
||||
|
||||
if (Configuration::isCatalogMode() && Configuration::get('PS_DISPLAY_BEST_SELLERS')) {
|
||||
$links[] = [
|
||||
'id' => 'best-sales-page',
|
||||
'label' => $this->trans('Best sellers', [], 'Shop.Theme.Catalog'),
|
||||
'url' => $this->context->link->getPageLink('best-sales'),
|
||||
];
|
||||
$links[] = [
|
||||
'id' => 'prices-drop-page',
|
||||
'label' => $this->trans('Price drop', [], 'Shop.Theme.Catalog'),
|
||||
'url' => $this->context->link->getPageLink('prices-drop'),
|
||||
];
|
||||
}
|
||||
|
||||
if (Configuration::get('PS_DISPLAY_MANUFACTURERS')) {
|
||||
$manufacturers = Manufacturer::getLiteManufacturersList($this->context->language->id, 'sitemap');
|
||||
$links[] = [
|
||||
'id' => 'manufacturer-page',
|
||||
'label' => $this->trans('Brands', [], 'Shop.Theme.Catalog'),
|
||||
'url' => $this->context->link->getPageLink('manufacturer'),
|
||||
'children' => $manufacturers,
|
||||
];
|
||||
}
|
||||
|
||||
if (Configuration::get('PS_DISPLAY_SUPPLIERS')) {
|
||||
$suppliers = Supplier::getLiteSuppliersList($this->context->language->id, 'sitemap');
|
||||
$links[] = [
|
||||
'id' => 'supplier-page',
|
||||
'label' => $this->trans('Suppliers', [], 'Shop.Theme.Catalog'),
|
||||
'url' => $this->context->link->getPageLink('supplier'),
|
||||
'children' => $suppliers,
|
||||
];
|
||||
}
|
||||
|
||||
return $links;
|
||||
}
|
||||
}
|
||||
93
controllers/front/StatisticsController.php
Normal file
93
controllers/front/StatisticsController.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
class StatisticsControllerCore extends FrontController
|
||||
{
|
||||
public $display_header = false;
|
||||
public $display_footer = false;
|
||||
|
||||
protected $param_token;
|
||||
|
||||
public function postProcess()
|
||||
{
|
||||
$this->param_token = Tools::getValue('token');
|
||||
if (!$this->param_token) {
|
||||
die;
|
||||
}
|
||||
|
||||
if ($_POST['type'] == 'navinfo') {
|
||||
$this->processNavigationStats();
|
||||
} elseif ($_POST['type'] == 'pagetime') {
|
||||
$this->processPageTime();
|
||||
} else {
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log statistics on navigation (resolution, plugins, etc.).
|
||||
*/
|
||||
protected function processNavigationStats()
|
||||
{
|
||||
$id_guest = (int) Tools::getValue('id_guest');
|
||||
if (sha1($id_guest . _COOKIE_KEY_) != $this->param_token) {
|
||||
die;
|
||||
}
|
||||
|
||||
$guest = new Guest((int) substr($_POST['id_guest'], 0, 10));
|
||||
$guest->javascript = true;
|
||||
$guest->screen_resolution_x = (int) substr($_POST['screen_resolution_x'], 0, 5);
|
||||
$guest->screen_resolution_y = (int) substr($_POST['screen_resolution_y'], 0, 5);
|
||||
$guest->screen_color = (int) substr($_POST['screen_color'], 0, 3);
|
||||
$guest->sun_java = (int) substr($_POST['sun_java'], 0, 1);
|
||||
$guest->adobe_flash = (int) substr($_POST['adobe_flash'], 0, 1);
|
||||
$guest->adobe_director = (int) substr($_POST['adobe_director'], 0, 1);
|
||||
$guest->apple_quicktime = (int) substr($_POST['apple_quicktime'], 0, 1);
|
||||
$guest->real_player = (int) substr($_POST['real_player'], 0, 1);
|
||||
$guest->windows_media = (int) substr($_POST['windows_media'], 0, 1);
|
||||
$guest->update();
|
||||
}
|
||||
|
||||
/**
|
||||
* Log statistics on time spend on pages.
|
||||
*/
|
||||
protected function processPageTime()
|
||||
{
|
||||
$id_connection = (int) Tools::getValue('id_connections');
|
||||
$time = (int) Tools::getValue('time');
|
||||
$time_start = Tools::getValue('time_start');
|
||||
$id_page = (int) Tools::getValue('id_page');
|
||||
|
||||
if (sha1($id_connection . $id_page . $time_start . _COOKIE_KEY_) != $this->param_token) {
|
||||
die;
|
||||
}
|
||||
|
||||
if ($time <= 0) {
|
||||
die;
|
||||
}
|
||||
|
||||
Connection::setPageTime($id_connection, $id_page, substr($time_start, 0, 19), $time);
|
||||
}
|
||||
}
|
||||
236
controllers/front/StoresController.php
Normal file
236
controllers/front/StoresController.php
Normal file
@@ -0,0 +1,236 @@
|
||||
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
class StoresControllerCore extends FrontController
|
||||
{
|
||||
public $php_self = 'stores';
|
||||
|
||||
/**
|
||||
* Initialize stores controller.
|
||||
*
|
||||
* @see FrontController::init()
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
|
||||
// StarterTheme: Remove check when google maps v3 is done
|
||||
if (!extension_loaded('Dom')) {
|
||||
$this->errors[] = $this->trans('PHP "Dom" extension has not been loaded.', [], 'Shop.Notifications.Error');
|
||||
$this->context->smarty->assign('errors', $this->errors);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get formatted string address.
|
||||
*
|
||||
* @param array $store
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function processStoreAddress($store)
|
||||
{
|
||||
// StarterTheme: Remove method when google maps v3 is done
|
||||
$ignore_field = [
|
||||
'firstname',
|
||||
'lastname',
|
||||
];
|
||||
|
||||
$out_datas = [];
|
||||
|
||||
$address_datas = AddressFormat::getOrderedAddressFields($store['id_country'], false, true);
|
||||
$state = (isset($store['id_state'])) ? new State($store['id_state']) : null;
|
||||
|
||||
foreach ($address_datas as $data_line) {
|
||||
$data_fields = explode(' ', $data_line);
|
||||
$addr_out = [];
|
||||
|
||||
$data_fields_mod = false;
|
||||
foreach ($data_fields as $field_item) {
|
||||
$field_item = trim($field_item);
|
||||
if (!in_array($field_item, $ignore_field) && !empty($store[$field_item])) {
|
||||
$addr_out[] = ($field_item == 'city' && $state && isset($state->iso_code) && strlen($state->iso_code)) ?
|
||||
$store[$field_item] . ', ' . $state->iso_code : $store[$field_item];
|
||||
$data_fields_mod = true;
|
||||
}
|
||||
}
|
||||
if ($data_fields_mod) {
|
||||
$out_datas[] = implode(' ', $addr_out);
|
||||
}
|
||||
}
|
||||
|
||||
$out = implode('<br />', $out_datas);
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
public function getStoresForXml()
|
||||
{
|
||||
// StarterTheme: Remove method when google maps v3 is done
|
||||
$distance_unit = Configuration::get('PS_DISTANCE_UNIT');
|
||||
if (!in_array($distance_unit, ['km', 'mi'])) {
|
||||
$distance_unit = 'km';
|
||||
}
|
||||
|
||||
$distance = (int) Tools::getValue('radius', 100);
|
||||
$multiplicator = ($distance_unit == 'km' ? 6371 : 3959);
|
||||
|
||||
$stores = Db::getInstance()->executeS('
|
||||
SELECT s.*, cl.name country, st.iso_code state,
|
||||
(' . (int) $multiplicator . '
|
||||
* acos(
|
||||
cos(radians(' . (float) Tools::getValue('latitude') . '))
|
||||
* cos(radians(latitude))
|
||||
* cos(radians(longitude) - radians(' . (float) Tools::getValue('longitude') . '))
|
||||
+ sin(radians(' . (float) Tools::getValue('latitude') . '))
|
||||
* sin(radians(latitude))
|
||||
)
|
||||
) distance,
|
||||
cl.id_country id_country
|
||||
FROM ' . _DB_PREFIX_ . 'store s
|
||||
' . Shop::addSqlAssociation('store', 's') . '
|
||||
LEFT JOIN ' . _DB_PREFIX_ . 'country_lang cl ON (cl.id_country = s.id_country)
|
||||
LEFT JOIN ' . _DB_PREFIX_ . 'state st ON (st.id_state = s.id_state)
|
||||
WHERE s.active = 1 AND cl.id_lang = ' . (int) $this->context->language->id . '
|
||||
HAVING distance < ' . (int) $distance . '
|
||||
ORDER BY distance ASC
|
||||
LIMIT 0,20');
|
||||
|
||||
return $stores;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the Xml for showing the nodes in the google map.
|
||||
*/
|
||||
protected function displayAjax()
|
||||
{
|
||||
// StarterTheme: Remove method when google maps v3 is done
|
||||
$stores = $this->getStoresForXml();
|
||||
$parnode = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><markers></markers>');
|
||||
|
||||
foreach ($stores as $store) {
|
||||
$other = '';
|
||||
$newnode = $parnode->addChild('marker');
|
||||
$newnode->addAttribute('name', $store['name']);
|
||||
$address = $this->processStoreAddress($store);
|
||||
|
||||
//$other .= $this->renderStoreWorkingHours($store);
|
||||
$newnode->addAttribute('addressNoHtml', strip_tags(str_replace('<br />', ' ', $address)));
|
||||
$newnode->addAttribute('address', $address);
|
||||
$newnode->addAttribute('other', $other);
|
||||
$newnode->addAttribute('phone', $store['phone']);
|
||||
$newnode->addAttribute('id_store', (int) $store['id_store']);
|
||||
$newnode->addAttribute('has_store_picture', file_exists(_PS_STORE_IMG_DIR_ . (int) $store['id_store'] . '.jpg'));
|
||||
$newnode->addAttribute('lat', (float) $store['latitude']);
|
||||
$newnode->addAttribute('lng', (float) $store['longitude']);
|
||||
if (isset($store['distance'])) {
|
||||
$newnode->addAttribute('distance', (int) $store['distance']);
|
||||
}
|
||||
}
|
||||
|
||||
header('Content-type: text/xml');
|
||||
|
||||
$this->ajaxRender($parnode->asXML());
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign template vars related to page content.
|
||||
*
|
||||
* @see FrontController::initContent()
|
||||
*/
|
||||
public function initContent()
|
||||
{
|
||||
$distance_unit = Configuration::get('PS_DISTANCE_UNIT');
|
||||
if (!in_array($distance_unit, ['km', 'mi'])) {
|
||||
$distance_unit = 'km';
|
||||
}
|
||||
|
||||
$this->context->smarty->assign([
|
||||
'mediumSize' => Image::getSize(ImageType::getFormattedName('medium')),
|
||||
'searchUrl' => $this->context->link->getPageLink('stores'),
|
||||
'distance_unit' => $distance_unit,
|
||||
'stores' => $this->getTemplateVarStores(),
|
||||
]);
|
||||
|
||||
parent::initContent();
|
||||
$this->setTemplate('cms/stores');
|
||||
}
|
||||
|
||||
public function getTemplateVarStores()
|
||||
{
|
||||
$stores = Store::getStores($this->context->language->id);
|
||||
|
||||
$imageRetriever = new \PrestaShop\PrestaShop\Adapter\Image\ImageRetriever($this->context->link);
|
||||
|
||||
foreach ($stores as &$store) {
|
||||
unset($store['active']);
|
||||
// Prepare $store.address
|
||||
$address = new Address();
|
||||
$store['address'] = [];
|
||||
$attr = ['address1', 'address2', 'postcode', 'city', 'id_state', 'id_country'];
|
||||
foreach ($attr as $a) {
|
||||
$address->{$a} = $store[$a];
|
||||
$store['address'][$a] = $store[$a];
|
||||
unset($store[$a]);
|
||||
}
|
||||
$store['address']['formatted'] = AddressFormat::generateAddress($address, [], '<br />');
|
||||
|
||||
// Prepare $store.business_hours
|
||||
// Required for trad
|
||||
$temp = json_decode($store['hours'], true);
|
||||
unset($store['hours']);
|
||||
$store['business_hours'] = [
|
||||
[
|
||||
'day' => $this->trans('Monday', [], 'Shop.Theme.Global'),
|
||||
'hours' => $temp[0],
|
||||
], [
|
||||
'day' => $this->trans('Tuesday', [], 'Shop.Theme.Global'),
|
||||
'hours' => $temp[1],
|
||||
], [
|
||||
'day' => $this->trans('Wednesday', [], 'Shop.Theme.Global'),
|
||||
'hours' => $temp[2],
|
||||
], [
|
||||
'day' => $this->trans('Thursday', [], 'Shop.Theme.Global'),
|
||||
'hours' => $temp[3],
|
||||
], [
|
||||
'day' => $this->trans('Friday', [], 'Shop.Theme.Global'),
|
||||
'hours' => $temp[4],
|
||||
], [
|
||||
'day' => $this->trans('Saturday', [], 'Shop.Theme.Global'),
|
||||
'hours' => $temp[5],
|
||||
], [
|
||||
'day' => $this->trans('Sunday', [], 'Shop.Theme.Global'),
|
||||
'hours' => $temp[6],
|
||||
],
|
||||
];
|
||||
$store['image'] = $imageRetriever->getImage(new Store($store['id_store']), $store['id_store']);
|
||||
if (is_array($store['image'])) {
|
||||
$store['image']['legend'] = $store['image']['legend'][$this->context->language->id];
|
||||
}
|
||||
}
|
||||
|
||||
return $stores;
|
||||
}
|
||||
}
|
||||
34
controllers/front/index.php
Normal file
34
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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 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;
|
||||
93
controllers/front/listing/BestSalesController.php
Normal file
93
controllers/front/listing/BestSalesController.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
use PrestaShop\PrestaShop\Adapter\BestSales\BestSalesProductSearchProvider;
|
||||
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchQuery;
|
||||
use PrestaShop\PrestaShop\Core\Product\Search\SortOrder;
|
||||
|
||||
class BestSalesControllerCore extends ProductListingFrontController
|
||||
{
|
||||
public $php_self = 'best-sales';
|
||||
|
||||
/**
|
||||
* Initializes controller.
|
||||
*
|
||||
* @see FrontController::init()
|
||||
*
|
||||
* @throws PrestaShopException
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
if (Configuration::get('PS_DISPLAY_BEST_SELLERS')) {
|
||||
parent::init();
|
||||
} else {
|
||||
Tools::redirect('index.php?controller=404');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function initContent()
|
||||
{
|
||||
parent::initContent();
|
||||
|
||||
$this->doProductSearch('catalog/listing/best-sales');
|
||||
}
|
||||
|
||||
protected function getProductSearchQuery()
|
||||
{
|
||||
$query = new ProductSearchQuery();
|
||||
$query
|
||||
->setQueryType('best-sales')
|
||||
->setSortOrder(new SortOrder('product', 'name', 'asc'));
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
protected function getDefaultProductSearchProvider()
|
||||
{
|
||||
return new BestSalesProductSearchProvider(
|
||||
$this->getTranslator()
|
||||
);
|
||||
}
|
||||
|
||||
public function getListingLabel()
|
||||
{
|
||||
return $this->getTranslator()->trans('Best sellers', [], 'Shop.Theme.Catalog');
|
||||
}
|
||||
|
||||
public function getBreadcrumbLinks()
|
||||
{
|
||||
$breadcrumb = parent::getBreadcrumbLinks();
|
||||
|
||||
$breadcrumb['links'][] = [
|
||||
'title' => $this->trans('Best sellers', [], 'Shop.Theme.Catalog'),
|
||||
'url' => $this->context->link->getPageLink('best-sales', true),
|
||||
];
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
}
|
||||
275
controllers/front/listing/CategoryController.php
Normal file
275
controllers/front/listing/CategoryController.php
Normal file
@@ -0,0 +1,275 @@
|
||||
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
use PrestaShop\PrestaShop\Adapter\Category\CategoryProductSearchProvider;
|
||||
use PrestaShop\PrestaShop\Adapter\Image\ImageRetriever;
|
||||
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchQuery;
|
||||
use PrestaShop\PrestaShop\Core\Product\Search\SortOrder;
|
||||
|
||||
class CategoryControllerCore extends ProductListingFrontController
|
||||
{
|
||||
/** string Internal controller name */
|
||||
public $php_self = 'category';
|
||||
|
||||
/** @var bool If set to false, customer cannot view the current category. */
|
||||
public $customer_access = true;
|
||||
|
||||
/**
|
||||
* @var Category
|
||||
*/
|
||||
protected $category;
|
||||
|
||||
public function canonicalRedirection($canonicalURL = '')
|
||||
{
|
||||
if (Validate::isLoadedObject($this->category)) {
|
||||
parent::canonicalRedirection($this->context->link->getCategoryLink($this->category));
|
||||
} elseif ($canonicalURL) {
|
||||
parent::canonicalRedirection($canonicalURL);
|
||||
}
|
||||
}
|
||||
|
||||
public function getCanonicalURL()
|
||||
{
|
||||
$canonicalUrl = $this->context->link->getCategoryLink($this->category);
|
||||
$parsedUrl = parse_url($canonicalUrl);
|
||||
if (isset($parsedUrl['query'])) {
|
||||
parse_str($parsedUrl['query'], $params);
|
||||
} else {
|
||||
$params = [];
|
||||
}
|
||||
$page = (int) Tools::getValue('page');
|
||||
if ($page > 1) {
|
||||
$params['page'] = $page;
|
||||
} else {
|
||||
unset($params['page']);
|
||||
}
|
||||
$canonicalUrl = http_build_url($parsedUrl, ['query' => http_build_query($params)]);
|
||||
|
||||
return $canonicalUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes controller.
|
||||
*
|
||||
* @see FrontController::init()
|
||||
*
|
||||
* @throws PrestaShopException
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
$id_category = (int) Tools::getValue('id_category');
|
||||
$this->category = new Category(
|
||||
$id_category,
|
||||
$this->context->language->id
|
||||
);
|
||||
|
||||
if (!Validate::isLoadedObject($this->category) || !$this->category->active) {
|
||||
Tools::redirect('index.php?controller=404');
|
||||
}
|
||||
|
||||
parent::init();
|
||||
|
||||
if (!$this->category->checkAccess($this->context->customer->id)) {
|
||||
header('HTTP/1.1 403 Forbidden');
|
||||
header('Status: 403 Forbidden');
|
||||
$this->errors[] = $this->trans('You do not have access to this category.', [], 'Shop.Notifications.Error');
|
||||
$this->setTemplate('errors/forbidden');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$categoryVar = $this->getTemplateVarCategory();
|
||||
|
||||
$filteredCategory = Hook::exec(
|
||||
'filterCategoryContent',
|
||||
['object' => $categoryVar],
|
||||
$id_module = null,
|
||||
$array_return = false,
|
||||
$check_exceptions = true,
|
||||
$use_push = false,
|
||||
$id_shop = null,
|
||||
$chain = true
|
||||
);
|
||||
if (!empty($filteredCategory['object'])) {
|
||||
$categoryVar = $filteredCategory['object'];
|
||||
}
|
||||
|
||||
$this->context->smarty->assign([
|
||||
'category' => $categoryVar,
|
||||
'subcategories' => $this->getTemplateVarSubCategories(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function initContent()
|
||||
{
|
||||
parent::initContent();
|
||||
|
||||
if ($this->category->checkAccess($this->context->customer->id)) {
|
||||
$this->doProductSearch(
|
||||
'catalog/listing/category',
|
||||
[
|
||||
'entity' => 'category',
|
||||
'id' => $this->category->id,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* overrides layout if category is not visible.
|
||||
*
|
||||
* @return bool|string
|
||||
*/
|
||||
public function getLayout()
|
||||
{
|
||||
if (!$this->category->checkAccess($this->context->customer->id)) {
|
||||
return 'layouts/layout-full-width.tpl';
|
||||
}
|
||||
|
||||
return parent::getLayout();
|
||||
}
|
||||
|
||||
protected function getAjaxProductSearchVariables()
|
||||
{
|
||||
$data = parent::getAjaxProductSearchVariables();
|
||||
$rendered_products_header = $this->render('catalog/_partials/category-header', ['listing' => $data]);
|
||||
$data['rendered_products_header'] = $rendered_products_header;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function getProductSearchQuery()
|
||||
{
|
||||
$query = new ProductSearchQuery();
|
||||
$query
|
||||
->setIdCategory($this->category->id)
|
||||
->setSortOrder(new SortOrder('product', Tools::getProductsOrder('by'), Tools::getProductsOrder('way')));
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
protected function getDefaultProductSearchProvider()
|
||||
{
|
||||
return new CategoryProductSearchProvider(
|
||||
$this->getTranslator(),
|
||||
$this->category
|
||||
);
|
||||
}
|
||||
|
||||
protected function getTemplateVarCategory()
|
||||
{
|
||||
$category = $this->objectPresenter->present($this->category);
|
||||
$category['image'] = $this->getImage(
|
||||
$this->category,
|
||||
$this->category->id_image
|
||||
);
|
||||
|
||||
return $category;
|
||||
}
|
||||
|
||||
protected function getTemplateVarSubCategories()
|
||||
{
|
||||
return array_map(function (array $category) {
|
||||
$object = new Category(
|
||||
$category['id_category'],
|
||||
$this->context->language->id
|
||||
);
|
||||
|
||||
$category['image'] = $this->getImage(
|
||||
$object,
|
||||
$object->id_image
|
||||
);
|
||||
|
||||
$category['url'] = $this->context->link->getCategoryLink(
|
||||
$category['id_category'],
|
||||
$category['link_rewrite']
|
||||
);
|
||||
|
||||
return $category;
|
||||
}, $this->category->getSubCategories($this->context->language->id));
|
||||
}
|
||||
|
||||
protected function getImage($object, $id_image)
|
||||
{
|
||||
$retriever = new ImageRetriever(
|
||||
$this->context->link
|
||||
);
|
||||
|
||||
return $retriever->getImage($object, $id_image);
|
||||
}
|
||||
|
||||
public function getBreadcrumbLinks()
|
||||
{
|
||||
$breadcrumb = parent::getBreadcrumbLinks();
|
||||
|
||||
foreach ($this->category->getAllParents() as $category) {
|
||||
if ($category->id_parent != 0 && !$category->is_root_category) {
|
||||
$breadcrumb['links'][] = $this->getCategoryPath($category);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->category->id_parent != 0 && !$this->category->is_root_category) {
|
||||
$breadcrumb['links'][] = $this->getCategoryPath($this->category);
|
||||
}
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
|
||||
public function getCategory()
|
||||
{
|
||||
return $this->category;
|
||||
}
|
||||
|
||||
public function getTemplateVarPage()
|
||||
{
|
||||
$page = parent::getTemplateVarPage();
|
||||
|
||||
$page['body_classes']['category-id-' . $this->category->id] = true;
|
||||
$page['body_classes']['category-' . $this->category->name] = true;
|
||||
$page['body_classes']['category-id-parent-' . $this->category->id_parent] = true;
|
||||
$page['body_classes']['category-depth-level-' . $this->category->level_depth] = true;
|
||||
|
||||
return $page;
|
||||
}
|
||||
|
||||
public function getListingLabel()
|
||||
{
|
||||
if (!Validate::isLoadedObject($this->category)) {
|
||||
$this->category = new Category(
|
||||
(int) Tools::getValue('id_category'),
|
||||
$this->context->language->id
|
||||
);
|
||||
}
|
||||
|
||||
return $this->trans(
|
||||
'Category: %category_name%',
|
||||
['%category_name%' => $this->category->name],
|
||||
'Shop.Theme.Catalog'
|
||||
);
|
||||
}
|
||||
}
|
||||
217
controllers/front/listing/ManufacturerController.php
Normal file
217
controllers/front/listing/ManufacturerController.php
Normal file
@@ -0,0 +1,217 @@
|
||||
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
use PrestaShop\PrestaShop\Adapter\Manufacturer\ManufacturerProductSearchProvider;
|
||||
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchQuery;
|
||||
use PrestaShop\PrestaShop\Core\Product\Search\SortOrder;
|
||||
|
||||
class ManufacturerControllerCore extends ProductListingFrontController
|
||||
{
|
||||
public $php_self = 'manufacturer';
|
||||
|
||||
protected $manufacturer;
|
||||
protected $label;
|
||||
|
||||
public function canonicalRedirection($canonicalURL = '')
|
||||
{
|
||||
if (Validate::isLoadedObject($this->manufacturer)) {
|
||||
parent::canonicalRedirection($this->context->link->getManufacturerLink($this->manufacturer));
|
||||
} elseif ($canonicalURL) {
|
||||
parent::canonicalRedirection($canonicalURL);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize manufaturer controller.
|
||||
*
|
||||
* @see FrontController::init()
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
if ($id_manufacturer = Tools::getValue('id_manufacturer')) {
|
||||
$this->manufacturer = new Manufacturer((int) $id_manufacturer, $this->context->language->id);
|
||||
|
||||
if (!Validate::isLoadedObject($this->manufacturer) || !$this->manufacturer->active || !$this->manufacturer->isAssociatedToShop()) {
|
||||
$this->redirect_after = '404';
|
||||
$this->redirect();
|
||||
} else {
|
||||
$this->canonicalRedirection();
|
||||
}
|
||||
}
|
||||
|
||||
parent::init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign template vars related to page content.
|
||||
*
|
||||
* @see FrontController::initContent()
|
||||
*/
|
||||
public function initContent()
|
||||
{
|
||||
if (Configuration::get('PS_DISPLAY_MANUFACTURERS')) {
|
||||
parent::initContent();
|
||||
|
||||
if (Validate::isLoadedObject($this->manufacturer) && $this->manufacturer->active && $this->manufacturer->isAssociatedToShop()) {
|
||||
$this->assignManufacturer();
|
||||
$this->label = $this->trans(
|
||||
'List of products by brand %brand_name%',
|
||||
[
|
||||
'%brand_name%' => $this->manufacturer->name,
|
||||
],
|
||||
'Shop.Theme.Catalog'
|
||||
);
|
||||
$this->doProductSearch(
|
||||
'catalog/listing/manufacturer',
|
||||
['entity' => 'manufacturer', 'id' => $this->manufacturer->id]
|
||||
);
|
||||
} else {
|
||||
$this->assignAll();
|
||||
$this->label = $this->trans(
|
||||
'List of all brands',
|
||||
[],
|
||||
'Shop.Theme.Catalog'
|
||||
);
|
||||
$this->setTemplate('catalog/manufacturers', ['entity' => 'manufacturers']);
|
||||
}
|
||||
} else {
|
||||
$this->redirect_after = '404';
|
||||
$this->redirect();
|
||||
}
|
||||
}
|
||||
|
||||
protected function getProductSearchQuery()
|
||||
{
|
||||
$query = new ProductSearchQuery();
|
||||
$query
|
||||
->setIdManufacturer($this->manufacturer->id)
|
||||
->setSortOrder(new SortOrder('product', Tools::getProductsOrder('by'), Tools::getProductsOrder('way')));
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
protected function getDefaultProductSearchProvider()
|
||||
{
|
||||
return new ManufacturerProductSearchProvider(
|
||||
$this->getTranslator(),
|
||||
$this->manufacturer
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign template vars if displaying one manufacturer.
|
||||
*/
|
||||
protected function assignManufacturer()
|
||||
{
|
||||
$manufacturerVar = $this->objectPresenter->present($this->manufacturer);
|
||||
|
||||
$filteredManufacturer = Hook::exec(
|
||||
'filterManufacturerContent',
|
||||
['filtered_content' => $manufacturerVar['description']],
|
||||
$id_module = null,
|
||||
$array_return = false,
|
||||
$check_exceptions = true,
|
||||
$use_push = false,
|
||||
$id_shop = null,
|
||||
$chain = true
|
||||
);
|
||||
if (!empty($filteredManufacturer)) {
|
||||
$manufacturerVar['description'] = $filteredManufacturer;
|
||||
}
|
||||
|
||||
$this->context->smarty->assign([
|
||||
'manufacturer' => $manufacturerVar,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign template vars if displaying the manufacturer list.
|
||||
*/
|
||||
protected function assignAll()
|
||||
{
|
||||
$manufacturersVar = $this->getTemplateVarManufacturers();
|
||||
|
||||
if (!empty($manufacturersVar)) {
|
||||
foreach ($manufacturersVar as $k => $manufacturer) {
|
||||
$filteredManufacturer = Hook::exec(
|
||||
'filterManufacturerContent',
|
||||
['filtered_content' => $manufacturer['text']],
|
||||
$id_module = null,
|
||||
$array_return = false,
|
||||
$check_exceptions = true,
|
||||
$use_push = false,
|
||||
$id_shop = null,
|
||||
$chain = true
|
||||
);
|
||||
if (!empty($filteredManufacturer)) {
|
||||
$manufacturersVar[$k]['text'] = $filteredManufacturer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->context->smarty->assign([
|
||||
'brands' => $manufacturersVar,
|
||||
]);
|
||||
}
|
||||
|
||||
public function getTemplateVarManufacturers()
|
||||
{
|
||||
$manufacturers = Manufacturer::getManufacturers(true, $this->context->language->id, true, $this->p, $this->n, false);
|
||||
$manufacturers_for_display = [];
|
||||
|
||||
foreach ($manufacturers as $manufacturer) {
|
||||
$manufacturers_for_display[$manufacturer['id_manufacturer']] = $manufacturer;
|
||||
$manufacturers_for_display[$manufacturer['id_manufacturer']]['text'] = $manufacturer['short_description'];
|
||||
$manufacturers_for_display[$manufacturer['id_manufacturer']]['image'] = $this->context->link->getManufacturerImageLink($manufacturer['id_manufacturer'], 'small_default');
|
||||
$manufacturers_for_display[$manufacturer['id_manufacturer']]['url'] = $this->context->link->getmanufacturerLink($manufacturer['id_manufacturer']);
|
||||
$manufacturers_for_display[$manufacturer['id_manufacturer']]['nb_products'] = $manufacturer['nb_products'] > 1 ? ($this->trans('%number% products', ['%number%' => $manufacturer['nb_products']], 'Shop.Theme.Catalog')) : $this->trans('%number% product', ['%number%' => $manufacturer['nb_products']], 'Shop.Theme.Catalog');
|
||||
}
|
||||
|
||||
return $manufacturers_for_display;
|
||||
}
|
||||
|
||||
public function getListingLabel()
|
||||
{
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
public function getBreadcrumbLinks()
|
||||
{
|
||||
$breadcrumb = parent::getBreadcrumbLinks();
|
||||
$breadcrumb['links'][] = [
|
||||
'title' => $this->getTranslator()->trans('Brands', [], 'Shop.Theme.Global'),
|
||||
'url' => $this->context->link->getPageLink('manufacturer', true),
|
||||
];
|
||||
|
||||
if (Validate::isLoadedObject($this->manufacturer) && $this->manufacturer->active && $this->manufacturer->isAssociatedToShop()) {
|
||||
$breadcrumb['links'][] = [
|
||||
'title' => $this->manufacturer->name,
|
||||
'url' => $this->context->link->getManufacturerLink($this->manufacturer),
|
||||
];
|
||||
}
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
}
|
||||
81
controllers/front/listing/NewProductsController.php
Normal file
81
controllers/front/listing/NewProductsController.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
use PrestaShop\PrestaShop\Adapter\NewProducts\NewProductsProductSearchProvider;
|
||||
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchQuery;
|
||||
use PrestaShop\PrestaShop\Core\Product\Search\SortOrder;
|
||||
|
||||
class NewProductsControllerCore extends ProductListingFrontController
|
||||
{
|
||||
public $php_self = 'new-products';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function initContent()
|
||||
{
|
||||
parent::initContent();
|
||||
|
||||
$this->doProductSearch('catalog/listing/new-products');
|
||||
}
|
||||
|
||||
protected function getProductSearchQuery()
|
||||
{
|
||||
$query = new ProductSearchQuery();
|
||||
$query
|
||||
->setQueryType('new-products')
|
||||
->setSortOrder(new SortOrder('product', 'date_add', 'desc'));
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
protected function getDefaultProductSearchProvider()
|
||||
{
|
||||
return new NewProductsProductSearchProvider(
|
||||
$this->getTranslator()
|
||||
);
|
||||
}
|
||||
|
||||
public function getListingLabel()
|
||||
{
|
||||
return $this->trans(
|
||||
'New products',
|
||||
[],
|
||||
'Shop.Theme.Catalog'
|
||||
);
|
||||
}
|
||||
|
||||
public function getBreadcrumbLinks()
|
||||
{
|
||||
$breadcrumb = parent::getBreadcrumbLinks();
|
||||
|
||||
$breadcrumb['links'][] = [
|
||||
'title' => $this->trans('New products', [], 'Shop.Theme.Catalog'),
|
||||
'url' => $this->context->link->getPageLink('new-products', true),
|
||||
];
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
}
|
||||
81
controllers/front/listing/PricesDropController.php
Normal file
81
controllers/front/listing/PricesDropController.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
use PrestaShop\PrestaShop\Adapter\PricesDrop\PricesDropProductSearchProvider;
|
||||
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchQuery;
|
||||
use PrestaShop\PrestaShop\Core\Product\Search\SortOrder;
|
||||
|
||||
class PricesDropControllerCore extends ProductListingFrontController
|
||||
{
|
||||
public $php_self = 'prices-drop';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function initContent()
|
||||
{
|
||||
parent::initContent();
|
||||
|
||||
$this->doProductSearch('catalog/listing/prices-drop');
|
||||
}
|
||||
|
||||
protected function getProductSearchQuery()
|
||||
{
|
||||
$query = new ProductSearchQuery();
|
||||
$query
|
||||
->setQueryType('prices-drop')
|
||||
->setSortOrder(new SortOrder('product', 'name', 'asc'));
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
protected function getDefaultProductSearchProvider()
|
||||
{
|
||||
return new PricesDropProductSearchProvider(
|
||||
$this->getTranslator()
|
||||
);
|
||||
}
|
||||
|
||||
public function getListingLabel()
|
||||
{
|
||||
return $this->trans(
|
||||
'On sale',
|
||||
[],
|
||||
'Shop.Theme.Catalog'
|
||||
);
|
||||
}
|
||||
|
||||
public function getBreadcrumbLinks()
|
||||
{
|
||||
$breadcrumb = parent::getBreadcrumbLinks();
|
||||
|
||||
$breadcrumb['links'][] = [
|
||||
'title' => $this->trans('On sale', [], 'Shop.Theme.Catalog'),
|
||||
'url' => $this->context->link->getPageLink('prices-drop', true),
|
||||
];
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
}
|
||||
118
controllers/front/listing/SearchController.php
Normal file
118
controllers/front/listing/SearchController.php
Normal file
@@ -0,0 +1,118 @@
|
||||
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
use PrestaShop\PrestaShop\Adapter\Search\SearchProductSearchProvider;
|
||||
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchQuery;
|
||||
use PrestaShop\PrestaShop\Core\Product\Search\SortOrder;
|
||||
|
||||
class SearchControllerCore extends ProductListingFrontController
|
||||
{
|
||||
public $php_self = 'search';
|
||||
public $instant_search;
|
||||
public $ajax_search;
|
||||
|
||||
protected $search_string;
|
||||
protected $search_tag;
|
||||
|
||||
/**
|
||||
* Assign template vars related to page content.
|
||||
*
|
||||
* @see FrontController::initContent()
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
|
||||
$this->search_string = Tools::getValue('s');
|
||||
if (!$this->search_string) {
|
||||
$this->search_string = Tools::getValue('search_query');
|
||||
}
|
||||
|
||||
$this->search_tag = Tools::getValue('tag');
|
||||
|
||||
$this->context->smarty->assign(
|
||||
[
|
||||
'search_string' => $this->search_string,
|
||||
'search_tag' => $this->search_tag,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that no search results page is indexed by search engines.
|
||||
*/
|
||||
public function getTemplateVarPage()
|
||||
{
|
||||
$page = parent::getTemplateVarPage();
|
||||
|
||||
$page['meta']['robots'] = 'noindex';
|
||||
|
||||
return $page;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the search.
|
||||
*/
|
||||
public function initContent()
|
||||
{
|
||||
parent::initContent();
|
||||
|
||||
$this->doProductSearch('catalog/listing/search', ['entity' => 'search']);
|
||||
}
|
||||
|
||||
protected function getProductSearchQuery()
|
||||
{
|
||||
$query = new ProductSearchQuery();
|
||||
$query
|
||||
->setSortOrder(new SortOrder('product', 'position', 'desc'))
|
||||
->setSearchString($this->search_string)
|
||||
->setSearchTag($this->search_tag);
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
protected function getDefaultProductSearchProvider()
|
||||
{
|
||||
return new SearchProductSearchProvider(
|
||||
$this->getTranslator()
|
||||
);
|
||||
}
|
||||
|
||||
public function getListingLabel()
|
||||
{
|
||||
return $this->getTranslator()->trans('Search results', [], 'Shop.Theme.Catalog');
|
||||
}
|
||||
|
||||
public function getBreadcrumbLinks()
|
||||
{
|
||||
$breadcrumb = parent::getBreadcrumbLinks();
|
||||
$breadcrumb['links'][] = [
|
||||
'title' => $this->getTranslator()->trans('Search results', [], 'Shop.Theme.Catalog'),
|
||||
'url' => $this->getCurrentUrl(),
|
||||
];
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
}
|
||||
221
controllers/front/listing/SupplierController.php
Normal file
221
controllers/front/listing/SupplierController.php
Normal file
@@ -0,0 +1,221 @@
|
||||
<?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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
use PrestaShop\PrestaShop\Adapter\Supplier\SupplierProductSearchProvider;
|
||||
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchQuery;
|
||||
use PrestaShop\PrestaShop\Core\Product\Search\SortOrder;
|
||||
|
||||
class SupplierControllerCore extends ProductListingFrontController
|
||||
{
|
||||
public $php_self = 'supplier';
|
||||
|
||||
/** @var Supplier */
|
||||
protected $supplier;
|
||||
protected $label;
|
||||
|
||||
public function canonicalRedirection($canonicalURL = '')
|
||||
{
|
||||
if (Validate::isLoadedObject($this->supplier)) {
|
||||
parent::canonicalRedirection($this->context->link->getSupplierLink($this->supplier));
|
||||
} elseif ($canonicalURL) {
|
||||
parent::canonicalRedirection($canonicalURL);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize supplier controller.
|
||||
*
|
||||
* @see FrontController::init()
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
if ($id_supplier = (int) Tools::getValue('id_supplier')) {
|
||||
$this->supplier = new Supplier($id_supplier, $this->context->language->id);
|
||||
|
||||
if (!Validate::isLoadedObject($this->supplier) || !$this->supplier->active) {
|
||||
$this->redirect_after = '404';
|
||||
$this->redirect();
|
||||
} else {
|
||||
$this->canonicalRedirection();
|
||||
}
|
||||
}
|
||||
|
||||
parent::init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign template vars related to page content.
|
||||
*
|
||||
* @see FrontController::initContent()
|
||||
*/
|
||||
public function initContent()
|
||||
{
|
||||
if (Configuration::get('PS_DISPLAY_SUPPLIERS')) {
|
||||
parent::initContent();
|
||||
|
||||
if (Validate::isLoadedObject($this->supplier) && $this->supplier->active && $this->supplier->isAssociatedToShop()) {
|
||||
$this->assignSupplier();
|
||||
$this->label = $this->trans(
|
||||
'List of products by supplier %supplier_name%',
|
||||
[
|
||||
'%supplier_name%' => $this->supplier->name,
|
||||
],
|
||||
'Shop.Theme.Catalog'
|
||||
);
|
||||
$this->doProductSearch(
|
||||
'catalog/listing/supplier',
|
||||
['entity' => 'supplier', 'id' => $this->supplier->id]
|
||||
);
|
||||
} else {
|
||||
$this->assignAll();
|
||||
$this->label = $this->trans(
|
||||
'List of all suppliers',
|
||||
[],
|
||||
'Shop.Theme.Catalog'
|
||||
);
|
||||
$this->setTemplate('catalog/suppliers', ['entity' => 'suppliers']);
|
||||
}
|
||||
} else {
|
||||
$this->redirect_after = '404';
|
||||
$this->redirect();
|
||||
}
|
||||
}
|
||||
|
||||
protected function getProductSearchQuery()
|
||||
{
|
||||
$query = new ProductSearchQuery();
|
||||
$query
|
||||
->setIdSupplier($this->supplier->id)
|
||||
->setSortOrder(new SortOrder('product', 'position', 'asc'));
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
protected function getDefaultProductSearchProvider()
|
||||
{
|
||||
return new SupplierProductSearchProvider(
|
||||
$this->getTranslator(),
|
||||
$this->supplier
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign template vars if displaying one supplier.
|
||||
*/
|
||||
protected function assignSupplier()
|
||||
{
|
||||
$supplierVar = $this->objectPresenter->present($this->supplier);
|
||||
|
||||
$filteredSupplier = Hook::exec(
|
||||
'filterSupplierContent',
|
||||
['object' => $supplierVar],
|
||||
$id_module = null,
|
||||
$array_return = false,
|
||||
$check_exceptions = true,
|
||||
$use_push = false,
|
||||
$id_shop = null,
|
||||
$chain = true
|
||||
);
|
||||
if (!empty($filteredSupplier['object'])) {
|
||||
$supplierVar = $filteredSupplier['object'];
|
||||
}
|
||||
|
||||
$this->context->smarty->assign([
|
||||
'supplier' => $supplierVar,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign template vars if displaying the supplier list.
|
||||
*/
|
||||
protected function assignAll()
|
||||
{
|
||||
$suppliersVar = $this->getTemplateVarSuppliers();
|
||||
|
||||
if (!empty($suppliersVar)) {
|
||||
foreach ($suppliersVar as $k => $supplier) {
|
||||
$filteredSupplier = Hook::exec(
|
||||
'filterSupplierContent',
|
||||
['object' => $supplier],
|
||||
$id_module = null,
|
||||
$array_return = false,
|
||||
$check_exceptions = true,
|
||||
$use_push = false,
|
||||
$id_shop = null,
|
||||
$chain = true
|
||||
);
|
||||
if (!empty($filteredSupplier['object'])) {
|
||||
$suppliersVar[$k] = $filteredSupplier['object'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->context->smarty->assign([
|
||||
'brands' => $suppliersVar,
|
||||
]);
|
||||
}
|
||||
|
||||
public function getTemplateVarSuppliers()
|
||||
{
|
||||
$suppliers = Supplier::getSuppliers(true, $this->context->language->id, true);
|
||||
$suppliers_for_display = [];
|
||||
|
||||
foreach ($suppliers as $supplier) {
|
||||
$suppliers_for_display[$supplier['id_supplier']] = $supplier;
|
||||
$suppliers_for_display[$supplier['id_supplier']]['text'] = $supplier['description'];
|
||||
$suppliers_for_display[$supplier['id_supplier']]['image'] = $this->context->link->getSupplierImageLink($supplier['id_supplier'], 'small_default');
|
||||
$suppliers_for_display[$supplier['id_supplier']]['url'] = $this->context->link->getsupplierLink($supplier['id_supplier']);
|
||||
$suppliers_for_display[$supplier['id_supplier']]['nb_products'] = $supplier['nb_products'] > 1
|
||||
? $this->trans('%number% products', ['%number%' => $supplier['nb_products']], 'Shop.Theme.Catalog')
|
||||
: $this->trans('%number% product', ['%number%' => $supplier['nb_products']], 'Shop.Theme.Catalog');
|
||||
}
|
||||
|
||||
return $suppliers_for_display;
|
||||
}
|
||||
|
||||
public function getListingLabel()
|
||||
{
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
public function getBreadcrumbLinks()
|
||||
{
|
||||
$breadcrumb = parent::getBreadcrumbLinks();
|
||||
|
||||
$breadcrumb['links'][] = [
|
||||
'title' => $this->trans('All suppliers', [], 'Shop.Theme.Catalog'),
|
||||
'url' => $this->context->link->getPageLink('supplier', true),
|
||||
];
|
||||
|
||||
if (Validate::isLoadedObject($this->supplier) && $this->supplier->active && $this->supplier->isAssociatedToShop()) {
|
||||
$breadcrumb['links'][] = [
|
||||
'title' => $this->supplier->name,
|
||||
'url' => $this->context->link->getSupplierLink($this->supplier),
|
||||
];
|
||||
}
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
}
|
||||
34
controllers/front/listing/index.php
Normal file
34
controllers/front/listing/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 Open Software License (OSL 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/OSL-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/OSL-3.0 Open Software License (OSL 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;
|
||||
Reference in New Issue
Block a user