From b4ad9eae30ba263c8987c4c5169afc502b20a874 Mon Sep 17 00:00:00 2001 From: Tlapi Date: Wed, 31 Jan 2018 15:50:42 +0100 Subject: [PATCH] init version --- monster_ecomail/config.xml | 13 + monster_ecomail/lib/api.php | 140 +++++ monster_ecomail/logo.png | Bin 0 -> 6616 bytes monster_ecomail/monster_ecomail.php | 502 ++++++++++++++++++ .../blocknewsletter/blocknewsletter.php | 23 + 5 files changed, 678 insertions(+) create mode 100644 monster_ecomail/config.xml create mode 100644 monster_ecomail/lib/api.php create mode 100644 monster_ecomail/logo.png create mode 100644 monster_ecomail/monster_ecomail.php create mode 100644 monster_ecomail/override/modules/blocknewsletter/blocknewsletter.php diff --git a/monster_ecomail/config.xml b/monster_ecomail/config.xml new file mode 100644 index 0000000..b4db180 --- /dev/null +++ b/monster_ecomail/config.xml @@ -0,0 +1,13 @@ + + + monster_ecomail + + + + + + + 1 + 0 + cs + \ No newline at end of file diff --git a/monster_ecomail/lib/api.php b/monster_ecomail/lib/api.php new file mode 100644 index 0000000..892b9d7 --- /dev/null +++ b/monster_ecomail/lib/api.php @@ -0,0 +1,140 @@ +APIKey = $arg; + + return $this; + } + + public function getListsCollection() { + + return $this->call( 'lists' ); + + } + + public function subscribeToList( $listId, $customerData ) { + + return $this->call( + sprintf( + 'lists/%d/subscribe', + $listId + ), + 'POST', + array( + 'subscriber_data' => $customerData, + 'resubscribe' => true, + 'update_existing' => true + ) + ); + + } + + public function createTransaction( Order $order ) { + + $shopUrl = new ShopUrl( $order->id_shop ); + + $addressData = array(); + if(Configuration::get('MONSTER_ECOMAIL_LOAD_ADDRESS')) { + $addressDelivery = new Address($order->id_address_delivery); + + $addressData = array( + 'city' => $addressDelivery->city, + 'country' => $addressDelivery->country + ); + } + + $arr = array(); + foreach ($order->getProducts() as $orderProduct) { + $product = new Product($orderProduct['product_id']); + $category = new Category($product->getDefaultCategory()); + $arr[] = array( + 'code' => $orderProduct['product_reference'], + 'title' => $orderProduct['product_name'], + 'category' => $category->getName(), + 'price' => round($orderProduct['unit_price_tax_incl'], 2), + 'amount' => $orderProduct['product_quantity'], + 'timestamp' => strtotime($order->date_add) + ); + } + + return $this->call( + 'tracker/transaction', + 'POST', + array( + 'transaction' => array_merge( + array( + 'order_id' => $order->id, + 'email' => $order->getCustomer()->email, + 'shop' => $shopUrl->getURL(), + 'amount' => round($order->total_paid_tax_incl, 2), + 'tax' => round($order->total_paid_tax_incl - $order->total_paid_tax_excl, 2), + 'shipping' => round($order->total_shipping, 2), + 'timestamp' => strtotime( $order->date_add ) + ), $addressData), + 'transaction_items' => $arr + ) + ); + + } + + protected function call( $url, $method = 'GET', $data = null ) { + $ch = curl_init(); + + curl_setopt( + $ch, + CURLOPT_URL, + "http://api2.ecomailapp.cz/" . $url + ); + curl_setopt( + $ch, + CURLOPT_RETURNTRANSFER, + TRUE + ); + curl_setopt( + $ch, + CURLOPT_HEADER, + FALSE + ); + curl_setopt( + $ch, + CURLOPT_HTTPHEADER, + array( + "Content-Type: application/json", + 'Key: ' . $this->APIKey + ) + ); + + if( in_array( + $method, + array( + 'POST', + 'PUT' + ) + ) + ) { + + curl_setopt( + $ch, + CURLOPT_CUSTOMREQUEST, + $method + ); + + curl_setopt( + $ch, + CURLOPT_POSTFIELDS, + json_encode( $data ) + ); + + } + + $response = curl_exec( $ch ); + curl_close( $ch ); + + return json_decode( $response ); + } + +} \ No newline at end of file diff --git a/monster_ecomail/logo.png b/monster_ecomail/logo.png new file mode 100644 index 0000000000000000000000000000000000000000..39c1325289770cbccf873b7ce22320ece79f84c5 GIT binary patch literal 6616 zcmbVRXEM`)8!s@1C;HKwf?dD;D!vGY~PL>#syI2bwj4s9k?d8&gkp%#V-R<-Z+zd3- zrLCN>!WMrp!k$>?OEv%?i}ZB1uzG@V`GtCe~zILj=vyoPvjtf z2W6n4&7tgs!*GZRiwjx7;cyNKDPg#nBtk??kV6Cp7lXp2pm3NF3@#0aNsGWZ{&hhv zz2VT-(z+D^%vUJO&9aOVf;t5tG<^r2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fw2u$8@%Y7gq%}`FPB508HuswZNvAF>&lX)%p+d)1w`0RPWn%w7a z@p%!w_vxm=EfMG)@S~9kJ0nmj8;7p;xLc7R-%#&zsmLp3Ja&$+;$5g$UWDwc{Trs~ z^WUWKJT^RAZ|?9VPu7{HAfo54|Nf%!nU*eAqsx52r$`qn7`j>cV}|>kao8_v8{gm? z71z82n1$AKv*VH|yntmng(+eO6+&0N30W=}1$f*|%52XE94tghudC(E(qmOrA{MQM zVkWwA)}@}>Q%?ie#u*z<=&IMB4BuzYHLNgxkYvJs9y`)8^N7o^FG2NbuM4YT z%ucLzoL4K^GNHkNBC_^F_O8MAwZX=HQ!BT()3X)qvt0>qtHWJqBksgiZp# z- zssc;1(Pvk2vD3aE=LIQ+%ggYXN>>4VTi|5D^UM+-i@S!O418> zN6J5SO%;8s^vr;lrj%jEpfSl{J9g^$+tD4c*9oc=g%~45PSCPBYL)k?Uzli5z;^+OAu)MJxaD!!+BeRP{mJ|&j&SVDBmmi zs-`#aDTKIeEVXU2i}^}Ek~<7` zqzr`(d)js#U>`4@-h9w8QMH~{teQaBcw)PE)+O=cwPXiIltiIjy#GtHy14*$qwquT eX$mX2Lo_x#Vlmb)sNsA47aXa55%)dyYx literal 0 HcmV?d00001 diff --git a/monster_ecomail/monster_ecomail.php b/monster_ecomail/monster_ecomail.php new file mode 100644 index 0000000..a9ac2e4 --- /dev/null +++ b/monster_ecomail/monster_ecomail.php @@ -0,0 +1,502 @@ +name = 'monster_ecomail'; + $this->tab = 'emailing'; + $this->version = '1.3.7'; + $this->author = 'MONSTER MEDIA, s.r.o.'; + $this->need_instance = 0; + $this->ps_versions_compliancy = array('min' => '1.5.1', 'max' => '1.7.0'); + $this->bootstrap = true; + + parent::__construct(); + + $this->displayName = $this->l('Ecomail'); + $this->description = $this->l('Napojení e-shopu na Ecomail.'); + + $this->confirmUninstall = $this->l('Opravdu si přejete odinstalovat napojení na Ecomail?'); + } + + public function install() + { + return parent::install() && + $this->setValues() && + $this->setTab() && + $this->setDatabase() && + $this->setHooks(); + } + + public function uninstall() + { + return parent::uninstall() && + $this->unsetValues() && + $this->unsetTab() && + $this->unsetDatabase(); + } + + //hodnoty v configu + public function setValues(){ + return true; + } + + public function unsetValues(){ + return + Configuration::deleteByName('MONSTER_ECOMAIL_API_KEY') && + Configuration::deleteByName('MONSTER_ECOMAIL_APP_ID') && + Configuration::deleteByName('MONSTER_ECOMAIL_LIST_ID'); + + } + + //taby v adminu + public function setTab(){ + return true; + } + + public function unsetTab(){ + return true; + } + + //tabulky v DB + public function setDatabase(){ + return true; + } + + public function unsetDatabase(){ + return true; + } + + //hooky + public function setHooks(){ + + return + $this->registerHook( 'actionCustomerAccountAdd' ) && + $this->registerHook( 'actionValidateOrder' ) && + $this->registerHook( 'displayFooter' ) && + $this->registerHook( 'actionCustomerNewsletterSubscribed' ); + } + + public function getContent() + { + $output = null; + + if (Tools::isSubmit('submit'.$this->name)) + { + Configuration::updateValue('MONSTER_ECOMAIL_API_KEY', Tools::getValue('api_key')); + Configuration::updateValue('MONSTER_ECOMAIL_APP_ID', Tools::getValue('app_id')); + Configuration::updateValue('MONSTER_ECOMAIL_LIST_ID', Tools::getValue('list_id')); + + Configuration::updateValue('MONSTER_ECOMAIL_LOAD_ORDER_DATA', Tools::getValue('load_order_data')); + + Configuration::updateValue('MONSTER_ECOMAIL_LOAD_NAME', Tools::getValue('load_name')); + Configuration::updateValue('MONSTER_ECOMAIL_LOAD_ADDRESS', Tools::getValue('load_address')); + Configuration::updateValue('MONSTER_ECOMAIL_LOAD_BIRTHDAY', Tools::getValue('load_birthday')); + + } + + if(Configuration::get( 'MONSTER_ECOMAIL_API_KEY' ) && !$this->getAPI()->getListsCollection()){ + $output .= $this->displayError("Nepodařilo se spojit se službou Ecomail. Zkontrolujte prosím svůj API klíč."); + } + + if(Configuration::get( 'MONSTER_ECOMAIL_API_KEY' ) && $this->getAPI()->getListsCollection()){ + $output .= $this->displayConfirmation($this->l('Spojení se službou Ecomail je aktivní.')); + } + + return $output.$this->displayForm(); + } + + public function displayForm() + { + // Get default language + $default_lang = (int)Configuration::get('PS_LANG_DEFAULT'); + + if(Configuration::get( 'MONSTER_ECOMAIL_API_KEY' ) && $this->getAPI()->getListsCollection()){ + + $options = array(); + if( Configuration::get( 'MONSTER_ECOMAIL_API_KEY' ) ) { + $listsCollection = $this->getAPI() + ->getListsCollection(); + foreach( $listsCollection as $list ) { + $options[] = array( + 'id_option' => $list->id, + 'name' => $list->name + ); + } + } + + // Init Fields form array + $fields_form[0]['form'] = array( + 'legend' => array( + 'title' => $this->l('Konfigurace Ecomail'), + ), + 'input' => array( + array( + 'type' => 'text', + 'label' => $this->l( 'Vložte Váš API klíč' ), + 'name' => 'api_key', + 'rows' => 20, + 'required' => true + ), + array( + 'type' => 'select', + 'label' => $this->l( 'Vyberte seznam kontaktů:' ), + 'desc' => $this->l( + 'Vyberte list do kterého budou zapsáni noví zákazníci. Pokud jste jej vytvořili teprve nyní, může trvat až 30 minut, než bude možné se na něj napojit.' + ), + 'name' => 'list_id', + 'required' => true, + 'options' => array( + 'query' => $options, + 'id' => 'id_option', + 'name' => 'name' + ) + ), + array( + 'type' => 'switch', + 'label' => $this->l('Aktualizovat údaje na základě dat z objednávek'), + 'name' => 'load_order_data', + 'values' => array( + array( + 'id' => 'active_on', + 'value' => 1, + 'label' => $this->l('Yes') + ), + array( + 'id' => 'active_off', + 'value' => 0, + 'label' => $this->l('No') + ) + ), + ), + array( + 'type' => 'switch', + 'label' => $this->l('Odesílat jména zákazníků'), + 'name' => 'load_name', + 'values' => array( + array( + 'id' => 'active_on', + 'value' => 1, + 'label' => $this->l('Yes') + ), + array( + 'id' => 'active_off', + 'value' => 0, + 'label' => $this->l('No') + ) + ), + ), + array( + 'type' => 'switch', + 'label' => $this->l('Odesílat adresy zákazníků'), + 'name' => 'load_address', + 'values' => array( + array( + 'id' => 'active_on', + 'value' => 1, + 'label' => $this->l('Yes') + ), + array( + 'id' => 'active_off', + 'value' => 0, + 'label' => $this->l('No') + ) + ), + ), + array( + 'type' => 'switch', + 'label' => $this->l('Odesílat data narození zákazníků'), + 'name' => 'load_birthday', + 'values' => array( + array( + 'id' => 'active_on', + 'value' => 1, + 'label' => $this->l('Yes') + ), + array( + 'id' => 'active_off', + 'value' => 0, + 'label' => $this->l('No') + ) + ), + ), + ), + 'submit' => array( + 'title' => $this->l('Save'), + 'class' => 'btn btn-default pull-right' + ) + ); + + $fields_form[1]['form'] = array( + 'legend' => array( + 'title' => $this->l('Marketer+'), + ), + 'input' => array( + array( + 'type' => 'text', + 'label' => $this->l( 'Vložte Vaše appId' ), + 'desc' => $this->l( + 'Tento údaj slouží pro aktivaci trackovacího kódu a sledování transakcí - pouze pro tarif Marketer+' + ), + 'name' => 'app_id', + 'rows' => 20 + ) + ), + 'submit' => array( + 'title' => $this->l('Save'), + 'class' => 'btn btn-default pull-right' + ) + ); + + }else{ + $fields_form[0]['form'] = array( + 'legend' => array( + 'title' => $this->l('Konfigurace Ecomail'), + ), + 'input' => array( + array( + 'type' => 'text', + 'label' => $this->l( 'Vložte Váš API klíč' ), + 'name' => 'api_key', + 'rows' => 20, + 'required' => true, + 'desc' => $this->l('Po správném načtení vašeho API klíče si zvolíte seznam kontaktů pro váš e-shop.') + ) + ), + 'submit' => array( + 'title' => $this->l('Save'), + 'class' => 'btn btn-default pull-right' + ) + ); + } + + $helper = new HelperForm(); + + // Module, token and currentIndex + $helper->module = $this; + $helper->name_controller = $this->name; + $helper->token = Tools::getAdminTokenLite('AdminModules'); + $helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name; + + // Language + $helper->default_form_language = $default_lang; + $helper->allow_employee_form_lang = $default_lang; + + // Title and toolbar + $helper->title = $this->displayName; + $helper->show_toolbar = true; + $helper->toolbar_scroll = true; + $helper->submit_action = 'submit'.$this->name; + $helper->toolbar_btn = array( + 'save' => + array( + 'desc' => $this->l('Save'), + 'href' => AdminController::$currentIndex.'&configure='.$this->name.'&save'.$this->name. + '&token='.Tools::getAdminTokenLite('AdminModules'), + ), + 'back' => array( + 'href' => AdminController::$currentIndex.'&token='.Tools::getAdminTokenLite('AdminModules'), + 'desc' => $this->l('Back to list') + ) + ); + + // Load current value + $helper->fields_value['api_key'] = Configuration::get('MONSTER_ECOMAIL_API_KEY'); + $helper->fields_value['app_id'] = Configuration::get('MONSTER_ECOMAIL_APP_ID'); + $helper->fields_value['list_id'] = Configuration::get('MONSTER_ECOMAIL_LIST_ID'); + $helper->fields_value['load_order_data'] = Configuration::get('MONSTER_ECOMAIL_LOAD_ORDER_DATA'); + + $helper->fields_value['load_name'] = Configuration::get('MONSTER_ECOMAIL_LOAD_NAME'); + $helper->fields_value['load_address'] = Configuration::get('MONSTER_ECOMAIL_LOAD_ADDRESS'); + $helper->fields_value['load_birthday'] = Configuration::get('MONSTER_ECOMAIL_LOAD_BIRTHDAY'); + + return $helper->generateForm($fields_form); + } + + protected function getAPI() { + require_once __DIR__ . '/lib/api.php'; + $obj = new EcomailAPI(); + $obj->setAPIKey( Configuration::get('MONSTER_ECOMAIL_API_KEY') ); + return $obj; + } + + //registrace zákazníka, registrace v košíku, objednávka bez registrace + public function hookActionCustomerAccountAdd( $params ) { + if( $params['_POST']['newsletter'] ) { + + if( Configuration::get('MONSTER_ECOMAIL_API_KEY') ) { + + $nameData = array(); + $birthdayData = array(); + $addressData = array(); + + if(Configuration::get('MONSTER_ECOMAIL_LOAD_NAME')){ + $nameData = array( + 'name' => $params['_POST']['customer_firstname'], + 'surname' => $params['_POST']['customer_lastname'] + ); + } + + if(Configuration::get('MONSTER_ECOMAIL_LOAD_BIRTHDAY')){ + + $birthday = (empty($params['_POST']['years']) ? '' : (int)$params['_POST']['years'].'-'.(int)$params['_POST']['months'].'-'.(int)$params['_POST']['days']); + if (!Validate::isBirthDate($birthday)) { + $birthday = ""; + } + + $birthdayData = array( + 'birthday' => $birthday + ); + } + + if(Configuration::get('MONSTER_ECOMAIL_LOAD_ADDRESS')) { + //pokud probíhá nákup bez registrace nebo registrace v košíku + if ($params['_POST']['id_country']) { + $country = new Country($params['_POST']['id_country']); + + $addressData = array( + "company" => $params['_POST']['company'], + "city" => $params['_POST']['city'], + "street" => $params['_POST']['address1'], + "zip" => $params['_POST']['postcode'], + "country" => $country->iso_code + ); + } + } + + $this->getAPI() + ->subscribeToList( + Configuration::get('MONSTER_ECOMAIL_LIST_ID'), + array_merge( + array('email' => $params['_POST']['email']),$nameData,$birthdayData,$addressData) + ); + } + } + } + + //subscribe zákazníka v modulu blocknewsletter + public function hookActionCustomerNewsletterSubscribed( $params ) { + if( Configuration::get('MONSTER_ECOMAIL_API_KEY') ) { + + $customer = Customer::getCustomersByEmail( $params['email'] ); + + if($customer){ + + $customer = end($customer); //po registraci už není možné vytvářet další účty, takže bude mít nejvíc dat + + $nameData = array(); + $birthdayData = array(); + $addressData = array(); + + if(Configuration::get('MONSTER_ECOMAIL_LOAD_NAME')){ + $nameData = array( + 'name' => $customer['firstname'], + 'surname' => $customer['lastname'] + //'gender' => male/female - ecomail si dopočítává automaticky podle jmen + ); + } + + if(Configuration::get('MONSTER_ECOMAIL_LOAD_BIRTHDAY')){ + $birthdayData = array( + 'birthday' => $customer['birthday'] + ); + } + + if(Configuration::get('MONSTER_ECOMAIL_LOAD_ADDRESS')){ + $address = new Address($params['order']->id_address_invoice); + $country = new Country($address->id_country); + + $addressData = array( + 'company' => $customer['company'] + ); + } + + $this->getAPI() + ->subscribeToList( + Configuration::get('MONSTER_ECOMAIL_LIST_ID'), + array_merge(array('email' => $customer['email']),$nameData,$birthdayData,$addressData) + + ); + } + } + } + + //dokončení objednávky + public function hookActionValidateOrder( $params ) { + + //aktualizace stávajících údajů + subscribe uživatele, který se registroval dříve + if(Configuration::get('MONSTER_ECOMAIL_LOAD_ORDER_DATA')){ + $customer = new Customer($params['order']->id_customer); + + $nameData = array(); + $birthdayData = array(); + $addressData = array(); + + if(Configuration::get('MONSTER_ECOMAIL_LOAD_NAME')){ + $nameData = array( + 'name' => $customer->firstname, + 'surname' => $customer->lastname + + ); + } + + if(Configuration::get('MONSTER_ECOMAIL_LOAD_BIRTHDAY')){ + $birthdayData = array( + 'birthday' => $customer->birthday + + ); + } + + if(Configuration::get('MONSTER_ECOMAIL_LOAD_ADDRESS')){ + $address = new Address($params['order']->id_address_invoice); + $country = new Country($address->id_country); + + $addressData = array( + "city" => $address->city, + "street" => $address->address1, + "zip" => $address->postcode, + "country" => $country->iso_code, + "company" => $address->company + ); + } + + $this->getAPI() + ->subscribeToList( + Configuration::get('MONSTER_ECOMAIL_LIST_ID'), + array_merge(array('email' => $customer->email),$nameData,$birthdayData,$addressData) + ); + } + + //přenos transakce pro tarif Marketer+ + $this->getAPI() + ->createTransaction( $params['order'] ); + } + + public function hookDisplayFooter() { + + $output = ' + + +'; + + return $output; + } + + +} \ No newline at end of file diff --git a/monster_ecomail/override/modules/blocknewsletter/blocknewsletter.php b/monster_ecomail/override/modules/blocknewsletter/blocknewsletter.php new file mode 100644 index 0000000..e74f86e --- /dev/null +++ b/monster_ecomail/override/modules/blocknewsletter/blocknewsletter.php @@ -0,0 +1,23 @@ +context->shop->id; + + $result = Db::getInstance()->execute( $sql ); + + Hook::exec( + 'actionCustomerNewsletterSubscribed', + array( 'email' => $email ) + ); + + return $result; + } +} \ No newline at end of file