Initial commit

This commit is contained in:
2019-11-20 07:44:43 +01:00
commit 5bf49c4a81
41188 changed files with 5459177 additions and 0 deletions

View File

@@ -0,0 +1,146 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class AddressControllerCore extends FrontController
{
public $auth = false;
public $guestAllowed = true;
public $php_self = 'address';
public $authRedirection = 'addresses';
public $ssl = true;
private $address_form;
private $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);
$this->address_form->fillWith(Tools::getAllValues());
if (Tools::isSubmit('submitAddress')) {
if (!$this->address_form->submit()) {
$this->errors[] = $this->trans('Please fix the error below.', array(), 'Shop.Notifications.Error');
} else {
if (Tools::getValue('id_address')) {
$this->success[] = $this->trans('Address successfully updated!', array(), 'Shop.Notifications.Success');
} else {
$this->success[] = $this->trans('Address successfully added!', array(), 'Shop.Notifications.Success');
}
$this->should_redirect = true;
}
} elseif (($id_address = (int) Tools::getValue('id_address'))) {
$this->address_form->loadAddressById($id_address);
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!', array(), 'Shop.Notifications.Success');
$this->should_redirect = true;
} else {
$this->errors[] = $this->trans('Could not delete address.', array(), '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', array('entity' => 'address', 'id' => Tools::getValue('id_address')));
}
public function getBreadcrumbLinks()
{
$breadcrumb = parent::getBreadcrumbLinks();
$breadcrumb['links'][] = $this->addMyAccountToBreadcrumb();
$breadcrumb['links'][] = [
'title' => $this->trans('Addresses', array(), '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(array('id_country' => Tools::getValue('id_country')));
}
ob_end_clean();
header('Content-Type: application/json');
$this->ajaxRender(Tools::jsonEncode(array(
'address_form' => $this->render(
'customer/_partials/address-form',
$addressForm->getTemplateVariables()
),
)));
return;
}
}

View File

@@ -0,0 +1,71 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
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($this->trans('The customer could not be found.', array(), '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', array(), 'Shop.Theme.Actions') . '</a>';
$this->warning[] = $this->trans('No addresses are available. %s', array($link), 'Shop.Notifications.Success');
}
parent::initContent();
$this->setTemplate('customer/addresses');
}
public function getBreadcrumbLinks()
{
$breadcrumb = parent::getBreadcrumbLinks();
$breadcrumb['links'][] = $this->addMyAccountToBreadcrumb();
return $breadcrumb;
}
}

View File

@@ -0,0 +1,81 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
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', array('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;
}
}

View File

@@ -0,0 +1,110 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
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', array(), 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__);
}
}
}

View File

@@ -0,0 +1,622 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @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\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[]
*/
private $updateOperationError = array();
/**
* 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');
}
$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, array($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_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'),
]));
return;
}
/**
* @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,
]));
return;
}
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.',
array(),
'Shop.Notifications.Error'
);
} elseif (!Validate::isCleanHtml($code)) {
$this->errors[] = $this->trans(
'The voucher code is invalid.',
array(),
'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.',
array(),
'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
);
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',
array('%quantity%' => $minimal_quantity),
'Shop.Notifications.Error'
);
return false;
}
}
$data = array(
'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.',
array(),
'Shop.Notifications.Error'
);
} elseif (!$this->id_product) {
$this->{$ErrorKey}[] = $this->trans(
'Product not found',
array(),
'Shop.Notifications.Error'
);
}
$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.',
array('%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));
}
}
$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 item %product% in your cart is no longer available in this quantity. You cannot proceed with your order until the quantity is adjusted.',
array('%product%' => $product->name),
'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%.',
array('%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%.',
array('%product%' => $product->name, '%quantity%' => $combination->minimal_quantity),
'Shop.Notifications.Error'
);
return;
}
}
// 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.',
array(),
'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',
array('%quantity%' => $minimal_quantity),
'Shop.Notifications.Error'
);
} elseif (!$update_quantity) {
$this->errors[] = $this->trans(
'You already have the maximum quantity available for this product.',
array(),
'Shop.Notifications.Error'
);
} elseif ($this->shouldAvailabilityErrorBeRaised($product, $qty_to_check)) {
// check quantity after cart quantity update
$this->{$ErrorKey}[] = $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.',
array('%product%' => $product->name),
'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.
*
* @param Product $product
* @param int $qtyToCheck
*
* @return bool
*/
private 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;
}
// product quantity is the available quantity after decreasing products in cart
$productQuantity = Product::getQuantity(
$this->id_product,
$this->id_product_attribute,
null,
$this->context->cart,
$this->customization_id
);
return $productQuantity < 0;
}
/**
* Check if the products in the cart are available.
*
* @return bool|string
*/
private function areProductsAvailable()
{
$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.',
array('%product%' => $product['name']),
'Shop.Notifications.Error'
);
}
return $this->trans(
'This product (%product%) is no longer available.',
array('%product%' => $product['name']),
'Shop.Notifications.Error'
);
}
}

