253 lines
9.1 KiB
PHP
253 lines
9.1 KiB
PHP
<?php
|
|
/**
|
|
* NOTICE OF LICENSE
|
|
*
|
|
* This source file is subject to a commercial license from 202 ecommerce
|
|
* Use, copy, modification or distribution of this source file without written
|
|
* license agreement from 202 ecommerce is strictly forbidden.
|
|
*
|
|
* @author 202 ecommerce <contact@202-ecommerce.com>
|
|
* @copyright Copyright (c) 202 ecommerce 2014
|
|
* @license Commercial license
|
|
*
|
|
* Support <support@202-ecommerce.com>
|
|
*/
|
|
|
|
if (!defined('_PS_VERSION_')) {
|
|
die(header('HTTP/1.0 404 Not Found'));
|
|
}
|
|
|
|
class TotLoyaltyAdvancedAccountModuleFrontController extends ModuleFrontController
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->auth = true;
|
|
parent::__construct();
|
|
|
|
$this->context = Context::getContext();
|
|
|
|
include_once($this->module->getLocalPath().'LoyaltyModuleAdvanced.php');
|
|
include_once($this->module->getLocalPath().'LoyaltyStateModuleAdvanced.php');
|
|
|
|
// Declare smarty function to render pagination link
|
|
smartyRegisterFunction(
|
|
$this->context->smarty,
|
|
'function',
|
|
'summarypaginationlink',
|
|
array('TotLoyaltyAdvancedAccountModuleFrontController', 'getSummaryPaginationLink')
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @see FrontController::postProcess()
|
|
*/
|
|
public function postProcess()
|
|
{
|
|
if (Tools::getValue('process') == 'transformpoints') {
|
|
LoyaltyModuleAdvanced::TransformPoints();
|
|
}
|
|
if (Tools::getValue('process') == 'transformpoints1') {
|
|
LoyaltyModuleAdvanced::TransformPoints('cart?action=show');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @see FrontController::initContent()
|
|
*/
|
|
public function initContent()
|
|
{
|
|
parent::initContent();
|
|
|
|
// @TODO put css and js in setMedia()
|
|
// Do we really need this ? I'm pretty sure that cluetip at least is useless.
|
|
$this->context->controller->addJqueryPlugin(array('dimensions', 'cluetip'));
|
|
|
|
if (Tools::getValue('process') == 'summary') {
|
|
$this->assignSummaryExecution();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Render pagination link for summary
|
|
*
|
|
* @param (array) $params Array with to parameters p (for page number) and n (for nb of items per page)
|
|
* @return string link
|
|
*/
|
|
public static function getSummaryPaginationLink($params)
|
|
{
|
|
if (!isset($params['p'])) {
|
|
$p = 1;
|
|
} else {
|
|
$p = $params['p'];
|
|
}
|
|
|
|
if (!isset($params['n'])) {
|
|
$n = 10;
|
|
} else {
|
|
$n = $params['n'];
|
|
}
|
|
|
|
return Context::getContext()->link->getModuleLink(
|
|
'totloyaltyadvanced',
|
|
'account',
|
|
array(
|
|
'process' => 'summary',
|
|
'p' => $p,
|
|
'n' => $n,
|
|
)
|
|
);
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
/**
|
|
* Assign summary template
|
|
*/
|
|
public function assignSummaryExecution()
|
|
{
|
|
$customer_points = (int)LoyaltyModuleAdvanced::getPointsByCustomer((int)$this->context->customer->id);
|
|
$orders = LoyaltyModuleAdvanced::getAllByIdCustomer((int)$this->context->customer->id, (int)$this->context->language->id);
|
|
$displayorders = LoyaltyModuleAdvanced::getAllByIdCustomer(
|
|
(int)$this->context->customer->id,
|
|
(int)$this->context->language->id,
|
|
false,
|
|
true,
|
|
((int)Tools::getValue('n') > 0 ? (int)Tools::getValue('n') : 10),
|
|
((int)Tools::getValue('p') > 0 ? (int)Tools::getValue('p') : 1)
|
|
);
|
|
$this->context->smarty->assign(array(
|
|
'orders' => $orders,
|
|
'displayorders' => $displayorders,
|
|
'totalPoints' => ((int)$customer_points > 0 ? (int)$customer_points : 0),
|
|
'voucher' => Tools::displayPrice(LoyaltyModuleAdvanced::getVoucherValue($customer_points), (int)$this->context->currency->id),
|
|
'validation_id' => LoyaltyStateModuleAdvanced::getValidationId(),
|
|
'transformation_allowed' => $customer_points > 0,
|
|
'currentpage' => ((int)Tools::getValue('p') > 0 ? (int)Tools::getValue('p') : 1),
|
|
'nbpagination' => ((int)Tools::getValue('n') > 0 ? (int)Tools::getValue('n') : 10),
|
|
'nArray' => array(10, 20, 50),
|
|
'max_page' => floor(count($orders) / ((int)Tools::getValue('n') > 0 ? (int)Tools::getValue('n') : 10)),
|
|
'pagination_link' => $this->getSummaryPaginationLink(array('totloyaltyadvanced' => 'account')),
|
|
));
|
|
|
|
/* Discounts */
|
|
$nb_discounts = 0;
|
|
$discounts = array();
|
|
if ($ids_discount = LoyaltyModuleAdvanced::getDiscountByIdCustomer((int)$this->context->customer->id)) {
|
|
$nb_discounts = count($ids_discount);
|
|
foreach ($ids_discount as $key => $discount) {
|
|
$discounts[$key] = new CartRule((int)$discount['id_cart_rule'], (int)$this->context->cookie->id_lang);
|
|
$discounts[$key]->orders = LoyaltyModuleAdvanced::getOrdersByIdDiscount((int)$discount['id_cart_rule']);
|
|
}
|
|
}
|
|
|
|
$all_categories = Category::getSimpleCategories((int)$this->context->cookie->id_lang);
|
|
$voucher_categories = Configuration::get('PS_LOYALTY_VOUCHER_CATEGORY');
|
|
if ($voucher_categories != '' && $voucher_categories != 0) {
|
|
$voucher_categories = explode(',', Configuration::get('PS_LOYALTY_VOUCHER_CATEGORY'));
|
|
} else {
|
|
die(Tools::displayError());
|
|
}
|
|
|
|
if (count($voucher_categories) == count($all_categories)) {
|
|
$categories_names = null;
|
|
} else {
|
|
$categories_names = array();
|
|
foreach ($all_categories as $all_category) {
|
|
if (in_array($all_category['id_category'], $voucher_categories)) {
|
|
$categories_names[$all_category['id_category']] = trim($all_category['name']);
|
|
}
|
|
}
|
|
if (!empty($categories_names)) {
|
|
$categories_names = Tools::truncate(implode(', ', $categories_names), 100).'.';
|
|
} else {
|
|
$categories_names = null;
|
|
}
|
|
}
|
|
$this->context->smarty->assign(array(
|
|
'nbDiscounts' => (int)$nb_discounts,
|
|
'discounts' => $discounts,
|
|
'minimalLoyalty' => (float)Configuration::get('PS_LOYALTY_MINIMAL'),
|
|
'categories' => $categories_names,
|
|
'module_dir1' => _MODULE_DIR_.'totloyaltyadvanced/',
|
|
'temp_dir' => Tools::getHttpHost(true)._THEME_DIR_,
|
|
'baseDir' => Tools::getHttpHost(true).__PS_BASE_URI__,
|
|
));
|
|
|
|
$this->context->controller->addJS(
|
|
'modules/totloyaltyadvanced/views/js/totloyaltyadvanced.js'
|
|
);
|
|
$this->setTemplate('module:totloyaltyadvanced/views/templates/front/loyalty-latest.tpl');
|
|
}
|
|
|
|
/**
|
|
* Set my account breadcrumb links.
|
|
*/
|
|
public function getBreadcrumbLinks()
|
|
{
|
|
$breadcrumb = parent::getBreadcrumbLinks();
|
|
$breadcrumb['links'][] = $this->addMyAccountToBreadcrumb();
|
|
|
|
return $breadcrumb;
|
|
}
|
|
|
|
/**
|
|
* Adds page-customer-account body class.
|
|
*/
|
|
public function getTemplateVarPage()
|
|
{
|
|
$page = parent::getTemplateVarPage();
|
|
$page['body_classes']['page-customer-account'] = true;
|
|
|
|
return $page;
|
|
}
|
|
|
|
/**
|
|
* Returns the layout corresponding to the current page by using the override system
|
|
* Ex:
|
|
* On the url: http://localhost/index.php?id_product=1&controller=product, this method will
|
|
* check if the layout exists in the following files (in that order), and return the first found:
|
|
* - /themes/default/override/layout-product-1.tpl
|
|
* - /themes/default/override/layout-product.tpl
|
|
* - /themes/default/layout.tpl.
|
|
*
|
|
* @since 1.5.0.13
|
|
*
|
|
* @return bool|string
|
|
*/
|
|
public function getLayout()
|
|
{
|
|
$entity = 'module-totloyaltyadvanced-account'; # define our own url
|
|
|
|
$layout = $this->context->shop->theme->getLayoutRelativePathForPage($entity);
|
|
|
|
|
|
if ($overridden_layout = Hook::exec(
|
|
'overrideLayoutTemplate',
|
|
array(
|
|
'default_layout' => $layout,
|
|
'entity' => $entity,
|
|
'locale' => $this->context->language->locale,
|
|
'controller' => $this,
|
|
)
|
|
)) {
|
|
return $overridden_layout;
|
|
}
|
|
|
|
if ((int)Tools::getValue('content_only')) {
|
|
$layout = 'layouts/layout-content-only.tpl';
|
|
}
|
|
|
|
return $layout;
|
|
}
|
|
}
|