/**
 * Upgrades the module to version 1.3.0.
 *
 * Purges existing nosto configs.
 * Removes unused config variables.
 * Registers new hooks.
 * Un-register left/right column hooks.
 *
 * @param NostoTagging $object
 * @return bool
 */
function upgrade_module_1_3_0($object)
{
    // Purge the nosto configs the plugin have created so far and reload the config.
    $config_table = _DB_PREFIX_ . 'configuration';
    $config_lang_table = $config_table . '_lang';
    Db::getInstance()->execute('
			DELETE `' . $config_lang_table . '` FROM `' . $config_lang_table . '`
			LEFT JOIN `' . $config_table . '`
			ON `' . $config_lang_table . '`.`id_configuration` = `' . $config_table . '`.`id_configuration`
			WHERE `' . $config_table . '`.`name` LIKE "NOSTOTAGGING_%"');
    Db::getInstance()->execute('
			DELETE FROM `' . $config_table . '`
			WHERE `' . $config_table . '`.`name` LIKE "NOSTOTAGGING_%"');
    Configuration::loadConfiguration();
    // Backward compatibility
    if (_PS_VERSION_ < '1.5') {
        $object->registerHook('header');
        $object->registerHook('top');
        $object->registerHook('footer');
        $object->registerHook('productfooter');
        $object->registerHook('shoppingCart');
        $object->registerHook('orderConfirmation');
        $object->registerHook('paymentConfirm');
        $object->registerHook('paymentTop');
        $object->registerHook('home');
        $object->registerHook('updateproduct');
        $object->registerHook('deleteproduct');
        $object->registerHook('updateQuantity');
    } else {
        $object->registerHook('actionObjectUpdateAfter');
    }
    $object->unregisterHook('displayLeftColumn');
    $object->unregisterHook('displayRightColumn');
    return true;
}
 public static function loadConfiguration()
 {
     ConfigurationKPI::setKpiDefinition();
     $r = parent::loadConfiguration();
     ConfigurationKPI::unsetKpiDefinition();
     return $r;
 }
Example #3
0
 public function initializeContext()
 {
     global $smarty;
     // Clean all cache values
     Cache::clean('*');
     Context::getContext()->shop = new Shop(1);
     Shop::setContext(Shop::CONTEXT_SHOP, 1);
     Configuration::loadConfiguration();
     if (!isset(Context::getContext()->language) || !Validate::isLoadedObject(Context::getContext()->language)) {
         if ($id_lang = (int) Configuration::get('PS_LANG_DEFAULT')) {
             Context::getContext()->language = new Language($id_lang);
         }
     }
     if (!isset(Context::getContext()->country) || !Validate::isLoadedObject(Context::getContext()->country)) {
         if ($id_country = (int) Configuration::get('PS_COUNTRY_DEFAULT')) {
             Context::getContext()->country = new Country((int) $id_country);
         }
     }
     if (!isset(Context::getContext()->currency) || !Validate::isLoadedObject(Context::getContext()->currency)) {
         if ($id_currency = (int) Configuration::get('PS_CURRENCY_DEFAULT')) {
             Context::getContext()->currency = new Currency((int) $id_currency);
         }
     }
     Context::getContext()->cart = new Cart();
     Context::getContext()->employee = new Employee(1);
     if (!defined('_PS_SMARTY_FAST_LOAD_')) {
         define('_PS_SMARTY_FAST_LOAD_', true);
     }
     require_once _PS_ROOT_DIR_ . '/config/smarty.config.inc.php';
     Context::getContext()->smarty = $smarty;
 }
Example #4
0
 public function init()
 {
     define('_PS_ADMIN_DIR_', getcwd());
     // Load Presta Configuration
     Configuration::loadConfiguration();
     Context::getContext()->link = new Link();
     $this->confirm();
 }
Example #5
0
 public static function generateHtaccess($path = null, $rewrite_settings = null, $cache_control = null, $specific = '', $disable_multiviews = null, $medias = false, $disable_modsec = null)
 {
     if (Module::isInstalled('agilemultipleseller')) {
         AgileSellerManager::ensure_configuration_record_for_all_shops();
         Configuration::loadConfiguration();
         return self::generateHtaccess_override($path, $rewrite_settings, $cache_control, $specific, $disable_multiviews, $medias, $disable_modsec, $disable_modsec);
     }
     return parent::generateHtaccess($path, $rewrite_settings, $cache_control, $specific, $disable_multiviews, $medias, $disable_modsec);
 }
function update_module_followup()
{
    Configuration::loadConfiguration();
    $followup = Module::getInstanceByName('followup');
    if (!$followup->id) {
        return;
    }
    Db::getInstance()->Execute('ALTER TABLE `' . _DB_PREFIX_ . 'log_email` ADD INDEX `date_add`(`date_add`), ADD INDEX `id_cart`(`id_cart`);');
}
function alter_productcomments_guest_index()
{
    Configuration::loadConfiguration();
    $productcomments = Module::getInstanceByName('productcomments');
    if (!$productcomments->id) {
        return;
    }
    DB::getInstance()->Execute('
	ALTER TABLE `' . _DB_PREFIX_ . 'product_comment`
	DROP INDEX `id_guest`, ADD INDEX `id_guest` (`id_guest`);');
}
Example #8
0
 /**
  * Creates a new backup object
  *
  * @param string $filename Filename of the backup file
  */
 public function __construct($filename = NULL)
 {
     if ($filename) {
         $this->id = $this->getRealBackupPath($filename);
     }
     Configuration::loadConfiguration();
     $psBackupAll = Configuration::get('PS_BACKUP_ALL');
     $psBackupDropTable = Configuration::get('PS_BACKUP_DROP_TABLE');
     $this->psBackupAll = $psBackupAll !== false ? $psBackupAll : true;
     $this->psBackupDropTable = $psBackupDropTable !== false ? $psBackupDropTable : true;
 }
Example #9
0
 public function initializeContext()
 {
     global $smarty;
     Context::getContext()->shop = new Shop(1);
     Shop::setContext(Shop::CONTEXT_SHOP, 1);
     Configuration::loadConfiguration();
     Context::getContext()->language = new Language(Configuration::get('PS_LANG_DEFAULT'));
     Context::getContext()->country = new Country('PS_COUNTRY_DEFAULT');
     Context::getContext()->cart = new Cart();
     define('_PS_SMARTY_FAST_LOAD_', true);
     require_once _PS_ROOT_DIR_ . '/config/smarty.config.inc.php';
     Context::getContext()->smarty = $smarty;
 }
Example #10
0
function update_modules_sql()
{
    Configuration::loadConfiguration();
    $blocklink = Module::getInstanceByName('blocklink');
    if ($blocklink->id) {
        Db::getInstance()->Execute('ALTER IGNORE TABLE `' . _DB_PREFIX_ . 'blocklink_lang` ADD PRIMARY KEY (`id_link`, `id_lang`);');
    }
    $productComments = Module::getInstanceByName('productcomments');
    if ($productComments->id) {
        Db::getInstance()->Execute('ALTER IGNORE TABLE `' . _DB_PREFIX_ . 'product_comment_grade` ADD PRIMARY KEY (`id_product_comment`, `id_product_comment_criterion`);');
        Db::getInstance()->Execute('ALTER IGNORE TABLE `' . _DB_PREFIX_ . 'product_comment_criterion` DROP PRIMARY KEY, ADD PRIMARY KEY (`id_product_comment_criterion`, `id_lang`);');
        Db::getInstance()->Execute('ALTER IGNORE TABLE `' . _DB_PREFIX_ . 'product_comment_criterion_product` ADD PRIMARY KEY(`id_product`, `id_product_comment_criterion`);');
    }
}
function invoice_number_set()
{
    Configuration::loadConfiguration();
    $number = 1;
    // Update each order with a number
    $result = Db::getInstance()->ExecuteS('
	SELECT id_order
	FROM ' . _DB_PREFIX_ . 'orders
	ORDER BY id_order');
    foreach ($result as $row) {
        $order = new Order((int) $row['id_order']);
        $history = $order->getHistory(false);
        foreach ($history as $row2) {
            $oS = new OrderState((int) $row2['id_order_state'], (int) Configuration::get('PS_LANG_DEFAULT'));
            if ($oS->invoice) {
                Db::getInstance()->Execute('UPDATE ' . _DB_PREFIX_ . 'orders SET invoice_number = ' . (int) $number++ . ', `invoice_date` = `date_add` WHERE id_order = ' . (int) $order->id);
                break;
            }
        }
    }
    // Add configuration var
    Configuration::updateValue('PS_INVOICE_NUMBER', (int) $number);
}
Example #12
0
function delivery_number_set()
{
    Configuration::loadConfiguration();
    $number = 1;
    // Update each order with a number
    $result = Db::getInstance()->ExecuteS('
	SELECT id_order
	FROM ' . _DB_PREFIX_ . 'orders
	ORDER BY id_order');
    foreach ($result as $row) {
        $order = new Order(intval($row['id_order']));
        $history = $order->getHistory(false);
        foreach ($history as $row2) {
            $oS = new OrderState(intval($row2['id_order_state']));
            if ($oS->delivery) {
                Db::getInstance()->Execute('UPDATE ' . _DB_PREFIX_ . 'orders SET delivery_number = ' . intval($number++) . ', `delivery_date` = `date_add` WHERE id_order = ' . intval($order->id));
                break;
            }
        }
    }
    // Add configuration var
    Configuration::updateValue('PS_DELIVERY_NUMBER', intval($number));
}
Example #13
0
 /**
  * PROCESS : configureShop
  * Set default shop configuration
  */
 public function configureShop(array $data = array())
 {
     //clear image cache in tmp folder
     if (file_exists(_PS_TMP_IMG_DIR_)) {
         foreach (scandir(_PS_TMP_IMG_DIR_) as $file) {
             if ($file[0] != '.' && $file != 'index.php') {
                 Tools::deleteFile(_PS_TMP_IMG_DIR_ . $file);
             }
         }
     }
     $default_data = array('shop_name' => 'My Shop', 'shop_activity' => '', 'shop_country' => 'us', 'shop_timezone' => 'US/Eastern', 'use_smtp' => false, 'smtp_encryption' => 'off', 'smtp_port' => 25, 'rewrite_engine' => false);
     foreach ($default_data as $k => $v) {
         if (!isset($data[$k])) {
             $data[$k] = $v;
         }
     }
     Context::getContext()->shop = new Shop(1);
     Configuration::loadConfiguration();
     // use the old image system if the safe_mod is enabled otherwise the installer will fail with the fixtures installation
     if (InstallSession::getInstance()->safe_mode) {
         Configuration::updateGlobalValue('PS_LEGACY_IMAGES', 1);
     }
     $id_country = Country::getByIso($data['shop_country']);
     // Set default configuration
     Configuration::updateGlobalValue('PS_SHOP_DOMAIN', Tools::getHttpHost());
     Configuration::updateGlobalValue('PS_SHOP_DOMAIN_SSL', Tools::getHttpHost());
     Configuration::updateGlobalValue('PS_INSTALL_VERSION', _PS_INSTALL_VERSION_);
     Configuration::updateGlobalValue('PS_LOCALE_LANGUAGE', $this->language->getLanguageIso());
     Configuration::updateGlobalValue('PS_SHOP_NAME', $data['shop_name']);
     Configuration::updateGlobalValue('PS_SHOP_ACTIVITY', $data['shop_activity']);
     Configuration::updateGlobalValue('PS_COUNTRY_DEFAULT', $id_country);
     Configuration::updateGlobalValue('PS_LOCALE_COUNTRY', $data['shop_country']);
     Configuration::updateGlobalValue('PS_TIMEZONE', $data['shop_timezone']);
     Configuration::updateGlobalValue('PS_CONFIGURATION_AGREMENT', (int) $data['configuration_agrement']);
     // Set mails configuration
     Configuration::updateGlobalValue('PS_MAIL_METHOD', $data['use_smtp'] ? 2 : 1);
     Configuration::updateGlobalValue('PS_MAIL_SMTP_ENCRYPTION', $data['smtp_encryption']);
     Configuration::updateGlobalValue('PS_MAIL_SMTP_PORT', $data['smtp_port']);
     // Set default rewriting settings
     Configuration::updateGlobalValue('PS_REWRITING_SETTINGS', $data['rewrite_engine']);
     // Activate rijndael 128 encrypt algorihtm if mcrypt is activated
     Configuration::updateGlobalValue('PS_CIPHER_ALGORITHM', function_exists('mcrypt_encrypt') ? 1 : 0);
     $groups = Group::getGroups((int) Configuration::get('PS_LANG_DEFAULT'));
     $groups_default = Db::getInstance()->executeS('SELECT `name` FROM ' . _DB_PREFIX_ . 'configuration WHERE `name` LIKE "PS_%_GROUP" ORDER BY `id_configuration`');
     foreach ($groups_default as &$group_default) {
         if (is_array($group_default) && isset($group_default['name'])) {
             $group_default = $group_default['name'];
         }
     }
     if (is_array($groups) && count($groups)) {
         foreach ($groups as $key => $group) {
             if (Configuration::get($groups_default[$key]) != $groups[$key]['id_group']) {
                 Configuration::updateGlobalValue($groups_default[$key], (int) $groups[$key]['id_group']);
             }
         }
     }
     $states = Db::getInstance()->executeS('SELECT `id_order_state` FROM ' . _DB_PREFIX_ . 'order_state ORDER by `id_order_state`');
     $states_default = Db::getInstance()->executeS('SELECT MIN(`id_configuration`), `name` FROM ' . _DB_PREFIX_ . 'configuration WHERE `name` LIKE "PS_OS_%" GROUP BY `value` ORDER BY`id_configuration`');
     foreach ($states_default as &$state_default) {
         if (is_array($state_default) && isset($state_default['name'])) {
             $state_default = $state_default['name'];
         }
     }
     if (is_array($states) && count($states)) {
         foreach ($states as $key => $state) {
             if (Configuration::get($states_default[$key]) != $states[$key]['id_order_state']) {
                 Configuration::updateGlobalValue($states_default[$key], (int) $states[$key]['id_order_state']);
             }
         }
         /* deprecated order state */
         Configuration::updateGlobalValue('PS_OS_OUTOFSTOCK_PAID', (int) Configuration::get('PS_OS_OUTOFSTOCK'));
     }
     // Set logo configuration
     if (file_exists(_PS_IMG_DIR_ . 'logo.jpg')) {
         list($width, $height) = getimagesize(_PS_IMG_DIR_ . 'logo.jpg');
         Configuration::updateGlobalValue('SHOP_LOGO_WIDTH', round($width));
         Configuration::updateGlobalValue('SHOP_LOGO_HEIGHT', round($height));
     }
     // Disable cache for debug mode
     if (_PS_MODE_DEV_) {
         Configuration::updateGlobalValue('PS_SMARTY_CACHE', 1);
     }
     // Active only the country selected by the merchant
     Db::getInstance()->execute('UPDATE ' . _DB_PREFIX_ . 'country SET active = 0 WHERE id_country != ' . (int) $id_country);
     // Set localization configuration
     $version = str_replace('.', '', _PS_VERSION_);
     $version = substr($version, 0, 2);
     $localization_file_content = $this->getLocalizationPackContent($version, $data['shop_country']);
     $locale = new LocalizationPackCore();
     $locale->loadLocalisationPack($localization_file_content, '', true);
     // Create default employee
     if (isset($data['admin_firstname']) && isset($data['admin_lastname']) && isset($data['admin_password']) && isset($data['admin_email'])) {
         $employee = new Employee();
         $employee->firstname = Tools::ucfirst($data['admin_firstname']);
         $employee->lastname = Tools::ucfirst($data['admin_lastname']);
         $employee->email = $data['admin_email'];
         $employee->passwd = md5(_COOKIE_KEY_ . $data['admin_password']);
         $employee->last_passwd_gen = date('Y-m-d h:i:s', strtotime('-360 minutes'));
         $employee->bo_theme = 'default';
         $employee->default_tab = 1;
         $employee->active = true;
         $employee->optin = (bool) $data['send_informations'];
         $employee->id_profile = 1;
         $employee->id_lang = Configuration::get('PS_LANG_DEFAULT');
         $employee->bo_menu = 1;
         if (!$employee->add()) {
             $this->setError($this->language->l('Cannot create admin account'));
             return false;
         }
     } else {
         $this->setError($this->language->l('Cannot create admin account'));
         return false;
     }
     // Update default contact
     if (isset($data['admin_email'])) {
         Configuration::updateGlobalValue('PS_SHOP_EMAIL', $data['admin_email']);
         $contacts = new PrestaShopCollection('Contact');
         foreach ($contacts as $contact) {
             $contact->email = $data['admin_email'];
             $contact->update();
         }
     }
     if (!@Tools::generateHtaccess(null, $data['rewrite_engine'])) {
         Configuration::updateGlobalValue('PS_REWRITING_SETTINGS', 0);
     }
     return true;
 }
$confFile = new AddConfToFile(SETTINGS_FILE, 'w');
if ($confFile->error) {
    die('<action result="fail" error="' . $confFile->error . '" />' . "\n");
}
foreach ($datas as $data) {
    $confFile->writeInFile($data[0], $data[1]);
}
$confFile->writeEndTagPhp();
if ($confFile->error != false) {
    die('<action result="fail" error="' . $confFile->error . '" />' . "\n");
}
//sql file execution
global $requests, $warningExist;
$requests = '';
$warningExist = false;
Configuration::loadConfiguration();
foreach ($sqlContent as $query) {
    $query = trim($query);
    if (!empty($query)) {
        /* If php code have to be executed */
        if (strpos($query, '/* PHP:') !== false) {
            /* Parsing php code */
            $pos = strpos($query, '/* PHP:') + strlen('/* PHP:');
            $phpString = substr($query, $pos, strlen($query) - $pos - strlen(' */;'));
            $php = explode('::', $phpString);
            preg_match('/\\((.*)\\)/', $phpString, $pattern);
            $paramsString = trim($pattern[0], '()');
            preg_match_all('/([^,]+),? ?/', $paramsString, $parameters);
            if (isset($parameters[1])) {
                $parameters = $parameters[1];
            } else {
 public function ajaxProcessBackupDb()
 {
     $this->_loadDbRelatedClasses();
     $backup = new Backup();
     // for backup db, use autoupgrade directory
     // @TODO : autoupgrade must not be static
     $backup->setCustomBackupPath('autoupgrade');
     // maybe for big tables we should save them in more than one file ?
     $res = $backup->add();
     if ($res) {
         $this->nextParams['backupDbFilename'] = $backup->id;
         // We need to load configuration to use it ...
         Configuration::loadConfiguration();
         Configuration::updateValue('UPGRADER_BACKUPDB_FILENAME', $backup->id);
         $this->next = 'upgradeFiles';
         $this->nextDesc = sprintf($this->l('Database backup done in %s. Now updating files'), $backup->id);
     }
     // if an error occur, we assume the file is not saved
 }
Example #16
0
 /**
  * PROCESS : configureShop
  * Set default shop configuration
  */
 public function configureShop(array $data = array())
 {
     //clear image cache in tmp folder
     if (file_exists(_PS_TMP_IMG_DIR_)) {
         foreach (scandir(_PS_TMP_IMG_DIR_) as $file) {
             if ($file[0] != '.' && $file != 'index.php') {
                 Tools::deleteFile(_PS_TMP_IMG_DIR_ . $file);
             }
         }
     }
     $default_data = array('shop_name' => 'My Shop', 'shop_activity' => '', 'shop_country' => 'us', 'shop_timezone' => 'US/Eastern', 'use_smtp' => false, 'smtp_server' => '', 'smtp_login' => '', 'smtp_password' => '', 'smtp_encryption' => 'off', 'smtp_port' => 25);
     foreach ($default_data as $k => $v) {
         if (!isset($data[$k])) {
             $data[$k] = $v;
         }
     }
     Context::getContext()->shop = new Shop(1);
     Configuration::loadConfiguration();
     // use the old image system if the safe_mod is enabled otherwise the installer will fail with the fixtures installation
     if (InstallSession::getInstance()->safe_mode) {
         Configuration::updateGlobalValue('PS_LEGACY_IMAGES', 1);
     }
     $id_country = Country::getByIso($data['shop_country']);
     // Set default configuration
     Configuration::updateGlobalValue('PS_SHOP_DOMAIN', Tools::getHttpHost());
     Configuration::updateGlobalValue('PS_SHOP_DOMAIN_SSL', Tools::getHttpHost());
     Configuration::updateGlobalValue('PS_INSTALL_VERSION', _PS_INSTALL_VERSION_);
     Configuration::updateGlobalValue('PS_LOCALE_LANGUAGE', $this->language->getLanguageIso());
     Configuration::updateGlobalValue('PS_SHOP_NAME', $data['shop_name']);
     Configuration::updateGlobalValue('PS_SHOP_ACTIVITY', $data['shop_activity']);
     Configuration::updateGlobalValue('PS_COUNTRY_DEFAULT', $id_country);
     Configuration::updateGlobalValue('PS_LOCALE_COUNTRY', $data['shop_country']);
     Configuration::updateGlobalValue('PS_TIMEZONE', $data['shop_timezone']);
     Configuration::updateGlobalValue('PS_CONFIGURATION_AGREMENT', (int) $data['configuration_agrement']);
     // Set mails configuration
     Configuration::updateGlobalValue('PS_MAIL_METHOD', $data['use_smtp'] ? 2 : 1);
     Configuration::updateGlobalValue('PS_MAIL_SERVER', $data['smtp_server']);
     Configuration::updateGlobalValue('PS_MAIL_USER', $data['smtp_login']);
     Configuration::updateGlobalValue('PS_MAIL_PASSWD', $data['smtp_password']);
     Configuration::updateGlobalValue('PS_MAIL_SMTP_ENCRYPTION', $data['smtp_encryption']);
     Configuration::updateGlobalValue('PS_MAIL_SMTP_PORT', $data['smtp_port']);
     // Activate rijndael 128 encrypt algorihtm if mcrypt is activated
     Configuration::updateGlobalValue('PS_CIPHER_ALGORITHM', function_exists('mcrypt_encrypt') ? 1 : 0);
     // Set logo configuration
     if (file_exists(_PS_IMG_DIR_ . 'logo.jpg')) {
         list($width, $height) = getimagesize(_PS_IMG_DIR_ . 'logo.jpg');
         Configuration::updateGlobalValue('SHOP_LOGO_WIDTH', round($width));
         Configuration::updateGlobalValue('SHOP_LOGO_HEIGHT', round($height));
     }
     // Active only the country selected by the merchant
     Db::getInstance()->execute('UPDATE ' . _DB_PREFIX_ . 'country SET active = 0 WHERE id_country != ' . (int) $id_country);
     // Set localization configuration
     $version = str_replace('.', '', _PS_VERSION_);
     $version = substr($version, 0, 2);
     $localization_file_content = @Tools::file_get_contents('http://api.prestashop.com/localization/' . $version . '/' . $data['shop_country'] . '.xml');
     if (!@simplexml_load_string($localization_file_content)) {
         $localization_file_content = false;
     }
     if (!$localization_file_content) {
         $localization_file = _PS_ROOT_DIR_ . '/localization/default.xml';
         if (file_exists(_PS_ROOT_DIR_ . '/localization/' . $data['shop_country'] . '.xml')) {
             $localization_file = _PS_ROOT_DIR_ . '/localization/' . $data['shop_country'] . '.xml';
         }
         $localization_file_content = file_get_contents($localization_file);
     }
     $locale = new LocalizationPackCore();
     $locale->loadLocalisationPack($localization_file_content, '', true);
     // Create default employee
     if (isset($data['admin_firstname']) && isset($data['admin_lastname']) && isset($data['admin_password']) && isset($data['admin_email'])) {
         $employee = new Employee();
         $employee->firstname = Tools::ucfirst($data['admin_firstname']);
         $employee->lastname = Tools::ucfirst($data['admin_lastname']);
         $employee->email = $data['admin_email'];
         $employee->passwd = md5(_COOKIE_KEY_ . $data['admin_password']);
         $employee->last_passwd_gen = date('Y-m-d h:i:s', strtotime('-360 minutes'));
         $employee->bo_theme = 'default';
         $employee->default_tab = 1;
         $employee->active = true;
         $employee->id_profile = 1;
         $employee->id_lang = Configuration::get('PS_LANG_DEFAULT');
         $employee->bo_show_screencast = 1;
         if (!$employee->add()) {
             $this->setError($this->language->l('Cannot create admin account'));
             return false;
         }
     } else {
         $this->setError($this->language->l('Cannot create admin account'));
         return false;
     }
     // Update default contact
     if (isset($data['admin_email'])) {
         Configuration::updateGlobalValue('PS_SHOP_EMAIL', $data['admin_email']);
         $contacts = new Collection('Contact');
         foreach ($contacts as $contact) {
             $contact->email = $data['admin_email'];
             $contact->update();
         }
     }
     return true;
 }
Example #17
0
    private function _checkAndUpdateFromOldVersion($install = false)
    {
        if (!Configuration::get('PAYPAL_NEW') and ($this->active or $install)) {
            $ok = true;
            /* Check PayPal API */
            if (file_exists(_PS_ROOT_DIR_ . '/modules/paypalapi/paypalapi.php')) {
                $confs = Configuration::getMultiple(array('PAYPAL_HEADER', 'PAYPAL_SANDBOX', 'PAYPAL_API_USER', 'PAYPAL_API_PASSWORD', 'PAYPAL_API_SIGNATURE', 'PAYPAL_EXPRESS_CHECKOUT'));
                include_once _PS_ROOT_DIR_ . '/modules/paypalapi/paypalapi.php';
                $paypalapi = new PayPalAPI();
                if ($paypalapi->active) {
                    if (Configuration::get('PAYPAL_INTEGRAL') == 1) {
                        Configuration::updateValue('PAYPAL_PAYMENT_METHOD', _PAYPAL_INTEGRAL_);
                    } elseif (Configuration::get('PAYPAL_INTEGRAL') == 0) {
                        Configuration::updateValue('PAYPAL_PAYMENT_METHOD', _PAYPAL_OPTION_PLUS_);
                    }
                    $paypalapi->uninstall();
                    Configuration::loadConfiguration();
                    foreach ($confs as $key => $value) {
                        Configuration::updateValue($key, $value);
                    }
                }
            }
            /* Create Table */
            if (!Db::getInstance()->Execute('
			CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'paypal_order` (
			`id_order` int(10) unsigned NOT NULL auto_increment,
			`id_transaction` varchar(255) NOT NULL,
			PRIMARY KEY (`id_order`)
			) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8')) {
                $ok = false;
            }
            if (!Db::getInstance()->Execute('
			ALTER TABLE `' . _DB_PREFIX_ . 'paypal_order` ADD `payment_method` INT NOT NULL,
			ADD `payment_status` VARCHAR(255) NOT NULL,
			ADD `capture` INT NOT NULL')) {
                $ok = false;
            }
            /* Hook */
            $this->registerHook('cancelProduct');
            $this->registerHook('adminOrder');
            /* Create OrderState */
            if (!Configuration::get('PAYPAL_OS_AUTHORIZATION')) {
                $orderState = new OrderState();
                $orderState->name = array();
                foreach (Language::getLanguages() as $language) {
                    if (strtolower($language['iso_code']) == 'fr') {
                        $orderState->name[$language['id_lang']] = 'Autorisation acceptée par PayPal';
                    } else {
                        $orderState->name[$language['id_lang']] = 'Authorization accepted from PayPal';
                    }
                }
                $orderState->send_email = false;
                $orderState->color = '#DDEEFF';
                $orderState->hidden = false;
                $orderState->delivery = false;
                $orderState->logable = true;
                $orderState->invoice = true;
                if ($orderState->add()) {
                    @copy(_PS_ROOT_DIR_ . '/img/os/' . Configuration::get('PS_OS_PAYPAL') . '.gif', _PS_ROOT_DIR_ . '/img/os/' . (int) $orderState->id . '.gif');
                }
                Configuration::updateValue('PAYPAL_OS_AUTHORIZATION', (int) $orderState->id);
            }
            /* Delete unseless configuration */
            Configuration::deleteByName('PAYPAL_INTEGRAL');
            /* Add new Configurations */
            if (!Configuration::get('PAYPAL_PAYMENT_METHOD')) {
                Configuration::updateValue('PAYPAL_PAYMENT_METHOD', _PAYPAL_INTEGRAL_);
            }
            Configuration::updateValue('PAYPAL_CAPTURE', 0);
            Configuration::updateValue('PAYPAL_TEMPLATE', 'A');
            if ($ok) {
                Configuration::updateValue('PAYPAL_NEW', 1);
            }
            return $ok;
        }
        return false;
    }
Example #18
0
 /**
  * Get a single configuration value (in one language only)
  *
  * @param string $key Key wanted
  * @param integer $id_lang Language ID
  * @return string Value
  */
 public static function get($key, $id_lang = null, $id_shop_group = null, $id_shop = null)
 {
     // If conf if not initialized, try manual query
     if (!self::$_CONF) {
         Configuration::loadConfiguration();
         if (!self::$_CONF) {
             return Db::getInstance()->getValue('SELECT `value` FROM `' . _DB_PREFIX_ . 'configuration` WHERE `name` = "' . pSQL($key) . '"');
         }
     }
     $id_lang = (int) $id_lang;
     if ($id_shop === null) {
         $id_shop = Shop::getContextShopID(true);
     }
     if ($id_shop_group === null) {
         $id_shop_group = Shop::getContextShopGroupID(true);
     }
     if (!isset(self::$_CONF[$id_lang])) {
         $id_lang = 0;
     }
     if ($id_shop && Configuration::hasKey($key, $id_lang, null, $id_shop)) {
         return self::$_CONF[$id_lang]['shop'][$id_shop][$key];
     } elseif ($id_shop_group && Configuration::hasKey($key, $id_lang, $id_shop_group)) {
         return self::$_CONF[$id_lang]['group'][$id_shop_group][$key];
     } elseif (Configuration::hasKey($key, $id_lang)) {
         return self::$_CONF[$id_lang]['global'][$key];
     }
     return false;
 }
Example #19
0
    /**
     * Removes all "NOSTOTAGGING_" config entries for the current context and given language.
     *
     * @param int|null $id_lang the ID of the language object to remove the config entries for.
     * @param null|int $id_shop_group the ID of the shop context.
     * @param null|int $id_shop the ID of the shop.
     * @return bool
     */
    public function deleteAllFromContext($id_lang = null, $id_shop_group = null, $id_shop = null)
    {
        if (_PS_VERSION_ >= '1.5') {
            if ($id_shop === null) {
                $id_shop = (int) Shop::getContextShopID(true);
            }
            if ($id_shop_group === null) {
                $id_shop_group = (int) Shop::getContextShopGroupID(true);
            }
            if ($id_shop) {
                $context_restriction = ' AND `id_shop` = ' . $id_shop;
            } elseif ($id_shop_group) {
                $context_restriction = ' AND `id_shop_group` = ' . $id_shop_group . ' AND (`id_shop` IS NULL OR `id_shop` = 0)';
            } else {
                $context_restriction = ' AND (`id_shop_group` IS NULL OR `id_shop_group` = 0) AND (`id_shop` IS NULL OR `id_shop` = 0)';
            }
        } else {
            $context_restriction = '';
        }
        $config_table = _DB_PREFIX_ . 'configuration';
        $config_lang_table = $config_table . '_lang';
        if (!empty($id_lang)) {
            Db::getInstance()->execute('
				DELETE `' . $config_lang_table . '` FROM `' . $config_lang_table . '`
				INNER JOIN `' . $config_table . '`
				ON `' . $config_lang_table . '`.`id_configuration` = `' . $config_table . '`.`id_configuration`
				WHERE `' . $config_table . '`.`name` LIKE "NOSTOTAGGING_%"
				AND `id_lang` = ' . (int) $id_lang . $context_restriction);
        }
        // We do not actually delete the main config entries, just set them to NULL, as there might me other language
        // specific entries tied to them. The main entries are not used anyways if there are languages defined.
        /* todo: this breaks PS 1.4, apparently you cannot update a value that is NULL in PS 1.4.
        		Db::getInstance()->execute('
        			UPDATE `'.$config_table.'`
        			SET `value` = NULL
        			WHERE `name` LIKE "NOSTOTAGGING_%"'
        			.$context_restriction
        		);*/
        // Reload the config.
        Configuration::loadConfiguration();
        return true;
    }
Example #20
0
 /**
  * Get a single configuration value (in one language only)
  *
  * @param string $key    Key wanted
  * @param int    $idLang Language ID
  *
  * @return string Value
  */
 public static function get($key, $idLang = null, $idShopGroup = null, $idShop = null, $default = false)
 {
     if (defined('_PS_DO_NOT_LOAD_CONFIGURATION_') && _PS_DO_NOT_LOAD_CONFIGURATION_) {
         return false;
     }
     // Init the cache on demand
     if (!self::$_initialized) {
         Configuration::loadConfiguration();
     }
     $idLang = (int) $idLang;
     if (!self::isLangKey($key)) {
         $idLang = 0;
     }
     if (self::$_new_cache_shop === null) {
         $idShop = 0;
     } else {
         if ($idShop === null || !Shop::isFeatureActive()) {
             $idShop = Shop::getContextShopID(true);
         }
     }
     if (self::$_new_cache_group === null) {
         $idShopGroup = 0;
     } else {
         if ($idShopGroup === null || !Shop::isFeatureActive()) {
             $idShopGroup = Shop::getContextShopGroupID(true);
         }
     }
     if ($idShop && Configuration::hasKey($key, $idLang, null, $idShop)) {
         return self::$_new_cache_shop[$key][$idLang][$idShop];
     } elseif ($idShopGroup && Configuration::hasKey($key, $idLang, $idShopGroup)) {
         return self::$_new_cache_group[$key][$idLang][$idShopGroup];
     } elseif (Configuration::hasKey($key, $idLang)) {
         return self::$_new_cache_global[$key][$idLang];
     }
     return $default;
 }
Example #21
0
 /**
  * Get a single configuration value (in one language only)
  *
  * @param string $key Key wanted
  * @param integer $id_lang Language ID
  * @return string Value
  */
 public static function get($key, $id_lang = null, $id_shop_group = null, $id_shop = null)
 {
     if (defined('_PS_DO_NOT_LOAD_CONFIGURATION_') && _PS_DO_NOT_LOAD_CONFIGURATION_) {
         return false;
     }
     // If conf if not initialized, try manual query
     if (!isset(self::$_cache[self::$definition['table']])) {
         Configuration::loadConfiguration();
         if (!self::$_cache[self::$definition['table']]) {
             return Db::getInstance()->getValue('SELECT `value` FROM `' . _DB_PREFIX_ . bqSQL(self::$definition['table']) . '` WHERE `name` = "' . pSQL($key) . '"');
         }
     }
     $id_lang = (int) $id_lang;
     if ($id_shop === null) {
         $id_shop = Shop::getContextShopID(true);
     }
     if ($id_shop_group === null) {
         $id_shop_group = Shop::getContextShopGroupID(true);
     }
     if (!isset(self::$_cache[self::$definition['table']][$id_lang])) {
         $id_lang = 0;
     }
     if ($id_shop && Configuration::hasKey($key, $id_lang, null, $id_shop)) {
         return self::$_cache[self::$definition['table']][$id_lang]['shop'][$id_shop][$key];
     } elseif ($id_shop_group && Configuration::hasKey($key, $id_lang, $id_shop_group)) {
         return self::$_cache[self::$definition['table']][$id_lang]['group'][$id_shop_group][$key];
     } elseif (Configuration::hasKey($key, $id_lang)) {
         return self::$_cache[self::$definition['table']][$id_lang]['global'][$key];
     }
     return false;
 }