View File

@@ -0,0 +1,46 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
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');
return;
}
}

View File

@@ -0,0 +1,218 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
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',
array('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(array(
'cms' => $cmsVar,
));
if ($this->cms->indexation == 0) {
$this->context->smarty->assign('nobots', true);
}
$this->setTemplate(
'cms/page',
array('entity' => 'cms', 'id' => $this->cms->id)
);
} elseif ($this->assignCase == 2) {
$cmsCategoryVar = $this->getTemplateVarCategoryCms();
$filteredCmsCategoryContent = Hook::exec(
'filterCmsCategoryContent',
array('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 array((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'][] = array(
'title' => $cmsSubCategory->getName(),
'url' => $this->context->link->getCMSCategoryLink($cmsSubCategory),
);
}
}
if ($this->assignCase == 1) {
$breadcrumb['links'][] = array(
'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 = array();
$categoryCms['cms_category'] = $this->objectPresenter->present($this->cms_category);
$categoryCms['sub_categories'] = array();
$categoryCms['cms_pages'] = array();
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;
}
}

View File

@@ -0,0 +1,54 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
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;
}
}

View File

@@ -0,0 +1,177 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
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.', array(), 'Shop.Notifications.Warning');
}
$this->context->smarty->assign([
'cart_rules' => $cart_rules,
]);
parent::initContent();
$this->setTemplate('customer/discount');
}
public function getTemplateVarCartRules()
{
$cart_rules = [];
$vouchers = CartRule::getCustomerCartRules(
$this->context->language->id,
$this->context->customer->id,
true,
false
);
foreach ($vouchers as $key => $voucher) {
$cart_rules[$key] = $voucher;
$cart_rules[$key]['voucher_date'] = Tools::displayDate($voucher['date_to'], null, false);
$cart_rules[$key]['voucher_minimal'] = ($voucher['minimum_amount'] > 0) ? Tools::displayPrice($voucher['minimum_amount'], (int) $voucher['minimum_amount_currency']) : $this->trans('None', array(), 'Shop.Theme.Global');
$cart_rules[$key]['voucher_cumulable'] = $this->getCombinableVoucherTranslation($voucher);
$cartRuleValue = $this->accumulateCartRuleValue($voucher);
if (0 === count($cartRuleValue)) {
$cart_rules[$key]['value'] = '-';
} else {
$cart_rules[$key]['value'] = implode(' + ', $cartRuleValue);
}
}
return $cart_rules;
}
public function getBreadcrumbLinks()
{
$breadcrumb = parent::getBreadcrumbLinks();
$breadcrumb['links'][] = $this->addMyAccountToBreadcrumb();
return $breadcrumb;
}
/**
* @param $voucher
*
* @return mixed
*/
protected function getCombinableVoucherTranslation($voucher)
{
if ($voucher['cart_rule_restriction']) {
$combinableVoucherTranslation = $this->trans('No', array(), 'Shop.Theme.Global');
} else {
$combinableVoucherTranslation = $this->trans('Yes', array(), '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', array(), 'Shop.Theme.Checkout');
} else {
$taxTranslation = $this->trans('Tax excluded', array(), 'Shop.Theme.Checkout');
}
return sprintf(
'%s ' . $taxTranslation,
Tools::displayPrice($amount, (int) $currencyId)
);
}
/**
* @param $percentage
*
* @return string
*/
protected function formatReductionInPercentage($percentage)
{
return sprintf('%s%%', $percentage);
}
/**
* @param $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', array(), 'Shop.Theme.Checkout');
}
if ($voucher['gift_product'] > 0) {
$cartRuleValue[] = Product::getProductName(
$voucher['gift_product'],
$voucher['gift_product_attribute']
);
}
return $cartRuleValue;
}
}

View File

@@ -0,0 +1,337 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
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_ . strval(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() && !Tools::getValue('secure_key') && !Tools::getValue('id_order')) {
Tools::redirect('index.php?controller=authentication&back=get-file.php&key=' . $key);
} elseif (!$this->context->customer->isLogged() && 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.');
}
}
/* 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.');
}
/* 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']) && isset($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 = array(
'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 = array(
'Invalid key.' => $this->trans('Invalid key.', array(), 'Shop.Notifications.Error'),
'This product does not exist in our store.' => $this->trans('This product does not exist in our store.', array(), 'Shop.Notifications.Error'),
'This product has been deleted.' => $this->trans('This product has been deleted.', array(), 'Shop.Notifications.Error'),
'This file no longer exists.' => $this->trans('This file no longer exists.', array(), 'Shop.Notifications.Error'),
'This product has been refunded.' => $this->trans('This product has been refunded.', array(), 'Shop.Notifications.Error'),
'The product deadline is in the past.' => $this->trans('The product deadline is in the past.', array(), 'Shop.Notifications.Error'),
'Expiration date exceeded' => $this->trans('The product expiration date has passed, preventing you from download this product.', array(), 'Shop.Notifications.Error'),
'Expiration date has passed, you cannot download this product' => $this->trans('Expiration date has passed, you cannot download this product.', array(), 'Shop.Notifications.Error'),
'You have reached the maximum number of allowed downloads.' => $this->trans('You have reached the maximum number of downloads allowed.', array(), '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();
}
}

View File

@@ -0,0 +1,157 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @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 GuestTrackingControllerCore extends FrontController
{
public $ssl = true;
public $auth = false;
public $php_self = 'guest-tracking';
private $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',
array(),
'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',
array(),
'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',
array(),
'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.',
array('%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.',
array(),
'Shop.Notifications.Success'
);
} else {
$this->success[] = $this->trans(
'An unexpected error occurred while creating your account.',
array(),
'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.', array(), 'Shop.Notifications.Warning'
);
}
$presented_order = (new OrderPresenter())->present($this->order);
$this->context->smarty->assign(array(
'order' => $presented_order,
'guest_email' => Tools::getValue('email'),
'HOOK_DISPLAYORDERDETAIL' => Hook::exec('displayOrderDetail', array('order' => $this->order)),
));
return $this->setTemplate('customer/guest-tracking');
}
public function getBreadcrumbLinks()
{
$breadcrumbLinks = parent::getBreadcrumbLinks();
$breadcrumbLinks['links'][] = array(
'title' => $this->getTranslator()->trans('Guest order tracking', array(), 'Shop.Theme.Checkout'),
'url' => '#',
);
return $breadcrumbLinks;
}
}

View File

@@ -0,0 +1,113 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @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 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.', array(), 'Shop.Notifications.Warning');
}
$orders = $this->getTemplateVarOrders();
if (count($orders) <= 0) {
$this->warning[] = $this->trans('You have not placed any orders.', array(), 'Shop.Notifications.Warning');
}
$this->context->smarty->assign(array(
'orders' => $orders,
));
parent::initContent();
$this->setTemplate('customer/history');
}
public function getTemplateVarOrders()
{
$orders = array();
$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 .= '&amp;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();
return $breadcrumb;
}
}

View File

@@ -0,0 +1,88 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
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.', array(), 'Shop.Notifications.Success');
$should_redirect = true;
} else {
$this->errors[] = $this->trans('Could not update your information, please check your data.', array(), '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();
return $breadcrumb;
}
}

View File

@@ -0,0 +1,43 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
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(array(
'HOOK_HOME' => Hook::exec('displayHome'),
));
$this->setTemplate('index');
}
}

View File

@@ -0,0 +1,47 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
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');
}
}

View File

@@ -0,0 +1,159 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @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();
}
$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.
*/
private 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
);
}
}

