<?php
/**
 * Mageplaza
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Mageplaza.com license that is
 * available through the world-wide-web at this URL:
 * https://www.mageplaza.com/LICENSE.txt
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade this extension to newer
 * version in the future.
 *
 * @category    Mageplaza
 * @package     Mageplaza_Smtp
 * @copyright   Copyright (c) Mageplaza (https://www.mageplaza.com/)
 * @license     https://www.mageplaza.com/LICENSE.txt
 */

/**
 * @var \Mageplaza\Smtp\Block\Script $block
 */

$shopId = $block->getHelperEmailMarketing()->getAppID();
$isSuccessPage = $block->isSuccessPage();
?>
<!-- BEGIN AVADA EMAIL MARKETING SCRIPT-->
<?php if ($isSuccessPage && $block->getCurrentOrder()) {
    $order = $block->getCurrentOrder();
    $grandTotal = $order->getGrandTotal();
    $currencyCode = $order->getOrderCurrencyCode();
    $checkoutId = $order->getQuoteId();
    $email = $order->getCustomerEmail();

    ?>
    <script data-cfasync="false" type="text/javascript">
        var AVADA_EM = {
            shopId: "<?= /* @noEscape */ $shopId ?>",
            vendor: "magento",
            checkout: {
                revenue: "<?=  /* @noEscape */ $grandTotal ?>",
                currency: "<?=  /* @noEscape */ $currencyCode ?>",
                checkoutId: "<?=  /* @noEscape */ $checkoutId ?>",
                checkoutEmail: "<?=  /* @noEscape */ $email ?>"
            }
        };
        window.AVADA_EM = window.AVADA_EM||{};
        window.AVADA_EM.shopId = "<?= /* @noEscape */ $shopId ?>";
    </script>
<?php } ?>
<script data-cfasync="false" type="text/javascript">(function(b){var s=document.createElement("script");s.type="text/javascript";s.async=true;s.src=b;var x=document.getElementsByTagName("script")[0];x.parentNode.insertBefore(s,x);})("https://app.avada.io/avada-sdk.min.js");</script>