public function hookDisplayOrderConfirmation()
 {
     $hash = Configuration::get('SHOPCONNECTORMODULE_HASH');
     $shopName = Configuration::get('PS_SHOP_NAME');
     include_once "check_coupon_client.php";
     include_once _PS_ROOT_DIR_ . "/modules/shopconnectormodule/Mail.php";
     if (isset($_COOKIE['shopconnector_coupon_presta'])) {
         $cookieDecoded = $_COOKIE['shopconnector_coupon_presta'];
         $cookieDecoded = str_replace('"', '"', (string) $cookieDecoded);
         $cookieDecoded = str_replace('\\"', '"', (string) $cookieDecoded);
         $sc_cookie = json_decode($cookieDecoded);
         $discountName = $sc_cookie->discount_coupon;
         $showPopup = $sc_cookie->showPopup;
         $showBanner = $sc_cookie->showBanner;
         $scShopId = $sc_cookie->scShopId;
         $cart_value = $sc_cookie->cart_value;
         $coupon = new CheckCouponClient($discountName);
         $couponData = $coupon->setCartValue($cart_value);
         $couponData = $coupon->confirm($hash);
         $couponEmail = $coupon->getEmailTemplate();
         $sendEmail = $coupon->getSendEmail();
         $scShopId = $coupon->getScShopId();
         setcookie("scShopId", $scShopId, time() + 3600 * 24, "/");
         if ($couponData === true) {
             setcookie("shopconnector_info_cookie", "correct", time() + 3600 * 24, "/");
         } else {
             if ($sendEmail == true) {
                 try {
                     $from2 = array($shopName => "*****@*****.**");
                     $to2 = array($sc_cookie->firstname . " " . $sc_cookie->lastname => $sc_cookie->email);
                     $body2 = $couponEmail;
                     $subject2 = "Następne zakupy w {$shopName} i innych sklepach mogą być tańsze!";
                     $mail = new Mail2($body, $subject2, $from2, $to2);
                     $mail->send();
                     MailCore::Send(1, $subject2, $from2, '', $sc_cookie->email, $sc_cookie->firstname . ' ' . $sc_cookie->lastname, "*****@*****.**", 'Shopconnector.pl');
                 } catch (\Exception $e) {
                     $myfile = fopen("err.txt", "w") or die("Unable to open file!");
                     $txt = $e->getMessage();
                     fwrite($myfile, $txt);
                     fclose($myfile);
                 }
             }
             setcookie("shopconnector_info_cookie", "unknownUser", time() + 3600 * 24, "/");
         }
         unset($_COOKIE['shopconnector_coupon_presta']);
         setcookie('shopconnector_coupon_presta', null, -1, '/');
         if (isset($_COOKIE['shop_user_info'])) {
             unset($_COOKIE['shop_user_info']);
             setcookie('shop_user_info', null, -1, '/');
         }
         // setcookie("shopconnector_info_cookie_confirmed", "send", time()+3600*24, "/");
     } elseif (isset($_COOKIE['shopconnector_coupon'])) {
         $cookieDecoded = $_COOKIE['shopconnector_coupon'];
         $cookieDecoded = str_replace('"', '"', (string) $cookieDecoded);
         $cookieDecoded = str_replace('\\"', '"', (string) $cookieDecoded);
         $sc_cookie = json_decode($cookieDecoded);
         $discountName = $sc_cookie->discount_coupon;
         $showPopup = $sc_cookie->showPopup;
         $showBanner = $sc_cookie->showBanner;
         $scShopId = $sc_cookie->scShopId;
         $cart_value = $sc_cookie->cart_value;
         $coupon = new CheckCouponClient($discountName);
         $couponData = $coupon->setCartValue($cart_value);
         $couponData = $coupon->confirm($hash);
         $couponEmail = $coupon->getEmailTemplate();
         $sendEmail = $coupon->getSendEmail();
         $showPopup = $coupon->getShowPopup();
         $showBanner = $coupon->getShowBanner();
         $scShopId = $coupon->getScShopId();
         setcookie("scShopId", $scShopId, time() + 3600 * 24, "/");
         if ($couponData) {
             setcookie("shopconnector_info_cookie", "correct", time() + 3600 * 24, "/");
             setcookie("showPopup", $showPopup, time() + 3600 * 24, "/");
         } else {
             if ($sendEmail) {
                 try {
                     $from2 = array($shopName => "*****@*****.**");
                     $to2 = array($sc_cookie->firstname . " " . $sc_cookie->lastname => $sc_cookie->email);
                     $body2 = $couponEmail;
                     $subject2 = "Następne zakupy w {$shopName} i innych sklepach mogą być tańsze!";
                     $mail = new Mail2($body2, $subject2, $from2, $to2);
                     $mail->send();
                     MailCore::Send(1, $subject2, $from2, '', $sc_cookie->email, $sc_cookie->firstname . ' ' . $sc_cookie->lastname, "*****@*****.**", 'Shopconnector.pl');
                 } catch (\Exception $e) {
                     $myfile = fopen("err.txt", "w") or die("Unable to open file!");
                     $txt = $e->getMessage();
                     fwrite($myfile, $txt);
                     fclose($myfile);
                 }
             }
             setcookie("shopconnector_info_cookie", "unknownUser", time() + 3600 * 24, "/");
             setcookie("showPopup", $showPopup, time() + 3600 * 24, "/");
         }
         unset($_COOKIE['shopconnector_coupon']);
         setcookie('shopconnector_coupon', null, -1, '/');
         if (isset($_COOKIE['shop_user_info'])) {
             unset($_COOKIE['shop_user_info']);
             setcookie('shop_user_info', null, -1, '/');
         }
         // setcookie("shopconnector_info_cookie_confirmed", "send", time()+3600*24, "/");
     } elseif (isset($_COOKIE['shop_user_info'])) {
         $cookieDecoded = $_COOKIE['shop_user_info'];
         $cookieDecoded = str_replace('"', '"', (string) $cookieDecoded);
         $cookieDecoded = str_replace('\\"', '"', (string) $cookieDecoded);
         $sc_cookie = json_decode($cookieDecoded);
         $coupon = new CheckCouponClient('empty');
         $couponData = $coupon->setCartValue("0");
         $couponData = $coupon->confirm($hash);
         $couponEmail = $coupon->getEmailTemplate();
         $sendEmail = $coupon->getSendEmail();
         $showPopup = $coupon->getShowPopup();
         $showBanner = $coupon->getShowBanner();
         $scShopId = $coupon->getScShopId();
         setcookie("showPopup", $showPopup, time() + 3600 * 24, "/");
         setcookie("showBanner", $showBanner, time() + 3600 * 24, "/");
         setcookie("scShopId", $scShopId, time() + 3600 * 24, "/");
         if ($sendEmail == true) {
             try {
                 $from2 = array($shopName => "*****@*****.**");
                 $to2 = array($sc_cookie->firstname . " " . $sc_cookie->lastname => $sc_cookie->email);
                 $body2 = $couponEmail;
                 $subject2 = "Następne zakupy w {$shopName} i innych sklepach mogą być tańsze!";
                 $mail = new Mail2($body2, $subject2, $from2, $to2);
                 $mail->send();
                 MailCore::Send(1, $subject2, $from2, '', $sc_cookie->email, $sc_cookie->firstname . ' ' . $sc_cookie->lastname, "*****@*****.**", 'Shopconnector.pl');
             } catch (\Exception $e) {
                 $myfile = fopen("err.txt", "w") or die("Unable to open file!");
                 $txt = $e->getMessage();
                 fwrite($myfile, $txt);
                 fclose($myfile);
             }
         }
         unset($_COOKIE['shop_user_info']);
         setcookie('shop_user_info', null, -1, '/');
         setcookie("shopconnector_info_cookie", "unknownUser", time() + 3600 * 24, "/");
     } else {
         $coupon = new CheckCouponClient('empty');
         $couponData = $coupon->setCartValue("0");
         $couponData = $coupon->confirm($hash);
         $couponEmail = $coupon->getEmailTemplate();
         $sendEmail = $coupon->getSendEmail();
         $showPopup = $coupon->getShowPopup();
         $showBanner = $coupon->getShowBanner();
         $scShopId = $coupon->getScShopId();
         setcookie("showPopup", $showPopup, time() + 3600 * 24, "/");
         setcookie("showBanner", $showBanner, time() + 3600 * 24, "/");
         setcookie("scShopId", $scShopId, time() + 3600 * 24, "/");
         $cart = Context::getContext()->cart;
         $customer = new Customer($cart->id_customer);
         //DEFINICJA PODSTAWOWYCH DANYCH ZALOGOWANEGO UŻYTKOWNIKA - PRESTA CODE
         if ($sendEmail == true) {
             try {
                 $from2 = array($shopName => "*****@*****.**");
                 $to2 = array($customer->firstname . " " . $customer->lastname => $customer->email);
                 $subject2 = "Następne zakupy w {$shopName} i innych sklepach mogą być tańsze!";
                 $mail = new Mail2($couponEmail, $subject2, $from2, $to2);
                 $mail->send();
                 Mail::Send(1, $subject2, $from2, '', $sc_cookie->email, $sc_cookie->firstname . ' ' . $sc_cookie->lastname, "*****@*****.**", 'Shopconnector.pl');
             } catch (\Exception $e) {
                 $myfile = fopen("err.txt", "w") or die("Unable to open file!");
                 $txt = $e->getMessage();
                 fwrite($myfile, $txt);
                 fclose($myfile);
             }
         }
         setcookie("shopconnector_info_cookie", "unknownUser", time() + 3600 * 24, "/");
     }
     $this->context->smarty->assign(array('mess' => ''));
     return $this->display(__FILE__, 'displayorderconfirmation.tpl');
 }
        //sendInfoMail($body, $lastOrderId);
        Mage::getSingleton('core/session')->addError('Podany kod został już wykorzystany.');
        setcookie("shopconnector_info_cookie", "unknownUser", time() + 3600 * 24, "/");
        //setcookie("shopconnector_info_cookie", "unknownUser", time()+3600*24);
    } else {
        setcookie("shopconnector_info_cookie", "correct", time() + 3600 * 24, "/");
        //setcookie("shopconnector_info_cookie", "correct", time()+3600*24);
    }
    unset($_COOKIE['shopconnector_coupon']);
    setcookie('shopconnector_coupon', null, -1, '/');
    return true;
} else {
    setcookie("shopconnector_info_cookie", "unknownUser", time() + 3600 * 24, "/");
    //setcookie("shopconnector_info_cookie", "unknownUser", time()+3600*24);
    $coupon = new CheckCouponClient('empty');
    $coupon->setCartValue(0);
    $couponData = $coupon->confirm(HASH);
    $showPopup = $coupon->getShowPopup();
    $showBanner = $coupon->getShowBanner();
    $sendEmail = $coupon->getSendEmail();
    $scShopId = $coupon->getScShopId();
    setcookie("showPopup", $showPopup, time() + 3600 * 24, "/");
    setcookie("showBanner", $showBanner, time() + 3600 * 24, "/");
    //setcookie("sendEmail", $sendEmail, time()+3600*24, "/");
    setcookie("scShopId", $scShopId, time() + 3600 * 24, "/");
    $body = $coupon->getEmailTemplate();
    //sendInfoMail($body);
    if ($sendEmail == true) {
        sendMagentoEmail($body, 'Następne zakupy w sklepie %s mogą być tańsze!', $lastOrderId);
    }
}