From 8d76441ef5c0653f4568b09128f19110033d99ab Mon Sep 17 00:00:00 2001 From: Tlapi Date: Thu, 1 Apr 2021 22:23:01 +0200 Subject: [PATCH] update plugin --- monster_ecomail/lib/api.php | 25 +++++++++++++++ monster_ecomail/monster_ecomail.php | 48 ++++++++++------------------- 2 files changed, 42 insertions(+), 31 deletions(-) diff --git a/monster_ecomail/lib/api.php b/monster_ecomail/lib/api.php index 628f039..8c08ff9 100644 --- a/monster_ecomail/lib/api.php +++ b/monster_ecomail/lib/api.php @@ -33,6 +33,31 @@ public function subscribeToList( $listId, $customerData ) { ); } + + public function sendBasket($email, $products ) { + $data = json_encode( + array( + 'data' => array( + 'data' => array( + 'action' => 'Basket', + 'products' => $products + ) + ) + )); + return $this->call( + 'tracker/events', + 'POST', + array( + 'event' => array( + 'email' => $email, + 'category' => 'ue', + 'action' => 'Basket', + 'label' => 'Basket', + 'value' => "$data" + ) + ) + ); + } public function createTransaction( Order $order ) { diff --git a/monster_ecomail/monster_ecomail.php b/monster_ecomail/monster_ecomail.php index c6e7368..b99ed6a 100644 --- a/monster_ecomail/monster_ecomail.php +++ b/monster_ecomail/monster_ecomail.php @@ -11,7 +11,7 @@ public function __construct() { $this->name = 'monster_ecomail'; $this->tab = 'emailing'; - $this->version = '1.9.5'; + $this->version = '1.9.702'; $this->author = 'MONSTER MEDIA, s.r.o.'; $this->need_instance = 0; $this->ps_versions_compliancy = array('min' => '1.5.1', 'max' => '1.7.999'); @@ -244,10 +244,6 @@ public function displayForm() 'class' => 't', 'label' => $this->l('Odesílat produkty v košíku'), 'name' => 'load_cart', - 'desc' => $this->l( - 'V případě, že vaši zákazníci objednávají desítky druhů produktů v jedné objednávce, - doporučujeme tuto funkci deaktivovat nebo řádně otestovat, že nedochází ke zpomalení vašeho košíku.' - ), 'values' => array( array( 'id' => 'active_on', @@ -593,20 +589,23 @@ public function hookActionCartSave($params) $products = array(); foreach($cart_products as $p){ + $productCat = new Category($p["id_category_default"]); $products[] = array( "productId" => $p["id_product"], "img_url" => $this->context->link->getImageLink($p['link_rewrite'], $p["id_image"]), - "url" => $this->context->link->getProductLink((int)$p["id_product"], $p['link_rewrite'], new Category($p["id_category_default"])), + "url" => $this->context->link->getProductLink((int)$p["id_product"], $p['link_rewrite'], $productCat->link_rewrite[$this->context->language->id]), "name" => $p["name"], "price" => $p["price_wt"], "description" => $p["description_short"] ); } - - $this->context->cookie->monster_ecomail_cart = json_encode($products); - }else{ - return; - } + $result = $this->getAPI()->sendBasket($this->context->customer->email, $products); + if (isset($result->errors)) { + PrestaShopLogger::addLog('Ecomail failed: '. json_encode($result->errors), 1, null, 'Cart', (int)$this->context->cart->id, true); + } + } else { + return; + } } public function hookDisplayFooter($params) { @@ -623,27 +622,14 @@ public function hookDisplayFooter($params) { }); window.ecotrack(\'setUserIdFromLocation\', \'ecmid\');'; - if(isset($this->context->cookie->email)){ - $output .= 'window.ecotrack(\'setUserId\', \''.$this->context->cookie->email.'\'); - '; - } - - $output .= 'window.ecotrack(\'trackPageView\');'; + if(isset($this->context->cookie->email)){ + $output .= 'window.ecotrack(\'setUserId\', \''.$this->context->cookie->email.'\'); + '; + } - if(isset($this->context->cookie->monster_ecomail_cart)){ - $output .= "window.ecotrack('trackUnstructEvent', { - schema: '', - data: { - action: 'Basket', - products: ".$this->context->cookie->monster_ecomail_cart." - } - }) - "; + $output .= 'window.ecotrack(\'trackPageView\');'; - $this->context->cookie->__unset('monster_ecomail_cart'); - - } - $output .= ' + $output .= ' '; @@ -651,4 +637,4 @@ public function hookDisplayFooter($params) { } -} \ No newline at end of file +}