View File

@@ -0,0 +1,348 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
use PrestaShop\PrestaShop\Core\Foundation\Templating\RenderableProxy;
use PrestaShop\PrestaShop\Adapter\Product\PriceFormatter;
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') && $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.', array(), 'Shop.Notifications.Error');
} elseif (!$duplication['success']) {
$this->errors[] = $this->trans(
'Some items are no longer available, and we are unable to renew your order.', array(), '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();
}
protected 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 = array();
}
$addressValidator = new AddressValidator();
$invalidAddressIds = $addressValidator->validateCartAddresses($cart);
// Build the currently selected address' warning message (if relevant)
if (!$customer->isGuest() && !empty($invalidAddressIds)) {
$this->checkoutWarning['address'] = array(
'id_address' => (int) reset($invalidAddressIds),
'exception' => $this->trans(
'Your address is incomplete, please update it.',
array(),
'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
);
ob_end_clean();
header('Content-Type: application/json');
$this->ajaxRender(Tools::jsonEncode(array(
'preview' => $this->render('checkout/_partials/cart-summary', array(
'cart' => $cart,
'static_token' => Tools::getToken(false),
)),
)));
return;
}
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);
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, array('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(array('id_country' => Tools::getValue('id_country')));
}
$stepTemplateParameters = array();
foreach ($this->checkoutProcess->getSteps() as $step) {
if ($step instanceof CheckoutAddressesStep) {
$stepTemplateParameters = $step->getTemplateParameters();
}
}
$templateParams = array_merge(
$addressForm->getTemplateVariables(),
$stepTemplateParameters,
array('type' => 'delivery')
);
ob_end_clean();
header('Content-Type: application/json');
$this->ajaxRender(Tools::jsonEncode(array(
'address_form' => $this->render(
'checkout/_partials/address-form',
$templateParams
),
)));
return;
}
}

