From 959d895190937d73f5cb9f5eab32d44275ec75d8 Mon Sep 17 00:00:00 2001 From: L3RAZ Date: Tue, 16 Jul 2024 17:26:08 +0300 Subject: [PATCH] Added upgrade script for Google Pay funding source creation --- upgrade/upgrade-8.5.0.0.php | 70 +++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 upgrade/upgrade-8.5.0.0.php diff --git a/upgrade/upgrade-8.5.0.0.php b/upgrade/upgrade-8.5.0.0.php new file mode 100644 index 000000000..e7de0d902 --- /dev/null +++ b/upgrade/upgrade-8.5.0.0.php @@ -0,0 +1,70 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 + */ +if (!defined('_PS_VERSION_')) { + exit; +} + +/** + * Update main function for module version 8.5.0.0 + * + * @param Ps_checkout $module + * + * @return bool + */ +function upgrade_module_8_5_0_0($module) +{ + try { + $db = Db::getInstance(); + $shopsList = \Shop::getShops(false, null, true); + + foreach ($shopsList as $shopId) { + $isGooglePayEligible = (bool)\Configuration::get( + 'PS_CHECKOUT_GOOGLE_PAY', + null, + null, + $shopId + ); + $hasFundingSourceGooglePay = (bool)$db->getValue(' + SELECT 1 + FROM `' . _DB_PREFIX_ . 'pscheckout_funding_source` + WHERE `name` = "google_pay" + AND `id_shop` = ' . (int)$shopId + ); + + if (!$hasFundingSourceGooglePay) { + $db->insert( + 'pscheckout_funding_source', + [ + 'name' => 'google_pay', + 'position' => 11, + 'active' => (int)$isGooglePayEligible, + 'id_shop' => (int)$shopId, + ] + ); + } + } + } catch (Exception $exception) { + PrestaShopLogger::addLog($exception->getMessage(), 4, 1, 'Module', $module->id); + + return false; + } + + return true; +}