[-] FO : #PSCFV-152 - Check payment method are allowed before displaying them on the checkout page
This commit is contained in:
@@ -266,9 +266,18 @@ class HookCore extends ObjectModel
|
||||
// Store results per hook name
|
||||
$results = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
|
||||
$list = array();
|
||||
|
||||
// Get all available payment module
|
||||
$payment_modules = array();
|
||||
foreach (Module::getPaymentModules() as $module)
|
||||
$payment_modules[] = $module['name'];
|
||||
|
||||
if ($results)
|
||||
foreach ($results as $row)
|
||||
{
|
||||
if ($row['hook'] == 'displayPayment' && !in_array($row['module'], $payment_modules))
|
||||
continue;
|
||||
|
||||
$row['hook'] = strtolower($row['hook']);
|
||||
if (!isset($list[$row['hook']]))
|
||||
$list[$row['hook']] = array();
|
||||
@@ -324,6 +333,7 @@ class HookCore extends ObjectModel
|
||||
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 (!$module_list = Hook::getHookModuleExecList($hook_name))
|
||||
return '';
|
||||
|
||||
|
||||
+6
-4
@@ -1226,7 +1226,8 @@ abstract class ModuleCore
|
||||
public static function getPaymentModules()
|
||||
{
|
||||
$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))
|
||||
$groups = $context->customer->getGroups();
|
||||
|
||||
@@ -1239,16 +1240,17 @@ abstract class ModuleCore
|
||||
FROM `'._DB_PREFIX_.'module_country` mc
|
||||
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_.'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` h ON hm.`id_hook` = h.`id_hook`
|
||||
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 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 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
|
||||
ORDER BY hm.`position`, m.`name` DESC';
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
|
||||
|
||||
Reference in New Issue
Block a user