View File

@@ -0,0 +1,214 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @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 OrderDetailControllerCore extends FrontController
{
public $php_self = 'order-detail';
public $auth = true;
public $authRedirection = 'history';
public $ssl = true;
protected $order_to_display;
/**
* 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.', array(), 'Shop.Notifications.Error');
} elseif (empty($msgText)) {
$this->errors[] = $this->trans('The message cannot be blank.', array(), 'Shop.Notifications.Error');
} elseif (!Validate::isMessage($msgText)) {
$this->errors[] = $this->trans('This message is invalid (HTML is not allowed).', array(), '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 = strval(Configuration::get('PS_SHOP_EMAIL'));
} else {
$to = new Contact((int) Configuration::get('PS_MAIL_EMAIL_MESSAGE'));
$to = strval($to->email);
}
$toName = strval(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',
array(),
'Emails.Subject'
),
array(
'{lastname}' => $customer->lastname,
'{firstname}' => $customer->firstname,
'{email}' => $customer->email,
'{id_order}' => (int) $order->id,
'{order_name}' => $order->getUniqReference(),
'{message}' => Tools::nl2br($msgText),
'{product_name}' => $product_name,
),
$to,
$toName,
strval(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.', array(), 'Shop.Notifications.Error');
} elseif (Tools::getIsset('errorMsg')) {
$this->errors[] = $this->trans('Please provide an explanation for your RMA.', array(), 'Shop.Notifications.Error');
} elseif (Tools::getIsset('errorDetail1')) {
$this->errors[] = $this->trans('Please check at least one product you would like to return.', array(), 'Shop.Notifications.Error');
} elseif (Tools::getIsset('errorDetail2')) {
$this->errors[] = $this->trans('For each product you wish to add, please specify the desired quantity.', array(), 'Shop.Notifications.Error');
} elseif (Tools::getIsset('errorNotReturnable')) {
$this->errors[] = $this->trans('This order cannot be returned', array(), 'Shop.Notifications.Error');
} elseif (Tools::getIsset('messagesent')) {
$this->success[] = $this->trans('Message successfully sent', array(), '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->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'][] = array(
'title' => $this->trans('Order history', array(), 'Shop.Theme.Customeraccount'),
'url' => $this->context->link->getPageLink('history'),
);
return $breadcrumb;
}
}

View File

@@ -0,0 +1,138 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @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\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(array(
'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', array('orderReturn' => $orderReturn));
Tools::redirect('index.php?controller=order-follow');
}
}
/**
* Assign template vars related to page content.
*
* @see FrontController::initContent()
*/
public function initContent()
{
if (Configuration::isCatalogMode()) {
Tools::redirect('index.php');
}
$ordersReturn = $this->getTemplateVarOrdersReturns();
if (count($ordersReturn) <= 0) {
$this->warning[] = $this->trans(
'You have no merchandise return authorizations.', array(), 'Shop.Notifications.Error'
);
}
$this->context->smarty->assign('ordersReturn', $ordersReturn);
parent::initContent();
$this->setTemplate('customer/order-follow');
}
public function getTemplateVarOrdersReturns()
{
$orders_returns = array();
$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;
}
}

