Skip to content

Commit

Permalink
Fix upgrade script
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt75 committed Jul 19, 2023
1 parent 4251bef commit 6f793d1
Showing 1 changed file with 43 additions and 43 deletions.
86 changes: 43 additions & 43 deletions upgrade/upgrade-8.3.4.0.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 6f793d1

Please sign in to comment.