Skip to content

Commit

Permalink
update plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
ecomail-cz committed Apr 1, 2021
1 parent ede835b commit 8d76441
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 31 deletions.
25 changes: 25 additions & 0 deletions monster_ecomail/lib/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {

Expand Down
48 changes: 17 additions & 31 deletions monster_ecomail/monster_ecomail.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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) {
Expand All @@ -623,32 +622,19 @@ 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 .= '
</script>
<!-- Ecomail stops -->';

return $output;
}


}
}

0 comments on commit 8d76441

Please sign in to comment.