View File

@@ -0,0 +1,181 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @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\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.', array(), 'Shop.Notifications.Warning');
}
// StarterTheme: Use presenters!
$this->context->smarty->assign(array(
'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 = array();
$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) : array();
}
}
return $products;
}
public function getTemplateVarCustomization(array $product)
{
$product_customizations = array();
$imageRetriever = new ImageRetriever($this->context->link);
foreach ($product['customizedDatas'] as $byAddress) {
foreach ($byAddress as $customization) {
$presentedCustomization = array(
'quantity' => $customization['quantity'],
'fields' => array(),
'id_customization' => null,
);
foreach ($customization['datas'] as $byType) {
$field = array();
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'][] = array(
'title' => $this->trans('Merchandise returns', array(), 'Shop.Theme.Global'),
'url' => $this->context->link->getPageLink('order-follow'),
);
}
return $breadcrumb;
}
}

View File

@@ -0,0 +1,85 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
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.', array(), '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%', array('%id%' => $order_slip['id_order_slip']), 'Shop.Theme.Customeraccount');
$credit_slips[$order_slip['id_order_slip']]['order_number'] = $this->trans('#%id%', array('%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();
return $breadcrumb;
}
}

View File

@@ -0,0 +1,63 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
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.', array(), 'Shop.Theme.Global');
return $page;
}
}

View File

@@ -0,0 +1,248 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class PasswordControllerCore extends FrontController
{
public $php_self = 'password';
public $auth = false;
public $ssl = true;
/**
* 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', array(), 'Shop.Notifications.Error');
}
}
protected function sendRenewPasswordLink()
{
if (!($email = trim(Tools::getValue('email'))) || !Validate::isEmail($email)) {
$this->errors[] = $this->trans('Invalid email address.', array(), 'Shop.Notifications.Error');
} else {
$customer = new Customer();
$customer->getByEmail($email);
if (is_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%.',
array('%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.', array(), '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)', array((int) $minTime), 'Shop.Notifications.Error');
} else {
if (!$customer->hasRecentResetPasswordToken()) {
$customer->stampResetPasswordToken();
$customer->update();
}
$mailParams = array(
'{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',
array(),
'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%.', array('%email%' => $customer->email), 'Shop.Notifications.Success');
$this->setTemplate('customer/password-infos');
} else {
$this->errors[] = $this->trans('An error occurred while sending the email.', array(), 'Shop.Notifications.Error');
}
}
}
}
protected function changePassword()
{
$token = Tools::getValue('token');
$id_customer = (int) Tools::getValue('id_customer');
if ($email = Db::getInstance()->getValue('SELECT `email` FROM ' . _DB_PREFIX_ . 'customer c WHERE c.`secure_key` = \'' . pSQL($token) . '\' AND c.id_customer = ' . $id_customer)) {
$customer = new Customer();
$customer->getByEmail($email);
if (!Validate::isLoadedObject($customer)) {
$this->errors[] = $this->trans('Customer account not found', array(), 'Shop.Notifications.Error');
} elseif (!$customer->active) {
$this->errors[] = $this->trans('You cannot regenerate the password for this account.', array(), 'Shop.Notifications.Error');
}
// Case if both password params not posted or different, then "change password" form is not POSTED, show it.
if (!(Tools::isSubmit('passwd'))
|| !(Tools::isSubmit('confirmation'))
|| ($passwd = Tools::getValue('passwd')) !== ($confirmation = Tools::getValue('confirmation'))
|| !Validate::isPasswd($passwd) || !Validate::isPasswd($confirmation)) {
// Check if passwords are here anyway, BUT does not match the password validation format
if (Tools::isSubmit('passwd') || Tools::isSubmit('confirmation')) {
$this->errors[] = $this->trans('The password and its confirmation do not match.', array(), 'Shop.Notifications.Error');
}
$this->context->smarty->assign([
'customer_email' => $customer->email,
'customer_token' => $token,
'id_customer' => $id_customer,
'reset_token' => Tools::getValue('reset_token'),
]);
$this->setTemplate('customer/password-new');
} else {
// Both password fields posted. Check if all is right and store new password properly.
if (!Tools::getValue('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 {
// To update password, we must have the temporary reset token that matches.
if ($customer->getValidResetPasswordToken() !== Tools::getValue('reset_token')) {
$this->errors[] = $this->trans('The password change request expired. You should ask for a new one.', array(), 'Shop.Notifications.Error');
} 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', array('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',
array(),
'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', array($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.', array(), '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.', array(), 'Shop.Notifications.Error');
}
}
}
}
} else {
$this->errors[] = $this->trans('We cannot regenerate your password with the data you\'ve submitted', array(), 'Shop.Notifications.Error');
}
}
/**
* @return bool
*/
public function display()
{
$this->context->smarty->assign(
array(
'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 = array();
if (array_key_exists('error', $notifications)) {
$errors = $notifications['error'];
}
return $errors;
}
/**
* @return array
*/
protected function getSuccesses()
{
$notifications = $this->prepareNotifications();
$successes = array();
if (array_key_exists('success', $notifications)) {
$successes = $notifications['success'];
}
return $successes;
}
}

View File

@@ -0,0 +1,75 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
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.', array(), '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.', array(), '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.', array(), 'Shop.Notifications.Error'));
}
if (!OrderState::invoiceAvailable($order->getCurrentState()) && !$order->invoice_number) {
die($this->trans('No invoice is available.', array(), 'Shop.Notifications.Error'));
}
$this->order = $order;
}
public function display()
{
$order_invoice_list = $this->order->getInvoicesCollection();
Hook::exec('actionPDFInvoiceRender', array('order_invoice_list' => $order_invoice_list));
$pdf = new PDF($order_invoice_list, PDF::TEMPLATE_INVOICE, $this->context->smarty);
$pdf->render();
}
}

