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'); }
$sc_cookie = array(); } define("HASH", Configuration::get('SHOPCONNECTORMODULE_HASH')); //UNIKALNY HASH KAŻDEGO PARTNERA include_once "check_coupon_client.php"; $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) {
//POBRANIE KODU Z GET LUB POST if ($this->getRequest()->getParam('remove') == 1) { $deleteEvent = true; } else { $deleteEvent = false; } $user = Mage::getSingleton('customer/session')->getCustomer(); if (!empty($user)) { define("SC_CUSTOMER_FIRSTNAME", $user->getFirstname()); define("SC_CUSTOMER_LASTNAME", $user->getLastname()); define("SC_CUSTOMER_EMAIL", $user->getEmail()); } //pobranie wartości z koszyka $total_cart_price = Mage::getSingleton('checkout/cart')->getQuote()->getGrandTotal(); //SPRAWDZENIE ISTNIENIA KODU W SHOPCONNECTOR $coupon = new CheckCouponClient($discountName); //wysyłanie wartości koszyka aby sprawdzić czy jest wyższa niż minimalna wartość zakupów $coupon->setCartValue($total_cart_price); //sprawdzenie kuponu w shopconnector $couponCorrect = $coupon->check(HASH); if ($couponCorrect !== true) { Mage::getSingleton('core/session')->addNotice($couponCorrect); } $myfile = fopen("cokolwiek.txt", "w") or die("Unable to open file!"); $txt = "i tu tez dziala\n"; fwrite($myfile, $txt); fclose($myfile); //JEŚLI JEST KOD W SHOPCONNECTOR - TO SPRAWDZ CZY JEST JUZ W SYSTEMIE SKLEPU if (!empty($discountName) && $couponCorrect === true) { //usuwam ze sklepu if ($deleteEvent) {
} //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); }