Skip to content

Commit 08ecfe1

Browse files
committed
MAGETWO-99111: Payment Method Not Showing Admin Sales Grid only check method showing
1 parent 848e1f9 commit 08ecfe1

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
@@ -147,7 +147,7 @@ public function getStoreMethods($store = null, $quote = null)
147147
}
148148
$res[] = $methodInstance;
149149
}
150-
150+
// phpcs:ignore Generic.PHP.NoSilencedErrors
151151
@uasort(
152152
$res,
153153
function (MethodInterface $a, MethodInterface $b) {
@@ -267,14 +267,12 @@ public function getPaymentMethodList($sorted = true, $asLabelValue = false, $wit
267267
$groupRelations = [];
268268

269269
foreach ($this->getPaymentMethods() as $code => $data) {
270-
if (!empty($data['active'])) {
271-
$storedTitle = $this->getMethodInstance($code)->getConfigData('title', $store);
272-
if (!empty($storedTitle)) {
273-
$methods[$code] = $storedTitle;
274-
} elseif (!empty($data['title'])) {
275-
$methods[$code] = $data['title'];
276-
}
270+
$storeId = $store ? (int)$store->getId() : null;
271+
$storedTitle = $this->getMethodStoreTitle($code, $storeId);
272+
if (!empty($storedTitle)) {
273+
$methods[$code] = $storedTitle;
277274
}
275+
278276
if ($asLabelValue && $withGroups && isset($data['group'])) {
279277
$groupRelations[$code] = $data['group'];
280278
}
@@ -356,4 +354,21 @@ public function getZeroSubTotalPaymentAutomaticInvoice($store = null)
356354
$store
357355
);
358356
}
357+
358+
/**
359+
* Get config title of payment method
360+
*
361+
* @param string $code
362+
* @param int|null $storeId
363+
* @return string
364+
*/
365+
private function getMethodStoreTitle(string $code, $storeId = null): string
366+
{
367+
$configPath = sprintf('%s/%s/title', self::XML_PATH_PAYMENT_METHODS, $code);
368+
return (string) $this->scopeConfig->getValue(
369+
$configPath,
370+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
371+
$storeId
372+
);
373+
}
359374
}

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 the 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 the store config'
59+
);
2360
}
2461
}

0 commit comments

Comments
 (0)