Skip to content

Commit

Permalink
Merge pull request #189 from michielgerritsen/bugfix/order-free-products
Browse files Browse the repository at this point in the history
Bugfix: It is now possible to order free products that have a shipping price
  • Loading branch information
Marvin-Magmodules authored Aug 9, 2019
2 parents 07c2131 + 53c217a commit c17fb32
Show file tree
Hide file tree
Showing 22 changed files with 144 additions and 50 deletions.
5 changes: 5 additions & 0 deletions Model/Mollie.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ public function isAvailable(\Magento\Quote\Api\Data\CartInterface $quote = null)
return false;
}

$activeMethods = $this->mollieHelper->getAllActiveMethods($quote->getStoreId());
if (!array_key_exists($this->_code, $activeMethods)) {
return false;
}

return parent::isAvailable($quote);
}

Expand Down
94 changes: 47 additions & 47 deletions Model/MollieConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,58 +138,53 @@ public function getConfig()

try {
$mollieApi = $this->mollieModel->loadMollieApi($apiKey);
$activeMethods = $this->getActiveMethods($mollieApi);
} catch (\Exception $e) {
$mollieApi = '';
$this->mollieHelper->addTolog('error', $e->getMessage());
$activeMethods = [];
}

foreach ($this->methodCodes as $code) {
if (!empty($this->methods[$code]) && $this->methods[$code]->isAvailable()) {
if (!empty($activeMethods[$code])) {
$config['payment']['isActive'][$code] = true;
$config['payment']['instructions'][$code] = $this->getInstructions($code);
if ($useImage && isset($activeMethods[$code]['image'])) {
$config['payment']['image'][$code] = $activeMethods[$code]['image'];
} else {
$config['payment']['image'][$code] = '';
}
if ($code == 'mollie_methods_ideal') {
$issuerListType = $this->mollieHelper->getIssuerListType($code);
$config['payment']['issuersListType'][$code] = $issuerListType;
$config['payment']['issuers'][$code] = $this->mollieModel->getIssuers(
$mollieApi,
$code,
$issuerListType
);
}
if ($code == 'mollie_methods_kbc') {
$issuerListType = $this->mollieHelper->getIssuerListType($code);
$config['payment']['issuersListType'][$code] = $issuerListType;
$config['payment']['issuers'][$code] = $this->mollieModel->getIssuers(
$mollieApi,
$code,
$issuerListType
);
}
if ($code == 'mollie_methods_giftcard') {
$issuerListType = $this->mollieHelper->getIssuerListType($code);
$config['payment']['issuersListType'][$code] = $issuerListType;
$config['payment']['issuers'][$code] = $this->mollieModel->getIssuers(
$mollieApi,
$code,
$issuerListType
);
if (empty($config['payment']['issuers'][$code])) {
$config['payment']['isActive'][$code] = false;
}
}
} else {
$config['payment']['isActive'][$code] = false;
}
} else {
$config['payment']['isActive'][$code] = false;
if (empty($this->methods[$code]) || !$this->methods[$code]->isAvailable()) {
continue;
}

$config['payment']['instructions'][$code] = $this->getInstructions($code);

$config['payment']['image'][$code] = '';
if ($useImage) {
$cleanCode = str_replace('mollie_methods_', '', $code);
$url = $this->assetRepository->getUrl('Mollie_Payment::images/methods/' . $cleanCode . '.png');
$config['payment']['image'][$code] = $url;
}

if ($code == 'mollie_methods_ideal') {
$issuerListType = $this->mollieHelper->getIssuerListType($code);
$config['payment']['issuersListType'][$code] = $issuerListType;
$config['payment']['issuers'][$code] = $this->mollieModel->getIssuers(
$mollieApi,
$code,
$issuerListType
);
}

if ($code == 'mollie_methods_kbc') {
$issuerListType = $this->mollieHelper->getIssuerListType($code);
$config['payment']['issuersListType'][$code] = $issuerListType;
$config['payment']['issuers'][$code] = $this->mollieModel->getIssuers(
$mollieApi,
$code,
$issuerListType
);
}

if ($code == 'mollie_methods_giftcard') {
$issuerListType = $this->mollieHelper->getIssuerListType($code);
$config['payment']['issuersListType'][$code] = $issuerListType;
$config['payment']['issuers'][$code] = $this->mollieModel->getIssuers(
$mollieApi,
$code,
$issuerListType
);
}
}

Expand All @@ -203,7 +198,11 @@ public function getConfig()
*/
public function getActiveMethods($mollieApi)
{
$methodData = [];
static $methodData = null;

if ($methodData !== null) {
return $methodData;
}

try {
$quote = $this->checkoutSession->getQuote();
Expand All @@ -224,6 +223,7 @@ public function getActiveMethods($mollieApi)
}
} catch (\Exception $e) {
$this->mollieHelper->addTolog('error', 'Function: getActiveMethods: ' . $e->getMessage());
$methodData = [];
}

return $methodData;
Expand Down
52 changes: 52 additions & 0 deletions Test/Integration/Model/MollieConfigProviderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace Mollie\Payment\Test\Integration\Model;

use Mollie\Payment\Model\MollieConfigProvider;
use Mollie\Payment\Test\Integration\IntegrationTestCase;

class MollieConfigProviderTest extends IntegrationTestCase
{
/**
* @magentoConfigFixture default_store payment/mollie_general/enabled 1
* @magentoConfigFixture default_store payment/mollie_general/apikey_test test_TEST_API_KEY
* @magentoConfigFixture default_store payment/mollie_general/type test
*
* @magentoConfigFixture default_store payment/mollie_methods_bancontact/active 1
* @magentoConfigFixture default_store payment/mollie_methods_bancontact/active 1
* @magentoConfigFixture default_store payment/mollie_methods_banktransfer/active 1
* @magentoConfigFixture default_store payment/mollie_methods_belfius/active 1
* @magentoConfigFixture default_store payment/mollie_methods_creditcard/active 1
* @magentoConfigFixture default_store payment/mollie_methods_paypal/active 1
* @magentoConfigFixture default_store payment/mollie_methods_paysafecard/active 1
* @magentoConfigFixture default_store payment/mollie_methods_sofort/active 1
* @magentoConfigFixture default_store payment/mollie_methods_inghomepay/active 1
* @magentoConfigFixture default_store payment/mollie_methods_giropay/active 1
* @magentoConfigFixture default_store payment/mollie_methods_eps/active 1
* @magentoConfigFixture default_store payment/mollie_methods_klarnapaylater/active 1
* @magentoConfigFixture default_store payment/mollie_methods_klarnasliceit/active 1
* @magentoConfigFixture default_store payment/mollie_methods_przelewy24/active 1
* @magentoConfigFixture default_store payment/mollie_methods_applepay/active 1
* @magentoConfigFixture default_store payment/mollie_methods_ideal/active 1
* @magentoConfigFixture default_store payment/mollie_methods_kbc/active 1
* @magentoConfigFixture default_store payment/mollie_methods_giftcard/active 1
*/
public function testGetConfig()
{
/** @var MollieConfigProvider $instance */
$instance = $this->objectManager->get(MollieConfigProvider::class);

$result = $instance->getConfig();

$this->assertCount(17, $result['payment']['instructions']);
$this->assertCount(17, $result['payment']['image']);

$this->assertArrayHasKey('mollie_methods_ideal', $result['payment']['issuersListType']);
$this->assertArrayHasKey('mollie_methods_kbc', $result['payment']['issuersListType']);
$this->assertArrayHasKey('mollie_methods_giftcard', $result['payment']['issuersListType']);

$this->assertEquals([], $result['payment']['issuers']['mollie_methods_ideal']);
$this->assertEquals([], $result['payment']['issuers']['mollie_methods_kbc']);
$this->assertEquals([], $result['payment']['issuers']['mollie_methods_giftcard']);
}
}
39 changes: 39 additions & 0 deletions Test/Unit/Model/MollieConfigProviderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Mollie\Payment\Test\Unit\Model;

use Mollie\Payment\Helper\General;
use Mollie\Payment\Model\MollieConfigProvider;
use Mollie\Payment\Test\Unit\UnitTestCase;

class MollieConfigProviderTest extends UnitTestCase
{
public function testCallsTheApiOnlyOnce()
{
$client = new \Mollie\Api\MollieApiClient;

$methodsEndpointMock = $this->createMock(\Mollie\Api\Endpoints\MethodEndpoint::class);
$methodsEndpointMock->expects($this->once())->method('all')->willReturn([
(object)[
'id' => 'ideal',
'image' => (object)[
'size2x' => 'ideal.png',
]
]
]);
$client->methods = $methodsEndpointMock;

/** @var MollieConfigProvider $instance */
$instance = $this->objectManager->getObject(MollieConfigProvider::class);

$result = $instance->getActiveMethods($client);
$this->assertTrue(is_array($result));
$this->assertArrayHasKey('mollie_methods_ideal', $result);
$this->assertEquals('ideal.png', $result['mollie_methods_ideal']['image']);

$result = $instance->getActiveMethods($client);
$this->assertTrue(is_array($result));
$this->assertArrayHasKey('mollie_methods_ideal', $result);
$this->assertEquals('ideal.png', $result['mollie_methods_ideal']['image']);
}
}
Binary file added view/frontend/web/images/methods/applepay.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added view/frontend/web/images/methods/bancontact.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added view/frontend/web/images/methods/belfius.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added view/frontend/web/images/methods/creditcard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added view/frontend/web/images/methods/eps.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added view/frontend/web/images/methods/giftcard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added view/frontend/web/images/methods/giropay.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added view/frontend/web/images/methods/ideal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added view/frontend/web/images/methods/inghomepay.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added view/frontend/web/images/methods/kbc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added view/frontend/web/images/methods/paypal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added view/frontend/web/images/methods/paysafecard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added view/frontend/web/images/methods/przelewy24.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added view/frontend/web/images/methods/sofort.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 1 addition & 3 deletions view/frontend/web/js/view/payment/method-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ define(
}

$.each(methods, function (k, method) {
if (window.checkoutConfig.payment.isActive[method['type']]) {
rendererList.push(method);
}
rendererList.push(method);
});

return Component.extend({});
Expand Down

0 comments on commit c17fb32

Please sign in to comment.