I am creating Payment methods based on locations addon and need some help
Working with function fn_get_payment_methods located in core\fn.cart.php
function fn_get_payment_methods(&$auth, $lang_code = CART_LANGUAGE)
{
$condition = '';
if (AREA == 'C') {
$condition .= " AND (" . fn_find_array_in_set($auth['usergroup_ids'], '?:payments.usergroup_ids', true) . ")";
$condition .= " AND ?:payments.status = 'A' ";
$condition .= fn_get_localizations_condition('?:payments.localization');
}
$payment_methods = db_get_hash_array("SELECT ?:payments.payment_id, ?:payments.a_surcharge, ?:payments.p_surcharge, ?:payments.payment_category, ?:payment_descriptions.*, ?:payment_processors.processor, ?:payment_processors.type AS processor_type FROM ?:payments LEFT JOIN ?:payment_descriptions ON ?:payments.payment_id = ?:payment_descriptions.payment_id AND ?:payment_descriptions.lang_code = ?s LEFT JOIN ?:payment_processors ON ?:payment_processors.processor_id = ?:payments.processor_id WHERE 1 $condition ORDER BY ?:payments.position", 'payment_id', $lang_code);
fn_set_hook('get_payment_methods', $payment_methods, $auth);
return $payment_methods;
}
basically I only need to modify select query
$payment_methods = db_get_hash_array("SELECT ?:payments.payment_id...
so I have used get_payment_methods hook, and created new function “fn_location_based_payments_get_payment_methods” in my \addons\location_based_payments\func.php
I have just copied whole function content and modified select query to my needs. My func.php actually works, but I feel this is not most elegant way to execute db_get_hash_array twice. I am also aware about possible conflicts with other addons which use this hook
function fn_location_based_payments_get_payment_methods ($payment_methods, $auth)
{
$lang_code = CART_LANGUAGE;
$condition = '';
if (AREA == 'C') {
$condition .= " AND (" . fn_find_array_in_set($auth['usergroup_ids'], '?:payments.usergroup_ids', true) . ")";
$condition .= " AND ?:payments.status = 'A' ";
$condition .= fn_get_localizations_condition('?:payments.localization');
}
$payment_methods = db_get_hash_array("SELECT ?:payments.payment_id, ?:payments.a_surcharge, ?:payments.p_surcharge, ?:payments.payment_category, ?:payment_descriptions.*, ?:payment_processors.processor, ?:payment_processors.type AS processor_type FROM ?:payments LEFT JOIN ?:payment_descriptions ON ?:payments.payment_id = ?:payment_descriptions.payment_id AND ?:payment_descriptions.lang_code = ?s LEFT JOIN ?:payment_processors ON ?:payment_processors.processor_id = ?:payments.processor_id RIGHT JOIN ?:payment_destinations_addon ON ?:payments.payment_id = ?:payment_destinations_addon.payment_id WHERE 1 $condition ORDER BY ?:payments.position", 'payment_id', $lang_code);
}
Is there any way to modify this select statement without execute db_get_hash_array twice?
Also I need to add some code ( db insert statement) to function fn_update_payment located in \controllers\admin\payments.php
I know I can add some code to payments.php by creating payments.post.php file in addon, but i need this code in specific function.
As I know its not possible to declare the same function twice.