/** * Retrieve all payment methods list as an array * * Possible output: * 1) assoc array as <code> => <title> * 2) array of array('label' => <title>, 'value' => <code>) * 3) array of array( * array('value' => <code>, 'label' => <title>), * array('value' => array( * 'value' => array(array(<code1> => <title1>, <code2> =>...), * 'label' => <group name> * )), * array('value' => <code>, 'label' => <title>), * ... * ) * * @param bool $sorted * @param bool $asLabelValue * @param bool $withGroups * @param Store|null $store * @return array */ public function getPaymentMethodList($sorted = true, $asLabelValue = false, $withGroups = false, $store = null) { $methods = array(); $groups = array(); $groupRelations = array(); foreach ($this->getPaymentMethods() as $code => $data) { if (isset($data['title'])) { $methods[$code] = $data['title']; } else { if ($this->getMethodInstance($code)) { $methods[$code] = $this->getMethodInstance($code)->getConfigData('title', $store); } } if ($asLabelValue && $withGroups && isset($data['group'])) { $groupRelations[$code] = $data['group']; } } if ($asLabelValue && $withGroups) { $groups = $this->_paymentConfig->getGroups(); foreach ($groups as $code => $title) { $methods[$code] = $title; } } if ($sorted) { asort($methods); } if ($asLabelValue) { $labelValues = array(); foreach ($methods as $code => $title) { $labelValues[$code] = array(); } foreach ($methods as $code => $title) { if (isset($groups[$code])) { $labelValues[$code]['label'] = $title; } elseif (isset($groupRelations[$code])) { unset($labelValues[$code]); $labelValues[$groupRelations[$code]]['value'][$code] = array('value' => $code, 'label' => $title); } else { $labelValues[$code] = array('value' => $code, 'label' => $title); } } return $labelValues; } return $methods; }
public function testGetGroups() { $expected = []; $this->dataStorage->expects($this->once())->method('get')->with('groups')->will($this->returnValue($expected)); $this->assertEquals($expected, $this->config->getGroups()); }
public function testGetGroups() { $expected = array('any_payment' => 'Any Payment Methods', 'offline' => 'Offline Payment Methods'); $groups = $this->_model->getGroups(); $this->assertEquals($expected, $groups); }