//add payment module restriction when enable country

This commit is contained in:
vAugagneur
2012-10-01 15:40:11 +00:00
parent 1d9e531313
commit 2b917ed3c3
4 changed files with 56 additions and 15 deletions
+26
View File
@@ -344,4 +344,30 @@ class CountryCore extends ObjectModel
return (bool)preg_match($zip_regexp, $zip_code);
}
public static function addModuleRestrictions(array $shops = array(), array $countries = array(), array $modules = array())
{
if (!count($shops))
$shops = Shop::getShops(true, null, true);
if (!count($countries))
$countries = Country::getCountries((int)Context::getContext()->cookie->id_lang);
if (!count($modules))
$modules = Module::getPaymentModules();
$sql = false;
foreach ($shops as $id_shop)
foreach ($countries as $country)
foreach ($modules as $module)
$sql .= '('.(int)$module['id_module'].', '.(int)$id_shop.', '.(int)$country['id_country'].'),';
if ($sql)
{
$sql = 'INSERT IGNORE INTO `'._DB_PREFIX_.'module_country` (`id_module`, `id_shop`, `id_country`) VALUES '.rtrim($sql, ',');
return Db::getInstance()->execute($sql);
}
else
return true;
}
}
+6 -14
View File
@@ -111,21 +111,13 @@ abstract class PaymentModuleCore extends Module
*/
public function addCheckboxCountryRestrictionsForModule(array $shops = array())
{
if (!$shops)
$shops = Shop::getShops(true, null, true);
foreach ($shops as $s)
{
if (!Db::getInstance()->execute('
INSERT INTO `'._DB_PREFIX_.'module_country` (`id_module`, `id_shop`, `id_country`)
SELECT '.(int)$this->id.', "'.(int)$s.'", `id_country` FROM `'._DB_PREFIX_.'country` WHERE active = 1'))
return false;
}
return true;
$countries = Country::getCountries((int)Context::getContext()->cookie->id_lang, true); //get only active country
$country_ids = array();
foreach ($countries as $country)
$country_ids[] = $country['id_country'];
return Country::addModuleRestrictions($shops, $countries, array(array('id_module' => (int)$this->id)));
}
/**
* Validate an order in database
* Function called from a payment module
+1 -1
View File
@@ -1311,7 +1311,7 @@ abstract class ModuleCore
$paypal_condition = ' AND m.`name` = \'paypal\'';
$list = Shop::getContextListShopID();
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('SELECT DISTINCT h.`id_hook`, m.`name`, hm.`position`
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('SELECT DISTINCT m.`id_module`, h.`id_hook`, m.`name`, hm.`position`
FROM `'._DB_PREFIX_.'module` m
'.($frontend ? 'LEFT JOIN `'._DB_PREFIX_.'module_country` mc ON (m.`id_module` = mc.`id_module` AND mc.id_shop = '.(int)$context->shop->id.')' : '').'
'.($frontend ? 'INNER JOIN `'._DB_PREFIX_.'module_group` mg ON (m.`id_module` = mg.`id_module` AND mg.id_shop = '.(int)$context->shop->id.')' : '').'
@@ -404,6 +404,29 @@ class AdminCountriesControllerCore extends AdminController
return $res;
}
public function processStatus()
{
if (Validate::isLoadedObject($object = $this->loadObject()))
Country::addModuleRestrictions(array(), array(array('id_country' => $object->id)), array());
parent::processStatus();
}
public function processBulkStatusSelection($way)
{
if (is_array($this->boxes) && !empty($this->boxes))
{
$countries_ids = array();
foreach ($this->boxes as $id)
$countries_ids[] = array('id_country' => $id);
if (count($countries_ids))
Country::addModuleRestrictions(array(), $countries_ids, array());
}
parent::processBulkStatusSelection($way);
}
protected function displayValidFields()
{