[-] MO : #PSTEST-280 - Removed old-way method (deprecated) + fixed problem with cartRules
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@12207 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
@@ -53,6 +53,8 @@ class FrontControllerCore extends Controller
|
||||
public $display_column_right = true;
|
||||
|
||||
public static $initialized = false;
|
||||
|
||||
protected $page_name = null;
|
||||
|
||||
protected static $currentCustomerGroups;
|
||||
|
||||
@@ -235,7 +237,9 @@ class FrontControllerCore extends Controller
|
||||
|
||||
// Are we in a payment module
|
||||
$module_name = Tools::getValue('module');
|
||||
if (Tools::getValue('controller') == 'module' && $module_name != '' && new $module_name() instanceof PaymentModule)
|
||||
if (!is_null($this->page_name))
|
||||
$page_name = $this->page_name;
|
||||
else if (Tools::getValue('controller') == 'module' && $module_name != '' && new $module_name() instanceof PaymentModule)
|
||||
$page_name = 'module-payment-submit';
|
||||
// Are we in a module
|
||||
else if (preg_match('#^'.preg_quote($this->context->shop->getPhysicalURI(), '#').'modules/([a-zA-Z0-9_-]+?)/(.*)$#', $_SERVER['REQUEST_URI'], $m))
|
||||
|
||||
@@ -35,6 +35,8 @@ include_once(dirname(__FILE__).'/LoyaltyModule.php');
|
||||
include_once(dirname(__FILE__).'/LoyaltyStateModule.php');
|
||||
include_once(dirname(__FILE__).'/loyalty.php');
|
||||
|
||||
Tools::displayFileAsDeprecated();
|
||||
|
||||
$context = Context::getContext();
|
||||
if (!$context->customer->isLogged())
|
||||
Tools::redirect('index.php?controller=authentication&back=modules/loyalty/loyalty-program.php');
|
||||
@@ -98,7 +100,7 @@ if (Tools::getValue('transform-points') == 'true' AND $customerPoints > 0)
|
||||
$cartRule->add();
|
||||
|
||||
/* Register order(s) which contributed to create this voucher */
|
||||
LoyaltyModule::registerDiscount($voucher);
|
||||
LoyaltyModule::registerDiscount($cartRule);
|
||||
|
||||
Tools::redirect('modules/loyalty/loyalty-program.php');
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@
|
||||
|
||||
{if $transformation_allowed}
|
||||
<p style="text-align:center; margin-top:20px">
|
||||
<a href="{$base_dir}modules/loyalty/loyalty-program.php?transform-points=true" onclick="return confirm('{l s='Are you sure you want to transform your points into vouchers?' mod='loyalty' js=1}');">{l s='Transform my points into a voucher of' mod='loyalty'} <span class="price">{convertPrice price=$voucher}</span>.</a>
|
||||
<a href="{$link->getModuleLink('loyalty', 'transformpoints')}" onclick="return confirm('{l s='Are you sure you want to transform your points into vouchers?' mod='loyalty' js=1}');">{l s='Transform my points into a voucher of' mod='loyalty'} <span class="price">{convertPrice price=$voucher}</span>.</a>
|
||||
</p>
|
||||
{/if}
|
||||
|
||||
@@ -149,14 +149,14 @@
|
||||
{foreach from=$discounts item=discount name=myLoop}
|
||||
<tr class="alternate_item">
|
||||
<td class="history_date">{dateFormat date=$discount->date_add}</td>
|
||||
<td class="history_price"><span class="price">{if $discount->id_discount_type == 1}
|
||||
{$discount->value}%
|
||||
{elseif $discount->id_discount_type == 2}
|
||||
{displayPrice price=$discount->value currency=$discount->id_currency}
|
||||
<td class="history_price"><span class="price">{if $discount->reduction_percent > 0}
|
||||
{$discount->reduction_percent}%
|
||||
{elseif $discount->reduction_amount}
|
||||
{displayPrice price=$discount->reduction_amount currency=$discount->reduction_currency}
|
||||
{else}
|
||||
{l s='Free shipping' mod='loyalty'}
|
||||
{/if}</span></td>
|
||||
<td class="history_method bold">{$discount->name}</td>
|
||||
<td class="history_method bold">{$discount->code}</td>
|
||||
<td class="history_date">{dateFormat date=$discount->date_from}</td>
|
||||
<td class="history_date">{dateFormat date=$discount->date_to}</td>
|
||||
<td class="history_method bold">{if $discount->quantity > 0}{l s='To use' mod='loyalty'}{else}{l s='Used' mod='loyalty'}{/if}</td>
|
||||
|
||||
@@ -0,0 +1,190 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2011 PrestaShop SA
|
||||
* @version Release: $Revision$
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @since 1.5.0
|
||||
*/
|
||||
|
||||
include_once(dirname(__FILE__).'/LoyaltyModule.php');
|
||||
include_once(dirname(__FILE__).'/LoyaltyStateModule.php');
|
||||
|
||||
class ModuleLoyaltyController extends ModuleController
|
||||
{
|
||||
protected $page_name = 'module-loyalty-loyalty-program';
|
||||
|
||||
/**
|
||||
* @see FrontController::postProcess()
|
||||
*/
|
||||
public function postProcess()
|
||||
{
|
||||
$this->display_column_left = false;
|
||||
if ($this->process == 'transformpoints')
|
||||
$this->processTransformPoints();
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform loyalty point to a voucher
|
||||
*/
|
||||
public function processTransformPoints()
|
||||
{
|
||||
$customerPoints = (int)(LoyaltyModule::getPointsByCustomer((int)($this->context->customer->id)));
|
||||
if ($customerPoints > 0)
|
||||
{
|
||||
/* Generate a voucher code */
|
||||
$voucherCode = NULL;
|
||||
do
|
||||
$voucherCode = 'FID'.rand(1000, 100000);
|
||||
while (CartRule::cartRuleExists($voucherCode));
|
||||
|
||||
/* Voucher creation and affectation to the customer */
|
||||
$cartRule = new CartRule();
|
||||
$cartRule->code = $voucherCode;
|
||||
$cartRule->id_customer = (int)$this->context->cookie->id_customer;
|
||||
$cartRule->id_currency = (int)$this->context->cookie->id_currency;
|
||||
$cartRule->reduction_amount = LoyaltyModule::getVoucherValue((int)$customerPoints);
|
||||
$cartRule->quantity = 1;
|
||||
$cartRule->quantity_per_user = 1;
|
||||
|
||||
/* If merchandise returns are allowed, the voucher musn't be usable before this max return date */
|
||||
$dateFrom = Db::getInstance()->getValue('
|
||||
SELECT UNIX_TIMESTAMP(date_add) n
|
||||
FROM '._DB_PREFIX_.'loyalty
|
||||
WHERE id_cart_rule = 0 AND id_customer = '.(int)$this->context->cookie->id_customer.'
|
||||
ORDER BY date_add DESC');
|
||||
|
||||
if (Configuration::get('PS_ORDER_RETURN'))
|
||||
$dateFrom += 60 * 60 * 24 * (int)Configuration::get('PS_ORDER_RETURN_NB_DAYS');
|
||||
|
||||
$cartRule->date_from = date('Y-m-d H:i:s', $dateFrom);
|
||||
$cartRule->date_to = date('Y-m-d H:i:s', $dateFrom + 31536000); // + 1 year
|
||||
|
||||
$cartRule->minimum_amount = (float)Configuration::get('PS_LOYALTY_MINIMAL');
|
||||
$cartRule->active = 1;
|
||||
|
||||
$categories = Configuration::get('PS_LOYALTY_VOUCHER_CATEGORY');
|
||||
if ($categories != '' AND $categories != 0)
|
||||
$categories = explode(',', Configuration::get('PS_LOYALTY_VOUCHER_CATEGORY'));
|
||||
else
|
||||
die (Tools::displayError());
|
||||
|
||||
$languages = Language::getLanguages(true);
|
||||
$default_text = Configuration::get('PS_LOYALTY_VOUCHER_DETAILS', (int)Configuration::get('PS_LANG_DEFAULT'));
|
||||
|
||||
foreach ($languages AS $language)
|
||||
{
|
||||
$text = Configuration::get('PS_LOYALTY_VOUCHER_DETAILS', (int)$language['id_lang']);
|
||||
$cartRule->name[(int)$language['id_lang']] = $text ? strval($text) : strval($default_text);
|
||||
}
|
||||
|
||||
if (is_array($categories) AND sizeof($categories))
|
||||
$cartRule->add(true, false, $categories);
|
||||
else
|
||||
$cartRule->add();
|
||||
|
||||
/* Register order(s) which contributed to create this voucher */
|
||||
LoyaltyModule::registerDiscount($cartRule);
|
||||
|
||||
Tools::redirect($this->context->link->getModuleLink('loyalty', 'summary'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see FrontController::initContent()
|
||||
*/
|
||||
public function initContent()
|
||||
{
|
||||
parent::initContent();
|
||||
$this->context->controller->addJqueryPlugin(array('dimensions', 'cluetip'));
|
||||
|
||||
if ($this->process == 'summary')
|
||||
$this->assignSummaryExecution();
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign summary template
|
||||
*/
|
||||
public function assignSummaryExecution()
|
||||
{
|
||||
$customerPoints = (int)(LoyaltyModule::getPointsByCustomer((int)($this->context->customer->id)));
|
||||
$orders = LoyaltyModule::getAllByIdCustomer((int)($this->context->cookie->id_customer), (int)($this->context->cookie->id_lang));
|
||||
$displayorders = LoyaltyModule::getAllByIdCustomer((int)($this->context->cookie->id_customer), (int)($this->context->cookie->id_lang), 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,
|
||||
'pagination_link' => $this->context->link->getModuleLink('loyalty', 'summary'),
|
||||
'totalPoints' => (int)$customerPoints,
|
||||
'voucher' => LoyaltyModule::getVoucherValue($customerPoints, (int)($this->context->cookie->id_currency)),
|
||||
'validation_id' => LoyaltyStateModule::getValidationId(),
|
||||
'transformation_allowed' => $customerPoints > 0,
|
||||
'page' => ((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(sizeof($orders) / ((int)(Tools::getValue('n') > 0) ? (int)(Tools::getValue('n')) : 10))
|
||||
));
|
||||
|
||||
/* Discounts */
|
||||
$nbDiscounts = 0;
|
||||
$discounts = array();
|
||||
if ($ids_discount = LoyaltyModule::getDiscountByIdCustomer((int)$this->context->cookie->id_customer))
|
||||
{
|
||||
$nbDiscounts = 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 = LoyaltyModule::getOrdersByIdDiscount((int)$discount['id_cart_rule']);
|
||||
}
|
||||
}
|
||||
|
||||
$allCategories = Category::getSimpleCategories((int)($this->context->cookie->id_lang));
|
||||
$voucherCategories = Configuration::get('PS_LOYALTY_VOUCHER_CATEGORY');
|
||||
if ($voucherCategories != '' AND $voucherCategories != 0)
|
||||
$voucherCategories = explode(',', Configuration::get('PS_LOYALTY_VOUCHER_CATEGORY'));
|
||||
else
|
||||
die(Tools::displayError());
|
||||
|
||||
if (sizeof($voucherCategories) == sizeof($allCategories))
|
||||
$categoriesNames = null;
|
||||
else
|
||||
{
|
||||
$categoriesNames = array();
|
||||
foreach ($allCategories AS $k => $allCategory)
|
||||
if (in_array($allCategory['id_category'], $voucherCategories))
|
||||
$categoriesNames[$allCategory['id_category']] = trim($allCategory['name']);
|
||||
if (!empty($categoriesNames))
|
||||
$categoriesNames = Tools::truncate(implode(', ', $categoriesNames), 100).'.';
|
||||
else
|
||||
$categoriesNames = null;
|
||||
}
|
||||
$this->context->smarty->assign(array(
|
||||
'nbDiscounts' => (int)$nbDiscounts,
|
||||
'discounts' => $discounts,
|
||||
'minimalLoyalty' => (float)Configuration::get('PS_LOYALTY_MINIMAL'),
|
||||
'categories' => $categoriesNames));
|
||||
|
||||
$this->setTemplate('loyalty.tpl');
|
||||
}
|
||||
}
|
||||
@@ -25,5 +25,5 @@
|
||||
*}
|
||||
|
||||
<!-- MODULE Loyalty -->
|
||||
<li class="loyalty"><a href="{$base_dir_ssl}modules/loyalty/loyalty-program.php" title="{l s='My loyalty points' mod='loyalty'}"><img src="{$module_template_dir}images/loyalty.gif" alt="{l s='My loyalty points' mod='loyalty'}" class="icon" /> {l s='My loyalty points' mod='loyalty'}</a></li>
|
||||
<li class="loyalty"><a href="{$link->getModuleLink('loyalty', 'summary')}" title="{l s='My loyalty points' mod='loyalty'}"><img src="{$module_template_dir}images/loyalty.gif" alt="{l s='My loyalty points' mod='loyalty'}" class="icon" /> {l s='My loyalty points' mod='loyalty'}</a></li>
|
||||
<!-- END : MODULE Loyalty -->
|
||||
Reference in New Issue
Block a user