View File

@@ -0,0 +1,58 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
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.', array(), 'Shop.Notifications.Error'));
} elseif (!$from_admin && $this->orderReturn->id_customer != $this->context->customer->id) {
die($this->trans('Order return not found.', array(), 'Shop.Notifications.Error'));
} elseif ($this->orderReturn->state < 2) {
die($this->trans('Order return not confirmed.', array(), 'Shop.Notifications.Error'));
}
}
public function display()
{
$pdf = new PDF($this->orderReturn, PDF::TEMPLATE_ORDER_RETURN, $this->context->smarty);
$pdf->render();
}
}

View File

@@ -0,0 +1,56 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
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.', array(), 'Shop.Notifications.Error'));
} elseif ($this->order_slip->id_customer != $this->context->customer->id) {
die($this->trans('Order return not found.', array(), 'Shop.Notifications.Error'));
}
}
public function display()
{
$pdf = new PDF($this->order_slip, PDF::TEMPLATE_ORDER_SLIP, $this->context->smarty);
$pdf->render();
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,187 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
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(
array(
'our_offers' => $this->trans('Our Offers', array(), 'Shop.Theme.Global'),
'categories' => $this->trans('Categories', array(), 'Shop.Theme.Catalog'),
'your_account' => $this->trans('Your account', array(), 'Shop.Theme.Customeraccount'),
'pages' => $this->trans('Pages', array(), 'Shop.Theme.Catalog'),
'links' => array(
'offers' => $this->getOffersLinks(),
'pages' => $this->getPagesLinks(),
'user_account' => $this->getUserAccountLinks(),
'categories' => $this->getCategoriesLinks(),
),
)
);
parent::initContent();
$this->setTemplate('cms/sitemap');
}
public function getCategoriesLinks()
{
return array(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[] = array(
'id' => 'stores-page',
'label' => $this->trans('Our stores', array(), 'Shop.Theme.Global'),
'url' => $this->context->link->getPageLink('stores'),
);
$links[] = array(
'id' => 'contact-page',
'label' => $this->trans('Contact us', array(), 'Shop.Theme.Global'),
'url' => $this->context->link->getPageLink('contact'),
);
$links[] = array(
'id' => 'sitemap-page',
'label' => $this->trans('Sitemap', array(), 'Shop.Theme.Global'),
'url' => $this->context->link->getPageLink('sitemap'),
);
return $links;
}
/**
* @return array
*/
protected function getCmsTree($cms)
{
$links = array();
foreach ($cms['cms'] as $p) {
$links[] = array(
'id' => 'cms-page-' . $p['id_cms'],
'label' => $p['meta_title'],
'url' => $p['link'],
);
}
if (isset($cms['children'])) {
foreach ($cms['children'] as $c) {
$links[] = array(
'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 = array();
$links[] = array(
'id' => 'login-page',
'label' => $this->trans('Log in', array(), 'Shop.Theme.Global'),
'url' => $this->context->link->getPageLink('authentication'),
);
$links[] = array(
'id' => 'register-page',
'label' => $this->trans('Create new account', array(), 'Shop.Theme.Global'),
'url' => $this->context->link->getPageLink('authentication'),
);
return $links;
}
/**
* @return array
*/
protected function getOffersLinks()
{
$links = array(
array(
'id' => 'new-product-page',
'label' => $this->trans('New products', array(), 'Shop.Theme.Catalog'),
'url' => $this->context->link->getPageLink('new-products'),
),
);
if (Configuration::isCatalogMode() && Configuration::get('PS_DISPLAY_BEST_SELLERS')) {
$links[] = array(
'id' => 'best-sales-page',
'label' => $this->trans('Best sellers', array(), 'Shop.Theme.Catalog'),
'url' => $this->context->link->getPageLink('best-sales'),
);
$links[] = array(
'id' => 'prices-drop-page',
'label' => $this->trans('Price drop', array(), 'Shop.Theme.Catalog'),
'url' => $this->context->link->getPageLink('prices-drop'),
);
}
if (Configuration::get('PS_DISPLAY_SUPPLIERS')) {
$manufacturers = Manufacturer::getLiteManufacturersList($this->context->language->id, 'sitemap');
$links[] = array(
'id' => 'manufacturer-page',
'label' => $this->trans('Brands', array(), 'Shop.Theme.Catalog'),
'url' => $this->context->link->getPageLink('manufacturer'),
'children' => $manufacturers,
);
$suppliers = Supplier::getLiteSuppliersList($this->context->language->id, 'sitemap');
$links[] = array(
'id' => 'supplier-page',
'label' => $this->trans('Suppliers', array(), 'Shop.Theme.Catalog'),
'url' => $this->context->link->getPageLink('supplier'),
'children' => $suppliers,
);
}
return $links;
}
}

View File

@@ -0,0 +1,93 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
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);
}
}

