From 6f793d1245b5ea97c494d1ee80b96ad45aa18ba5 Mon Sep 17 00:00:00 2001 From: Matt75 <5262628+Matt75@users.noreply.github.com> Date: Wed, 19 Jul 2023 12:11:36 +0200 Subject: [PATCH] Fix upgrade script --- upgrade/upgrade-8.3.4.0.php | 86 ++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/upgrade/upgrade-8.3.4.0.php b/upgrade/upgrade-8.3.4.0.php index d5a5fb933..0ec225efe 100644 --- a/upgrade/upgrade-8.3.4.0.php +++ b/upgrade/upgrade-8.3.4.0.php @@ -47,49 +47,6 @@ function upgrade_module_8_3_4_0($module) $db = Db::getInstance(); - // Installing FundingSource if table pscheckout_funding_source is empty or incomplete - including BLIK - $fundingSources = ['paypal', 'paylater', 'card', 'bancontact', 'eps', 'giropay', 'ideal', 'mybank', 'p24', 'sofort', 'blik']; - $availableFundingSourcesByShops = []; - $maxPositionByShops = []; - $availableFundingSources = $db->executeS('SELECT * FROM ' . _DB_PREFIX_ . 'pscheckout_funding_source'); - - if (!empty($availableFundingSources)) { - foreach ($availableFundingSources as $availableFundingSource) { - $currentPosition = (int) $availableFundingSource['position']; - $shopId = (int) $availableFundingSource['id_shop']; - - if ( - !isset($maxPositionByShops[$shopId]) - || $maxPositionByShops[$shopId] < $currentPosition - ) { - $maxPositionByShops[$shopId] = $currentPosition; - } - - $availableFundingSourcesByShops[$shopId][] = $availableFundingSource['name']; - } - } - - foreach (Shop::getShops(false, null, true) as $shopId) { - $currentPosition = isset($maxPositionByShops[(int) $shopId]) ? $maxPositionByShops[(int) $shopId] + 1 : 1; - foreach ($fundingSources as $fundingSource) { - if ( - !isset($availableFundingSourcesByShops[(int) $shopId]) - || !in_array($fundingSource, $availableFundingSourcesByShops[(int) $shopId], true) - ) { - $db->insert( - 'pscheckout_funding_source', - [ - 'name' => pSQL($fundingSource), - 'active' => 1, - 'position' => (int) $currentPosition, - 'id_shop' => (int) $savedShopId, - ] - ); - ++$currentPosition; - } - } - } - // Check module OrderState $moduleOrderStates = [ 'PS_CHECKOUT_STATE_PENDING' => (int) Configuration::getGlobalValue('PS_CHECKOUT_STATE_PENDING'), @@ -203,6 +160,49 @@ function upgrade_module_8_3_4_0($module) Configuration::updateGlobalValue($configuration_key, $id_order_state); } } + + // Installing FundingSource if table pscheckout_funding_source is empty or incomplete - including BLIK + $fundingSources = ['paypal', 'paylater', 'card', 'bancontact', 'eps', 'giropay', 'ideal', 'mybank', 'p24', 'sofort', 'blik']; + $availableFundingSourcesByShops = []; + $maxPositionByShops = []; + $availableFundingSources = $db->executeS('SELECT * FROM ' . _DB_PREFIX_ . 'pscheckout_funding_source'); + + if (!empty($availableFundingSources)) { + foreach ($availableFundingSources as $availableFundingSource) { + $currentPosition = (int) $availableFundingSource['position']; + $shopId = (int) $availableFundingSource['id_shop']; + + if ( + !isset($maxPositionByShops[$shopId]) + || $maxPositionByShops[$shopId] < $currentPosition + ) { + $maxPositionByShops[$shopId] = $currentPosition; + } + + $availableFundingSourcesByShops[$shopId][] = $availableFundingSource['name']; + } + } + + foreach (Shop::getShops(false, null, true) as $shopId) { + $currentPosition = isset($maxPositionByShops[(int) $shopId]) ? $maxPositionByShops[(int) $shopId] + 1 : 1; + foreach ($fundingSources as $fundingSource) { + if ( + !isset($availableFundingSourcesByShops[(int) $shopId]) + || !in_array($fundingSource, $availableFundingSourcesByShops[(int) $shopId], true) + ) { + $db->insert( + 'pscheckout_funding_source', + [ + 'name' => pSQL($fundingSource), + 'active' => 1, + 'position' => (int) $currentPosition, + 'id_shop' => (int) $shopId, + ] + ); + ++$currentPosition; + } + } + } } catch (Exception $exception) { PrestaShopLogger::addLog($exception->getMessage(), 3, $exception->getCode(), 'Module', $module->id);