Skip to content

Commit

Permalink
Version bump and upgrade file fix (#800)
Browse files Browse the repository at this point in the history
  • Loading branch information
mandan2 authored Sep 4, 2023
1 parent 2b45b31 commit 2bde6b2
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 101 deletions.
2 changes: 1 addition & 1 deletion mollie.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function __construct()
{
$this->name = 'mollie';
$this->tab = 'payments_gateways';
$this->version = '6.0.3';
$this->version = '6.0.4';
$this->author = 'Mollie B.V.';
$this->need_instance = 1;
$this->bootstrap = true;
Expand Down
100 changes: 0 additions & 100 deletions upgrade/Upgrade-6.0.3.php

This file was deleted.

80 changes: 80 additions & 0 deletions upgrade/Upgrade-6.0.4.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
* @see https://github.com/mollie/PrestaShop
*/

use Mollie\Adapter\ConfigurationAdapter;
use Mollie\Config\Config;
use Mollie\Utility\PsVersionUtility;

if (!defined('_PS_VERSION_')) {
Expand All @@ -23,5 +25,83 @@ function upgrade_module_6_0_4(Mollie $module): bool
$module->registerHook('actionFrontControllerInitAfter');
}

updateConfigurationValues604($module);
updateOrderStatusNames604($module);

return true;
}

function updateConfigurationValues604(Mollie $module)
{
/** @var ConfigurationAdapter $configuration */
$configuration = $module->getService(ConfigurationAdapter::class);

if (
!empty($configuration->get(Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_AUTHORIZED))
&& !empty($configuration->get(Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_SHIPPED))
&& !empty($configuration->get(Config::MOLLIE_AUTHORIZABLE_PAYMENT_INVOICE_ON_STATUS))
&& empty($configuration->get('MOLLIE_STATUS_KLARNA_AUTHORIZED'))
&& empty($configuration->get('MOLLIE_STATUS_KLARNA_SHIPPED'))
&& empty($configuration->get('MOLLIE_KLARNA_INVOICE_ON'))
) {
return;
}

$klarnaInvoiceOn = $configuration->get('MOLLIE_KLARNA_INVOICE_ON');

switch ($klarnaInvoiceOn) {
case 'MOLLIE_STATUS_KLARNA_AUTHORIZED':
$configuration->updateValue(
Config::MOLLIE_AUTHORIZABLE_PAYMENT_INVOICE_ON_STATUS,
Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_AUTHORIZED
);
break;
case 'MOLLIE_STATUS_KLARNA_SHIPPED':
$configuration->updateValue(
Config::MOLLIE_AUTHORIZABLE_PAYMENT_INVOICE_ON_STATUS,
Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_SHIPPED
);
break;
default:
$configuration->updateValue(
Config::MOLLIE_AUTHORIZABLE_PAYMENT_INVOICE_ON_STATUS,
Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_DEFAULT
);
}

$configuration->updateValue(Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_AUTHORIZED, (int) $configuration->get('MOLLIE_STATUS_KLARNA_AUTHORIZED'));
$configuration->updateValue(Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_SHIPPED, (int) $configuration->get('MOLLIE_STATUS_KLARNA_SHIPPED'));

$configuration->delete('MOLLIE_STATUS_KLARNA_AUTHORIZED');
$configuration->delete('MOLLIE_STATUS_KLARNA_SHIPPED');
$configuration->delete('MOLLIE_KLARNA_INVOICE_ON');
}

function updateOrderStatusNames604(Mollie $module)
{
/** @var ConfigurationAdapter $configuration */
$configuration = $module->getService(ConfigurationAdapter::class);

$authorizablePaymentStatusShippedId = (int) $configuration->get(Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_SHIPPED);
$authorizablePaymentStatusShipped = new OrderState((int) $authorizablePaymentStatusShippedId);

if (is_array($authorizablePaymentStatusShipped->name)) {
foreach ($authorizablePaymentStatusShipped->name as $langId => $name) {
$authorizablePaymentStatusShipped->name[$langId] = 'Order payment shipped';
}
}

$authorizablePaymentStatusShipped->save();

$authorizablePaymentStatusAuthorizedId = (int) $configuration->get(Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_AUTHORIZED);
$authorizablePaymentStatusAuthorized = new OrderState((int) $authorizablePaymentStatusAuthorizedId);

if (is_array($authorizablePaymentStatusAuthorized->name)) {
foreach ($authorizablePaymentStatusAuthorized->name as $langId => $name) {
$authorizablePaymentStatusAuthorized->name[$langId] = 'Order payment authorized';
}
}

$authorizablePaymentStatusAuthorized->save();
}

0 comments on commit 2bde6b2

Please sign in to comment.