[*] classes : new module architecture
This commit is contained in:
+25
-22
@@ -28,21 +28,24 @@
|
||||
/**
|
||||
* @since 1.5.0
|
||||
*/
|
||||
|
||||
include_once(dirname(__FILE__).'/LoyaltyModule.php');
|
||||
include_once(dirname(__FILE__).'/LoyaltyStateModule.php');
|
||||
|
||||
class ModuleLoyaltyController extends ModuleController
|
||||
class LoyaltyDefaultModuleFrontController extends ModuleFrontController
|
||||
{
|
||||
protected $page_name = 'module-loyalty-loyalty-program';
|
||||
public $display_column_left = false;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
include_once($this->module->getLocalPath().'LoyaltyModule.php');
|
||||
include_once($this->module->getLocalPath().'LoyaltyStateModule.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* @see FrontController::postProcess()
|
||||
*/
|
||||
public function postProcess()
|
||||
{
|
||||
$this->display_column_left = false;
|
||||
if ($this->process == 'transformpoints')
|
||||
if (Tools::getValue('process') == 'transformpoints')
|
||||
$this->processTransformPoints();
|
||||
}
|
||||
|
||||
@@ -51,16 +54,16 @@ class ModuleLoyaltyController extends ModuleController
|
||||
*/
|
||||
public function processTransformPoints()
|
||||
{
|
||||
$customerPoints = (int)(LoyaltyModule::getPointsByCustomer((int)($this->context->customer->id)));
|
||||
$customerPoints = (int)LoyaltyModule::getPointsByCustomer((int)$this->context->customer->id);
|
||||
if ($customerPoints > 0)
|
||||
{
|
||||
/* Generate a voucher code */
|
||||
$voucherCode = NULL;
|
||||
$voucherCode = null;
|
||||
do
|
||||
$voucherCode = 'FID'.rand(1000, 100000);
|
||||
while (CartRule::cartRuleExists($voucherCode));
|
||||
|
||||
/* Voucher creation and affectation to the customer */
|
||||
// Voucher creation and affectation to the customer
|
||||
$cartRule = new CartRule();
|
||||
$cartRule->code = $voucherCode;
|
||||
$cartRule->id_customer = (int)$this->context->cookie->id_customer;
|
||||
@@ -69,7 +72,7 @@ class ModuleLoyaltyController extends ModuleController
|
||||
$cartRule->quantity = 1;
|
||||
$cartRule->quantity_per_user = 1;
|
||||
|
||||
/* If merchandise returns are allowed, the voucher musn't be usable before this max return date */
|
||||
// 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
|
||||
@@ -86,7 +89,7 @@ class ModuleLoyaltyController extends ModuleController
|
||||
$cartRule->active = 1;
|
||||
|
||||
$categories = Configuration::get('PS_LOYALTY_VOUCHER_CATEGORY');
|
||||
if ($categories != '' AND $categories != 0)
|
||||
if ($categories != '' && $categories != 0)
|
||||
$categories = explode(',', Configuration::get('PS_LOYALTY_VOUCHER_CATEGORY'));
|
||||
else
|
||||
die (Tools::displayError());
|
||||
@@ -94,21 +97,21 @@ class ModuleLoyaltyController extends ModuleController
|
||||
$languages = Language::getLanguages(true);
|
||||
$default_text = Configuration::get('PS_LOYALTY_VOUCHER_DETAILS', (int)Configuration::get('PS_LANG_DEFAULT'));
|
||||
|
||||
foreach ($languages AS $language)
|
||||
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))
|
||||
if (is_array($categories) && count($categories))
|
||||
$cartRule->add(true, false, $categories);
|
||||
else
|
||||
$cartRule->add();
|
||||
|
||||
/* Register order(s) which contributed to create this voucher */
|
||||
// Register order(s) which contributed to create this voucher
|
||||
LoyaltyModule::registerDiscount($cartRule);
|
||||
|
||||
Tools::redirect($this->context->link->getModuleLink('loyalty', 'summary'));
|
||||
Tools::redirect($this->context->link->getModuleLink('loyalty', 'default'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,7 +123,7 @@ class ModuleLoyaltyController extends ModuleController
|
||||
parent::initContent();
|
||||
$this->context->controller->addJqueryPlugin(array('dimensions', 'cluetip'));
|
||||
|
||||
if ($this->process == 'summary')
|
||||
if (Tools::getValue('process') == 'summary')
|
||||
$this->assignSummaryExecution();
|
||||
}
|
||||
|
||||
@@ -135,7 +138,7 @@ class ModuleLoyaltyController extends ModuleController
|
||||
$this->context->smarty->assign(array(
|
||||
'orders' => $orders,
|
||||
'displayorders' => $displayorders,
|
||||
'pagination_link' => $this->context->link->getModuleLink('loyalty', 'summary'),
|
||||
'pagination_link' => $this->context->link->getModuleLink('loyalty', 'default'),
|
||||
'totalPoints' => (int)$customerPoints,
|
||||
'voucher' => LoyaltyModule::getVoucherValue($customerPoints, (int)($this->context->cookie->id_currency)),
|
||||
'validation_id' => LoyaltyStateModule::getValidationId(),
|
||||
@@ -152,7 +155,7 @@ class ModuleLoyaltyController extends ModuleController
|
||||
if ($ids_discount = LoyaltyModule::getDiscountByIdCustomer((int)$this->context->cookie->id_customer))
|
||||
{
|
||||
$nbDiscounts = count($ids_discount);
|
||||
foreach ($ids_discount AS $key => $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']);
|
||||
@@ -161,12 +164,12 @@ class ModuleLoyaltyController extends ModuleController
|
||||
|
||||
$allCategories = Category::getSimpleCategories((int)($this->context->cookie->id_lang));
|
||||
$voucherCategories = Configuration::get('PS_LOYALTY_VOUCHER_CATEGORY');
|
||||
if ($voucherCategories != '' AND $voucherCategories != 0)
|
||||
if ($voucherCategories != '' && $voucherCategories != 0)
|
||||
$voucherCategories = explode(',', Configuration::get('PS_LOYALTY_VOUCHER_CATEGORY'));
|
||||
else
|
||||
die(Tools::displayError());
|
||||
|
||||
if (sizeof($voucherCategories) == sizeof($allCategories))
|
||||
if (count($voucherCategories) == count($allCategories))
|
||||
$categoriesNames = null;
|
||||
else
|
||||
{
|
||||
@@ -24,12 +24,6 @@ $_MODULE['<{loyalty}prestashop>loyalty_bafd7322c6e97d25b6299b5d6fe8920b'] = 'Non
|
||||
$_MODULE['<{loyalty}prestashop>loyalty_ade45d72ab6ba1ab576d8b9deb0c2438'] = 'Points attribués au statut suivant';
|
||||
$_MODULE['<{loyalty}prestashop>loyalty_9611a682e61c503c32e2dc58fdbc8ddf'] = 'Points annulés au statut suivant';
|
||||
$_MODULE['<{loyalty}prestashop>loyalty_2a46cccdea2f18fdfdfacf99a98b758d'] = 'Les bons de réductions crées par le système de fidélité peuvent être utilisés dans les catégories d\'articles suivantes :';
|
||||
$_MODULE['<{loyalty}prestashop>loyalty_8cf04a9734132302f96da8e113e80ce5'] = 'Accueil';
|
||||
$_MODULE['<{loyalty}prestashop>loyalty_ef7de3f485174ff47f061ad27d83d0ee'] = 'sélectionné';
|
||||
$_MODULE['<{loyalty}prestashop>loyalty_b56c3bda503a8dc4be356edb0cc31793'] = 'Réduire tout';
|
||||
$_MODULE['<{loyalty}prestashop>loyalty_5ffd7a335dd836b3373f5ec570a58bdc'] = 'Ouvrir tout';
|
||||
$_MODULE['<{loyalty}prestashop>loyalty_5e9df908eafa83cb51c0a3720e8348c7'] = 'Cocher tout';
|
||||
$_MODULE['<{loyalty}prestashop>loyalty_9747d23c8cc358c5ef78c51e59cd6817'] = 'Décocher tout';
|
||||
$_MODULE['<{loyalty}prestashop>loyalty_c2a7db7dec4de1bdb143ccd790f5a62c'] = 'Cocher pour quelle(s) catégorie(s) seront utilisables les bons de réductions fidélité';
|
||||
$_MODULE['<{loyalty}prestashop>loyalty_30e793698766edbaaf84a74d4c377f72'] = 'Statuts des points de fidélité';
|
||||
$_MODULE['<{loyalty}prestashop>loyalty_4f2a91e15af2631ff9424564b8a45fb2'] = 'Initial';
|
||||
@@ -84,6 +78,7 @@ $_MODULE['<{loyalty}prestashop>loyalty_a16cf3ec5200cc519f4fe48e34b1df83'] = 'Le
|
||||
$_MODULE['<{loyalty}prestashop>loyalty_8e69341aca5dbf9f55c2e75a2ed5df3c'] = 'Aucun bon de réduction pour le moment.';
|
||||
$_MODULE['<{loyalty}prestashop>loyalty_00d56a5e37c19c59d521530fc8e7f337'] = 'Aucun point de fidélité pour le moment.';
|
||||
$_MODULE['<{loyalty}prestashop>loyalty_0b3db27bc15f682e92ff250ebb167d4b'] = 'Retour à votre compte';
|
||||
$_MODULE['<{loyalty}prestashop>loyalty_8cf04a9734132302f96da8e113e80ce5'] = 'Accueil';
|
||||
$_MODULE['<{loyalty}prestashop>my-account_c540093e64d84440025b2d8201f04336'] = 'Mes points de fidélité';
|
||||
$_MODULE['<{loyalty}prestashop>product_08ef6b34ab8e7039ef0ee69378f0ac0b'] = 'En achetant ce produit vous pouvez gagner jusqu\'à ';
|
||||
$_MODULE['<{loyalty}prestashop>product_2996152bb442bf98c80c515c6055de5f'] = 'points de fidélité';
|
||||
|
||||
@@ -124,7 +124,7 @@
|
||||
|
||||
{if $transformation_allowed}
|
||||
<p style="text-align:center; margin-top:20px">
|
||||
<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>
|
||||
<a href="{$link->getModuleLink('loyalty', 'default', ['process' => '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}
|
||||
|
||||
+1
-1
@@ -25,5 +25,5 @@
|
||||
*}
|
||||
|
||||
<!-- MODULE Loyalty -->
|
||||
<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>
|
||||
<li class="loyalty"><a href="{$link->getModuleLink('loyalty', 'default', ['process' => '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