143 lines
4.9 KiB
PHP
143 lines
4.9 KiB
PHP
<?php
|
|
/**
|
|
* 2007-2016 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 202 ecommerce <contact@202-ecommerce.com>
|
|
* @copyright Copyright (c) 202 ecommerce 2014
|
|
* @license Commercial license
|
|
*/
|
|
|
|
if (!defined('_PS_VERSION_')) {
|
|
exit;
|
|
}
|
|
|
|
class TotLoyaltyState extends ObjectModel
|
|
{
|
|
public $name;
|
|
public $id_order_state;
|
|
|
|
/**
|
|
* @see ObjectModel::$definition
|
|
*/
|
|
public static $definition = array(
|
|
'table' => 'totloyalty_state',
|
|
'primary' => 'id_loyalty_state',
|
|
'multilang' => true,
|
|
'fields' => array(
|
|
'id_order_state' => array('type' => self::TYPE_INT, 'validate' => 'isInt'),
|
|
// Lang fields
|
|
'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 128),
|
|
),
|
|
);
|
|
|
|
public static function getDefaultId()
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
public static function getValidationId()
|
|
{
|
|
return 2;
|
|
}
|
|
|
|
public static function getCancelId()
|
|
{
|
|
return 3;
|
|
}
|
|
|
|
public static function getConvertId()
|
|
{
|
|
return 4;
|
|
}
|
|
|
|
public static function getNoneAwardId()
|
|
{
|
|
return 5;
|
|
}
|
|
|
|
public static function insertDefaultData($id_lang = 0)
|
|
{
|
|
$result = true;
|
|
$loyaltyModule = new totloyaltyadvanced();
|
|
if ($id_lang == 0) {
|
|
$languages = Language::getLanguages();
|
|
} else {
|
|
if (false == ($lang = Language::getLanguage($id_lang))) {
|
|
# if false, it's mean that prestashop cache is not clear, so we force that with Language::loadLanguages
|
|
Language::loadLanguages();
|
|
$lang = Language::getLanguage($id_lang);
|
|
}
|
|
$languages = array($lang);
|
|
}
|
|
|
|
$defaultTranslations = array(
|
|
'default' => array(
|
|
'id_loyalty_state' => (int)TotLoyaltyState::getDefaultId(),
|
|
'default' => $loyaltyModule->getL('Awaiting validation'),
|
|
'en' => 'Awaiting validation',
|
|
'fr' => 'En attente de validation'),
|
|
'validated' => array(
|
|
'id_loyalty_state' => (int)TotLoyaltyState::getValidationId(),
|
|
'id_order_state' => Configuration::get('PS_OS_DELIVERED'),
|
|
'default' => $loyaltyModule->getL('Available'),
|
|
'en' => 'Available',
|
|
'fr' => 'Disponible',
|
|
),
|
|
'cancelled' => array(
|
|
'id_loyalty_state' => (int)TotLoyaltyState::getCancelId(),
|
|
'id_order_state' => Configuration::get('PS_OS_CANCELED'),
|
|
'default' => $loyaltyModule->getL('Cancelled'),
|
|
'en' => 'Cancelled',
|
|
'fr' => 'Annulés',
|
|
),
|
|
'converted' => array(
|
|
'id_loyalty_state' => (int)TotLoyaltyState::getConvertId(),
|
|
'default' => $loyaltyModule->getL('Already converted'),
|
|
'en' => 'Already converted',
|
|
'fr' => 'Déjà convertis',
|
|
),
|
|
'none_award' => array(
|
|
'id_loyalty_state' => (int)TotLoyaltyState::getNoneAwardId(),
|
|
'default' => $loyaltyModule->getL('Unavailable on discounts'),
|
|
'en' => 'Unavailable on discounts',
|
|
'fr' => 'Non disponbile sur produits remisés',
|
|
),
|
|
);
|
|
|
|
foreach ($defaultTranslations as $loyaltyState) {
|
|
$state = new TotLoyaltyState((int)$loyaltyState['id_loyalty_state']);
|
|
|
|
if (isset($loyaltyState['id_order_state'])) {
|
|
$state->id_order_state = (int)$loyaltyState['id_order_state'];
|
|
}
|
|
|
|
foreach ($languages as $language) {
|
|
if (isset($loyaltyState[$language['iso_code']])) {
|
|
$state->name[(int)$language['id_lang']] = $loyaltyState[$language['iso_code']];
|
|
} else {
|
|
$state->name[(int)$language['id_lang']] = $loyaltyState['default'];
|
|
}
|
|
}
|
|
$result &= $state->save();
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
}
|