Skip to content

Commit 4bb408b

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-99112' into 2.3-develop-pr25
2 parents 5b19d3c + 4344cc9 commit 4bb408b

File tree

2 files changed

+68
-16
lines changed
  • app/code/Magento/Payment/Helper
  • dev/tests/integration/testsuite/Magento/Payment/Helper

2 files changed

+68
-16
lines changed

app/code/Magento/Payment/Helper/Data.php

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public function getStoreMethods($store = null, $quote = null)
149149
}
150150
$res[] = $methodInstance;
151151
}
152-
152+
// phpcs:ignore Generic.PHP.NoSilencedErrors
153153
@uasort(
154154
$res,
155155
function (MethodInterface $a, MethodInterface $b) {
@@ -261,14 +261,12 @@ public function getPaymentMethodList($sorted = true, $asLabelValue = false, $wit
261261
$groupRelations = [];
262262

263263
foreach ($this->getPaymentMethods() as $code => $data) {
264-
if (!empty($data['active'])) {
265-
$storedTitle = $this->getMethodInstance($code)->getConfigData('title', $store);
266-
if (isset($storedTitle)) {
267-
$methods[$code] = $storedTitle;
268-
} elseif (isset($data['title'])) {
269-
$methods[$code] = $data['title'];
270-
}
264+
$storeId = $store ? (int)$store->getId() : null;
265+
$storedTitle = $this->getMethodStoreTitle($code, $storeId);
266+
if (!empty($storedTitle)) {
267+
$methods[$code] = $storedTitle;
271268
}
269+
272270
if ($asLabelValue && $withGroups && isset($data['group'])) {
273271
$groupRelations[$code] = $data['group'];
274272
}
@@ -350,4 +348,21 @@ public function getZeroSubTotalPaymentAutomaticInvoice($store = null)
350348
$store
351349
);
352350
}
351+
352+
/**
353+
* Get config title of payment method
354+
*
355+
* @param string $code
356+
* @param int|null $storeId
357+
* @return string
358+
*/
359+
private function getMethodStoreTitle(string $code, ?int $storeId = null): string
360+
{
361+
$configPath = sprintf('%s/%s/title', self::XML_PATH_PAYMENT_METHODS, $code);
362+
return (string) $this->scopeConfig->getValue(
363+
$configPath,
364+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
365+
$storeId
366+
);
367+
}
353368
}

dev/tests/integration/testsuite/Magento/Payment/Helper/DataTest.php

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,59 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
namespace Magento\Payment\Helper;
7+
8+
use PHPUnit\Framework\TestCase;
9+
use Magento\OfflinePayments\Block\Info\Checkmo;
10+
use Magento\Payment\Model\Info;
11+
use Magento\TestFramework\Helper\Bootstrap;
612

713
/**
814
* Test class for \Magento\Payment\Helper\Data
915
*/
10-
namespace Magento\Payment\Helper;
11-
12-
class DataTest extends \PHPUnit\Framework\TestCase
16+
class DataTest extends TestCase
1317
{
18+
/**
19+
* @var Data
20+
*/
21+
private $helper;
22+
23+
/**
24+
* @inheritdoc
25+
*/
26+
protected function setUp()
27+
{
28+
parent::setUp();
29+
30+
$this->helper = Bootstrap::getObjectManager()->get(Data::class);
31+
}
32+
33+
/**
34+
* @return void
35+
*/
1436
public function testGetInfoBlock()
1537
{
16-
$helper = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Payment\Helper\Data::class);
17-
$paymentInfo = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
18-
\Magento\Payment\Model\Info::class
38+
$paymentInfo = Bootstrap::getObjectManager()->create(
39+
Info::class
1940
);
2041
$paymentInfo->setMethod('checkmo');
21-
$result = $helper->getInfoBlock($paymentInfo);
22-
$this->assertInstanceOf(\Magento\OfflinePayments\Block\Info\Checkmo::class, $result);
42+
$result = $this->helper->getInfoBlock($paymentInfo);
43+
$this->assertInstanceOf(Checkmo::class, $result);
44+
}
45+
46+
/**
47+
* Test to load Payment method title from store config
48+
*
49+
* @magentoConfigFixture current_store payment/cashondelivery/title Cash On Delivery Title Of The Method
50+
*/
51+
public function testPaymentMethodLabelByStore()
52+
{
53+
$result = $this->helper->getPaymentMethodList(true, true);
54+
$this->assertArrayHasKey('cashondelivery', $result, 'Payment info does not exist');
55+
$this->assertEquals(
56+
'Cash On Delivery Title Of The Method',
57+
$result['cashondelivery']['label'],
58+
'Payment method title is not loaded from store config'
59+
);
2360
}
2461
}

0 commit comments

Comments
 (0)