<?php

$path = "../../";
require_once $path . 'core/includes/header.inc.php';

$order = new Order($_SESSION['order_id']);

$weight_verification = config('weight_verification.enabled')
    ? \Mtc\Plugins\WeightVerification\Src\Models\WeightVerification::query()
        ->where('order_id', $order->getId())
        ->first()
    : null;

$tracking_codes = [];
if ($order->getId()) {
    $tracking_codes[] = $twig->render('analytics_js.twig', [
        'order' => $order,
        'settings' => $GLOBALS['settings'],
    ]);
}

$page_meta = [
    'title' => 'Your order is now complete | ' . config('app.name'),
    'page_title' => 'Order Complete',
    'page_sub_title' => 'Thank you for shopping online with ' . config('app.name'),
];

$_SESSION['basket_id'] = '';
unset($basket);
$basket = new Basket();
$basket->Go_basket();

echo $twig->render('shop/checkout/order_complete.twig', [
    'page_html' => $_SESSION['basket_html'],
    'basket_object' => $order,
    'page_meta' => $page_meta,
    'tracking_code' => $tracking_codes,
    'weight_verification_required' => $weight_verification && $weight_verification->action_required,
]);
