<?php

declare(strict_types=1);

/**
 * Copyright 2024-2025 Simply.IN Sp. z o.o.
 *
 * NOTICE OF LICENSE
 *
 * Licensed under the EUPL-1.2 or later.
 * You may not use this work except in compliance with the Licence.
 *
 * Copy of the Licence is available at:
 * https://joinup.ec.europa.eu/software/page/eupl
 * It is bundled with this package in the file LICENSE.txt
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the Licence is distributed on an as is basis,
 * without warranties or conditions of any kind, either express or implied.
 * Check the Licence for the specific language governing permissions
 * and limitations under the License.
 *
 * @author   Simply.IN Sp. z o.o.
 * @copyright 2024-2025 Simply.IN Sp. z o.o.
 * @license   https://joinup.ec.europa.eu/software/page/eupl
 */

if (!defined('_PS_VERSION_')) {
    exit;
}

/**
 * Migrates the cart-page 1-click badge from `displayShoppingCartFooter` to `displayExpressCheckout`
 * (theme hook right after "Proceed to checkout", inside the order-summary card) for every shop
 * installed before this version. A fresh install already registers only `displayExpressCheckout`
 * via {@see \SimplyIn\Install\HookRegistry::hooks()} — this only affects upgrades.
 *
 * `hookDisplayShoppingCartFooter()` stays in `simplyin.php` as a compatibility shim (renders the
 * same offer) so a shop is never left without the badge between this deploy and this script
 * actually running against its DB. Once every shop has run this migration, both the shim method
 * and {@see \SimplyIn\Install\HookRegistry::legacyHooksToUnregister()} can be deleted.
 *
 * registerHook()/unregisterHook() are idempotent in PrestaShop, so re-running this is harmless.
 *
 * @param \Simplyin $module
 *
 * @return bool
 */
function upgrade_module_8_1_41($module)
{
    $module->unregisterHook('displayShoppingCartFooter');
    $module->registerHook('displayExpressCheckout');

    return true;
}
