Skip to content

Commit

Permalink
init version
Browse files Browse the repository at this point in the history
  • Loading branch information
ecomail-cz committed Jan 31, 2018
1 parent 281f8cb commit b4ad9ea
Show file tree
Hide file tree
Showing 5 changed files with 678 additions and 0 deletions.
13 changes: 13 additions & 0 deletions monster_ecomail/config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<module>
<name>monster_ecomail</name>
<displayName><![CDATA[Ecomail]]></displayName>
<version><![CDATA[1.3.7]]></version>
<description><![CDATA[Napojení e-shopu na Ecomail.]]></description>
<author><![CDATA[MONSTER MEDIA, s.r.o.]]></author>
<tab><![CDATA[emailing]]></tab>
<confirmUninstall><![CDATA[Opravdu si přejete odinstalovat napojení na Ecomail?]]></confirmUninstall>
<is_configurable>1</is_configurable>
<need_instance>0</need_instance>
<limited_countries>cs</limited_countries>
</module>
140 changes: 140 additions & 0 deletions monster_ecomail/lib/api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<?php

class EcomailAPI {

protected $APIKey;

public function setAPIKey( $arg ) {
$this->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 );
}

}
Binary file added monster_ecomail/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit b4ad9ea

Please sign in to comment.