Allows to filter the payment method list before it is displayed on the checkout pages or in the backend.
The event handler should accept a single parameter - the options array. The array contains the following fields:
- payment_methods - a array of payment methods. Each element is the Shop_PaymentMethod object.
- amount - order total.
- country_id - shipping country identifier.
- customer_group_id - identifier of the customer group.
- ignore_customer_group_filter - boolean, indicates if the customer group filter was ignored.
- backend - boolean, true when payment methods are being listed in the backend.
- order_items - a list of order items (Shop_OrderItem or Shop_CartItem objects, depending on the caller context).
The handler should return an updated payment methods array.
Usage example:
public function subscribeEvents()
{
Backend::$events->addEvent('shop:onFilterPaymentMethods', $this, 'filter_payment_options');
}
public function filter_payment_options($params)
{
extract($params);
if(count($order_items))
{
//remove a certain payment method if order contains products from a specific category
$hide_special = false;
foreach($order_items as $item)
{
$category_list = $item->product->category_list;
foreach($category_list as $category)
{
if($category->code == 'special')
{
$hide_special = true;
break;
}
}
}
if($hide_special)
{
$filtered_payment_methods = array();
foreach($payment_methods as $i => $method)
{
if($method->ls_api_code != 'special')
$filtered_payment_methods[$i] = $method;
}
return $filtered_payment_methods;
}
}
return $payment_methods;
}