View File

@@ -0,0 +1,238 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
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.', array(), '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 = array(
'firstname',
'lastname',
);
$out_datas = array();
$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 = array();
$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, array('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());
return;
}
/**
* 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, array('km', 'mi'))) {
$distance_unit = 'km';
}
$this->context->smarty->assign(array(
'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, array(), '<br />');
// Prepare $store.business_hours
// Required for trad
$temp = json_decode($store['hours'], true);
unset($store['hours']);
$store['business_hours'] = [
[
'day' => $this->trans('Monday', array(), 'Shop.Theme.Global'),
'hours' => $temp[0],
], [
'day' => $this->trans('Tuesday', array(), 'Shop.Theme.Global'),
'hours' => $temp[1],
], [
'day' => $this->trans('Wednesday', array(), 'Shop.Theme.Global'),
'hours' => $temp[2],
], [
'day' => $this->trans('Thursday', array(), 'Shop.Theme.Global'),
'hours' => $temp[3],
], [
'day' => $this->trans('Friday', array(), 'Shop.Theme.Global'),
'hours' => $temp[4],
], [
'day' => $this->trans('Saturday', array(), 'Shop.Theme.Global'),
'hours' => $temp[5],
], [
'day' => $this->trans('Sunday', array(), '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;
}
}

View File

@@ -0,0 +1,34 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;

View File

@@ -0,0 +1,82 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchQuery;
use PrestaShop\PrestaShop\Core\Product\Search\SortOrder;
use PrestaShop\PrestaShop\Adapter\BestSales\BestSalesProductSearchProvider;
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', array(), 'Shop.Theme.Catalog');
}
}

View File

@@ -0,0 +1,274 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchQuery;
use PrestaShop\PrestaShop\Core\Product\Search\SortOrder;
use PrestaShop\PrestaShop\Adapter\Category\CategoryProductSearchProvider;
use PrestaShop\PrestaShop\Adapter\Image\ImageRetriever;
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 = array();
}
$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.', array(), 'Shop.Notifications.Error');
$this->setTemplate('errors/forbidden');
return;
}
$categoryVar = $this->getTemplateVarCategory();
$filteredCategory = Hook::exec(
'filterCategoryContent',
array('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(array(
'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', array('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);
}
}
$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%',
array('%category_name%' => $this->category->name),
'Shop.Theme.Catalog'
);
}
}

View File

@@ -0,0 +1,196 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchQuery;
use PrestaShop\PrestaShop\Core\Product\Search\SortOrder;
use PrestaShop\PrestaShop\Adapter\Manufacturer\ManufacturerProductSearchProvider;
class ManufacturerControllerCore extends ProductListingFrontController
{
public $php_self = 'manufacturer';
protected $manufacturer;
private $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_SUPPLIERS')) {
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%', array(
'%brand_name%' => $this->manufacturer->name,
),
'Shop.Theme.Catalog'
);
$this->doProductSearch(
'catalog/listing/manufacturer',
array('entity' => 'manufacturer', 'id' => $this->manufacturer->id)
);
} else {
$this->assignAll();
$this->label = $this->trans(
'List of all brands', array(), 'Shop.Theme.Catalog'
);
$this->setTemplate('catalog/manufacturers', array('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',
array('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(array(
'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',
array('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(array(
'brands' => $manufacturersVar,
));
}
public function getTemplateVarManufacturers()
{
$manufacturers = Manufacturer::getManufacturers(true, $this->context->language->id, true, $this->p, $this->n, false);
$manufacturers_for_display = array();
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', array('%number%' => $manufacturer['nb_products']), 'Shop.Theme.Catalog')) : $this->trans('%number% product', array('%number%' => $manufacturer['nb_products']), 'Shop.Theme.Catalog');
}
return $manufacturers_for_display;
}
public function getListingLabel()
{
return $this->label;
}
}

View File

@@ -0,0 +1,70 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchQuery;
use PrestaShop\PrestaShop\Core\Product\Search\SortOrder;
use PrestaShop\PrestaShop\Adapter\NewProducts\NewProductsProductSearchProvider;
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',
array(),
'Shop.Theme.Catalog'
);
}
}

View File

@@ -0,0 +1,70 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchQuery;
use PrestaShop\PrestaShop\Core\Product\Search\SortOrder;
use PrestaShop\PrestaShop\Adapter\PricesDrop\PricesDropProductSearchProvider;
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',
array(),
'Shop.Theme.Catalog'
);
}
}

View File

@@ -0,0 +1,95 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchQuery;
use PrestaShop\PrestaShop\Core\Product\Search\SortOrder;
use PrestaShop\PrestaShop\Adapter\Search\SearchProductSearchProvider;
class SearchControllerCore extends ProductListingFrontController
{
public $php_self = 'search';
public $instant_search;
public $ajax_search;
private $search_string;
private $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(
array(
'search_string' => $this->search_string,
'search_tag' => $this->search_tag,
)
);
}
/**
* Performs the search.
*/
public function initContent()
{
parent::initContent();
$this->doProductSearch('catalog/listing/search', array('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', array(), 'Shop.Theme.Catalog');
}
}

