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');
 }
 $cart = Context::getContext()->cart;
 $discountName = $_REQUEST['discount_name'];
 //POBRANIE KODU Z GET LUB POST
 $customer = new Customer($cart->id_customer);
 //DEFINICJA PODSTAWOWYCH DANYCH ZALOGOWANEGO UŻYTKOWNIKA - PRESTA CODE
 define("SC_CUSTOMER_FIRSTNAME", $customer->firstname);
 define("SC_CUSTOMER_LASTNAME", $customer->lastname);
 define("SC_CUSTOMER_EMAIL", $customer->email);
 //$cart = new Cart();
 $total_cart_price = $cart->getOrderTotal();
 $coupon = new CheckCouponClient($discountName);
 //SPRAWDZENIE ISTNIENIA KODU W SHOPCONNECTOR
 $coupon->setCartValue((string) $total_cart_price);
 $couponData = $coupon->check(HASH);
 $showPopup = $coupon->getShowPopup();
 $showBanner = $coupon->getShowBanner();
 $sendEmail = $coupon->getSendEmail();
 $scShopId = $coupon->getScShopId();
 $minimalCartValue = $coupon->getMinCart();
 //JEŚLI JEST KOD W SHOPCONNECTOR - TO SPRAWDZ CZY JEST JUZ W SYSTEMIE SKLEPU
 if (!empty($discountName)) {
     $discountValue = (string) $coupon->getDiscountType();
     $discount = new CartRuleCore(intval(CartRuleCore::getIdByCode($discountName)));
     //PRESTA CODE
     //JEŚLI KOD NIE ISTNIEJE W SKLEPIE TO DODAJEMY GO, DZIĘKI TEMU MOŻE GO WYKORZYSTAĆ KLIENT
     if (is_object($discount) and !$discount->id) {
         //PRESTA CODE
         if ($couponData === true) {
             try {
                 $object = new CartRuleCore();
                 $object->id_customer = 0;