[-] FO : #PSCFV-152 - Check payment method are allowed before displaying them on the checkout page

This commit is contained in:
mDeflotte
2012-05-03 12:45:02 +00:00
parent 73c7b86451
commit b86cfebbf4
2 changed files with 16 additions and 4 deletions
+10
View File
@@ -266,9 +266,18 @@ class HookCore extends ObjectModel
// Store results per hook name // Store results per hook name
$results = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); $results = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
$list = array(); $list = array();
// Get all available payment module
$payment_modules = array();
foreach (Module::getPaymentModules() as $module)
$payment_modules[] = $module['name'];
if ($results) if ($results)
foreach ($results as $row) foreach ($results as $row)
{ {
if ($row['hook'] == 'displayPayment' && !in_array($row['module'], $payment_modules))
continue;
$row['hook'] = strtolower($row['hook']); $row['hook'] = strtolower($row['hook']);
if (!isset($list[$row['hook']])) if (!isset($list[$row['hook']]))
$list[$row['hook']] = array(); $list[$row['hook']] = array();
@@ -324,6 +333,7 @@ class HookCore extends ObjectModel
throw new PrestaShopException('Invalid id_module or hook_name'); throw new PrestaShopException('Invalid id_module or hook_name');
// If no modules associated to hook_name or recompatible hook name, we stop the function // If no modules associated to hook_name or recompatible hook name, we stop the function
if (!$module_list = Hook::getHookModuleExecList($hook_name)) if (!$module_list = Hook::getHookModuleExecList($hook_name))
return ''; return '';
+6 -4
View File
@@ -1226,7 +1226,8 @@ abstract class ModuleCore
public static function getPaymentModules() public static function getPaymentModules()
{ {
$context = Context::getContext(); $context = Context::getContext();
$billing = new Address((int)$context->cart->id_address_invoice); if (isset($context->cart))
$billing = new Address((int)$context->cart->id_address_invoice);
if (isset($context->customer)) if (isset($context->customer))
$groups = $context->customer->getGroups(); $groups = $context->customer->getGroups();
@@ -1239,16 +1240,17 @@ abstract class ModuleCore
FROM `'._DB_PREFIX_.'module_country` mc FROM `'._DB_PREFIX_.'module_country` mc
LEFT JOIN `'._DB_PREFIX_.'module` m ON m.`id_module` = mc.`id_module` LEFT JOIN `'._DB_PREFIX_.'module` m ON m.`id_module` = mc.`id_module`
INNER JOIN `'._DB_PREFIX_.'module_group` mg ON (m.`id_module` = mg.`id_module`) INNER JOIN `'._DB_PREFIX_.'module_group` mg ON (m.`id_module` = mg.`id_module`)
INNER JOIN `'._DB_PREFIX_.'customer_group` cg on (cg.`id_group` = mg.`id_group` AND cg.`id_customer` = '.(int)$context->customer->id.') INNER JOIN `'._DB_PREFIX_.'customer_group` cg on (cg.`id_group` = mg.`id_group`
'.(isset($context->customer) ? 'AND cg.`id_customer` = '.(int)$context->customer->id : '').')
LEFT JOIN `'._DB_PREFIX_.'hook_module` hm ON hm.`id_module` = m.`id_module` LEFT JOIN `'._DB_PREFIX_.'hook_module` hm ON hm.`id_module` = m.`id_module`
LEFT JOIN `'._DB_PREFIX_.'hook` h ON hm.`id_hook` = h.`id_hook` LEFT JOIN `'._DB_PREFIX_.'hook` h ON hm.`id_hook` = h.`id_hook`
WHERE h.`name` = \''.pSQL($hookPayment).'\' WHERE h.`name` = \''.pSQL($hookPayment).'\'
AND mc.id_country = '.(int)$billing->id_country.' '.(isset($billing) ? 'AND mc.id_country = '.(int)$billing->id_country : '').'
AND mc.id_shop = '.(int)$context->shop->id.' AND mc.id_shop = '.(int)$context->shop->id.'
AND mg.id_shop = '.(int)$context->shop->id.' AND mg.id_shop = '.(int)$context->shop->id.'
AND (SELECT COUNT(*) FROM '._DB_PREFIX_.'module_shop ms WHERE ms.id_module = m.id_module AND ms.id_shop IN('.implode(', ', $list).')) = '.count($list).' AND (SELECT COUNT(*) FROM '._DB_PREFIX_.'module_shop ms WHERE ms.id_module = m.id_module AND ms.id_shop IN('.implode(', ', $list).')) = '.count($list).'
AND hm.id_shop IN('.implode(', ', $list).') AND hm.id_shop IN('.implode(', ', $list).')
AND (mg.`id_group` IN('.implode(', ', $groups).')) '.(isset($groups) ? 'AND (mg.`id_group` IN('.implode(', ', $groups).'))' : '').'
GROUP BY hm.id_hook, hm.id_module GROUP BY hm.id_hook, hm.id_module
ORDER BY hm.`position`, m.`name` DESC'; ORDER BY hm.`position`, m.`name` DESC';
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);