From 6ebbfd3925d70c5e13c47642c98604aabff3cb6d Mon Sep 17 00:00:00 2001 From: vSchoener Date: Wed, 16 May 2012 16:15:55 +0000 Subject: [PATCH] [-] BO : Fixed bug #PSCFV-1590. Save restrictions won't delete the ones for inactive module. git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@15354 b9a71923-0436-4b27-9f14-aed3839534dd --- controllers/admin/AdminPaymentController.php | 23 +++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/controllers/admin/AdminPaymentController.php b/controllers/admin/AdminPaymentController.php index 4e8b53c9e..31a0e811f 100644 --- a/controllers/admin/AdminPaymentController.php +++ b/controllers/admin/AdminPaymentController.php @@ -108,14 +108,31 @@ class AdminPaymentControllerCore extends AdminController protected function saveRestrictions($type) { - Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'module_'.bqSQL($type).'` WHERE id_shop = '.Context::getContext()->shop->id); + // Delete type restrictions for active module. + $modules = array(); + foreach ($this->payment_modules as $module) + if ($module->active) + $modules[] = (int)$module->id; + + Db::getInstance()->execute(' + DELETE FROM `'._DB_PREFIX_.'module_'.bqSQL($type).'` + WHERE id_shop = '.Context::getContext()->shop->id.' + AND `id_module` IN ('.implode(', ', $modules).')' + ); + + // Fill the new restriction selection for active module. + $values = array(); foreach ($this->payment_modules as $module) if ($module->active && isset($_POST[$module->name.'_'.$type.''])) foreach ($_POST[$module->name.'_'.$type.''] as $selected) - $values[] = '('.(int)$module->id.', '.Context::getContext()->shop->id.', '.(int)$selected.')'; + $values[] = '('.(int)$module->id.', '.(int)Context::getContext()->shop->id.', '.(int)$selected.')'; if (count($values)) - Db::getInstance()->execute('INSERT INTO '._DB_PREFIX_.'module_'.$type.' (`id_module`, `id_shop`, `id_'.$type.'`) VALUES '.implode(',', $values)); + Db::getInstance()->execute(' + INSERT INTO `'._DB_PREFIX_.'module_'.bqSQL($type).'` + (`id_module`, `id_shop`, `id_'.bqSQL($type).'`) + VALUES '.implode(',', $values)); + Tools::redirectAdmin(self::$currentIndex.'&conf=4'.'&token='.$this->token); }