Skip to content

Commit

Permalink
Merge pull request #191 from michielgerritsen/bugfix/store-name-in-pa…
Browse files Browse the repository at this point in the history
…yment-description

Bugfix: The correct store name is now used when using the {storename} variable in the payment description
  • Loading branch information
Marvin-Magmodules authored Aug 9, 2019
2 parents c17fb32 + df9a374 commit 1efe205
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
5 changes: 3 additions & 2 deletions Helper/General.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Magento\Sales\Api\OrderManagementInterface;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\OrderRepository;
use Magento\Store\Model\Information;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Config\Model\ResourceModel\Config;
use Magento\Payment\Helper\Data as PaymentHelper;
Expand Down Expand Up @@ -859,15 +860,15 @@ public function resetCouponAfterCancellation($order)
public function getPaymentDescription($method, $orderNumber, $storeId = 0)
{
$xpath = str_replace('%method%', 'mollie_methods_' . $method, self::XML_PATH_PAYMENT_DESCRIPTION);
$description = $this->getStoreConfig($xpath);
$description = $this->getStoreConfig($xpath, $storeId);

if (!trim($description)) {
$description = '{ordernumber}';
}

$replacements = [
'{ordernumber}' => $orderNumber,
'{storename}' => $this->storeManager->getStore($storeId)->getName(),
'{storename}' => $this->getStoreConfig(Information::XML_PATH_STORE_INFO_NAME, $storeId),
];

return str_replace(
Expand Down
2 changes: 1 addition & 1 deletion Model/Client/Payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function startTransaction(Order $order, $mollieApi)
$method = $this->mollieHelper->getMethodCode($order);
$paymentData = [
'amount' => $this->mollieHelper->getOrderAmountByOrder($order),
'description' => $this->mollieHelper->getPaymentDescription($method, $order->getIncrementId()),
'description' => $this->mollieHelper->getPaymentDescription($method, $order->getIncrementId(), $storeId),
'billingAddress' => $this->getAddressLine($order->getBillingAddress()),
'redirectUrl' => $this->mollieHelper->getRedirectUrl($orderId, $paymentToken),
'webhookUrl' => $this->mollieHelper->getWebhookUrl(),
Expand Down
31 changes: 15 additions & 16 deletions Test/Unit/Helper/GeneralTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use Magento\Sales\Api\OrderManagementInterface;
use Magento\Sales\Model\Order as OrderModel;
use Magento\Store\Api\Data\StoreInterface;
use Magento\Store\Model\Information;
use Magento\Store\Model\ScopeInterface;
use Magento\Store\Model\StoreManagerInterface;
use Mollie\Api\MollieApiClient;
use Mollie\Api\Resources\Order;
Expand All @@ -20,6 +22,11 @@ class GeneralTest extends \PHPUnit\Framework\TestCase
*/
private $objectManager;

protected function setUp()
{
$this->objectManager = new ObjectManager($this);
}

public function returnsTheCorrectDescriptionProvider()
{
return [
Expand All @@ -31,36 +38,28 @@ public function returnsTheCorrectDescriptionProvider()
];
}

protected function setUp()
{
$this->objectManager = new ObjectManager($this);
}

/**
* @dataProvider returnsTheCorrectDescriptionProvider
*/
public function testReturnsTheCorrectDescription($description, $expected)
{
$storeConfigMock = $this->createMock(ScopeConfigInterface::class);
$storeManagerMock = $this->createMock(StoreManagerInterface::class);
$storeMock = $this->createMock(StoreInterface::class);

$storeManagerMock->method('getStore')->willReturn($storeMock);
$storeMock->method('getName')->willReturn('My Test Store');

$storeConfigMock->method('getValue')->willReturn($description);
$storeConfigMock->method('getValue')
->withConsecutive(
['payment/mollie_methods_ideal/payment_description', ScopeInterface::SCOPE_STORE, 1],
[Information::XML_PATH_STORE_INFO_NAME, ScopeInterface::SCOPE_STORE, 1]
)
->willReturnOnConsecutiveCalls($description, 'My Test Store');

/** @var MollieHelper $instance */
$instance = $this->objectManager->getObject(MollieHelper::class, [
'storeManager' => $storeManagerMock,
]);
$instance = $this->objectManager->getObject(MollieHelper::class);

// The scopeConfig is burried in the context, use reflection to swap it with our mock
$property = (new \ReflectionObject($instance))->getProperty('scopeConfig');
$property->setAccessible(true);
$property->setValue($instance, $storeConfigMock);

$result = $instance->getPaymentDescription('ideal', '0000025');
$result = $instance->getPaymentDescription('ideal', '0000025', 1);

$this->assertSame($expected, $result);
}
Expand Down

0 comments on commit 1efe205

Please sign in to comment.