View File

@@ -0,0 +1,201 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchQuery;
use PrestaShop\PrestaShop\Core\Product\Search\SortOrder;
use PrestaShop\PrestaShop\Adapter\Supplier\SupplierProductSearchProvider;
class SupplierControllerCore extends ProductListingFrontController
{
public $php_self = 'supplier';
/** @var Supplier */
protected $supplier;
private $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%',
array(
'%supplier_name%' => $this->supplier->name,
),
'Shop.Theme.Catalog'
);
$this->doProductSearch(
'catalog/listing/supplier',
array('entity' => 'supplier', 'id' => $this->supplier->id)
);
} else {
$this->assignAll();
$this->label = $this->trans(
'List of all suppliers', array(), 'Shop.Theme.Catalog'
);
$this->setTemplate('catalog/suppliers', array('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',
array('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(array(
'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',
array('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(array(
'brands' => $suppliersVar,
));
}
public function getTemplateVarSuppliers()
{
$suppliers = Supplier::getSuppliers(true, $this->context->language->id, true);
$suppliers_for_display = array();
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', array('%number%' => $supplier['nb_products']), 'Shop.Theme.Catalog')
: $this->trans('%number% product', array('%number%' => $supplier['nb_products']), 'Shop.Theme.Catalog');
}
return $suppliers_for_display;
}
public function getListingLabel()
{
return $this->label;
}
}

View File

@@ -0,0 +1,34 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;