MagNews_Connector - Version 2.0.1

Version Notes

MagNews Connector for Magento was developed to integrate the information contained on your Ecommerce (customer lists, product descriptions, orders, click, shopping carts and whishlists) with the Email Marketing platform MagNews.

Our connector allows you to create promos containing information relevant to the user in few clicks.

=============================

Il connettore MagNews per Magento nasce dall'esigenza di integrare le informazioni contenute sul tuo ecommerce Magento (lista clienti, iscritti alla newsletter, descrizione prodotti, ordini, prodotti visualizzati/cliccati, carrelli abbandonati e lista desideri) con la tua piattaforma per l'Email Marketing MagNews.

Il nostro connettore ti permette di creare promozioni contenenti informazioni rilevanti per l'utente in pochi click.

Download this release

Release Info

Developer MagNews Development Team
Extension MagNews_Connector
Version 2.0.1
Comparing to
See all releases


Version 2.0.1

app/code/local/Diennea/MagNews/Helper/Data.php ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Diennea_Magnews_Helper_Data extends Mage_Core_Helper_Abstract
4
+ {
5
+
6
+ }
app/code/local/Diennea/MagNews/Model/Abandonedcart/Api.php ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Diennea_MagNews_Model_Abandonedcart_Api extends Mage_Api_Model_Resource_Abstract {
4
+
5
+ public function getlastbycustomer($customer_id,$options='') {
6
+
7
+ $lastcart_total = 0;
8
+ $lastcart_date = 0;
9
+ $lastcart_present = 0;
10
+ $quoteId = 0;
11
+ $lastcart_productids = '';
12
+ $lastcart_categoryids = '';
13
+
14
+ $cartCollection = Mage::getResourceModel('reports/quote_collection');
15
+ $cartCollection->prepareForAbandonedReport(array());
16
+ $cartCollection->addFieldToFilter('customer_id', $customer_id);
17
+ $cartCollection->load();
18
+
19
+ foreach ($cartCollection as $lastCart) {
20
+ $lastcart_date = $lastCart->updated_at;
21
+ $lastcart_total = $lastCart->grand_total;
22
+ $quoteId = $lastCart->getId();
23
+ $lastcart_present = 1;
24
+ }
25
+
26
+ if ($lastcart_present === 1) {
27
+ $quote = Mage::getModel("sales/quote");
28
+ $quote->loadByIdWithoutStore($quoteId);
29
+ $productids = array();
30
+ $categoryIds = array();
31
+ foreach ($quote->getAllItems() as $item) {
32
+ $productId = $item->getProductId();
33
+ $productids[] = $productId;
34
+ if (strlen($options) === 0 || strpos($options, 'categories') !== false) {
35
+ $product = Mage::getModel('catalog/product')->load($productId);
36
+ if ($product->getCategoryIds()) {
37
+ $categoryIds[] = implode(',', $product->getCategoryIds());
38
+ }
39
+ }
40
+ }
41
+ $lastcart_productids = implode(',', $productids);
42
+ $lastcart_categoryids = implode(',', $categoryIds);
43
+ }
44
+
45
+ $result = array(
46
+ 'total' => $lastcart_total,
47
+ 'ts' => $lastcart_date,
48
+ 'exist' => $lastcart_present,
49
+ 'customer_id' => $customer_id,
50
+ 'productids' => $lastcart_productids,
51
+ 'categoryids' => $lastcart_categoryids
52
+ );
53
+ return $result;
54
+ }
55
+
56
+ }
app/code/local/Diennea/MagNews/Model/Catalog/Api.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Estensione metodi sul catalogo.
4
+ *
5
+ * @author Andrea Mallegni
6
+ * @version $Id$
7
+ */
8
+ class Diennea_MagNews_Model_Catalog_Api extends Mage_Api_Model_Resource_Abstract {
9
+
10
+ /**
11
+ * Restituisce il min e il max id della tabella dei prodotti.
12
+ *
13
+ * @return int max id prodotto
14
+ */
15
+ public function getminandmaxproductid() {
16
+ $resource = Mage::getSingleton('core/resource');
17
+ $readConnection = $resource->getConnection('core_read');
18
+ $query = 'SELECT MIN(entity_id) AS min_id, MAX(entity_id) as max_id FROM ' . $resource->getTableName('catalog/product');
19
+ return $readConnection->fetchAll($query);
20
+ }
21
+
22
+ }
app/code/local/Diennea/MagNews/Model/Custom/Reports/Products/Mostabandoned/Collection.php ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by IntelliJ IDEA.
4
+ * User: Carlo
5
+ * Date: 14/04/14
6
+ * Time: 19.27
7
+ */
8
+ class Diennea_MagNews_Model_Custom_Reports_Products_Mostabandoned_Collection extends Mage_Reports_Model_Resource_Product_Collection
9
+ {
10
+
11
+ public function prepareAbandonedProductQuery()
12
+ {
13
+ $this->_reset()
14
+ ->addAttributeToSelect('*')
15
+ ->addAbandonedProducts()
16
+ ->setOrder('ordered_qty', self::SORT_ORDER_DESC);
17
+ return $this;
18
+ }
19
+
20
+ public function addAbandonedProducts()
21
+ {
22
+ $adapter = $this->getConnection();
23
+ $compositeTypeIds = Mage::getSingleton('catalog/product_type')->getCompositeTypes();
24
+ $orderTableAliasName = $adapter->quoteIdentifier('abandoned');
25
+
26
+ $orderJoinCondition = array(
27
+ $orderTableAliasName . '.entity_id=abandoned_items.quote_id',
28
+ //$adapter->quoteInto("{$orderTableAliasName}.state <> ?", Mage_Sales_Model_Order::STATE_CANCELED),
29
+
30
+ );
31
+
32
+ $productJoinCondition = array(
33
+ $adapter->quoteInto('(e.type_id NOT IN (?))', $compositeTypeIds),
34
+ 'e.entity_id = abandoned_items.product_id',
35
+ $adapter->quoteInto('e.entity_type_id = ?', $this->getProductEntityTypeId())
36
+ );
37
+
38
+
39
+ $this->getSelect()->reset()
40
+ ->from(
41
+ array('abandoned_items' => $this->getTable('sales/quote_item')),
42
+ array(
43
+ 'ordered_qty' => 'SUM(abandoned_items.qty)'
44
+ ))
45
+ ->joinInner(
46
+ array('abandoned' => $this->getTable('sales/quote')),
47
+ implode(' AND ', $orderJoinCondition),
48
+ array())
49
+ ->joinLeft(
50
+ array('e' => $this->getProductEntityTableName()),
51
+ implode(' AND ', $productJoinCondition),
52
+ array(
53
+ 'entity_id' => 'abandoned_items.product_id',
54
+ 'entity_type_id' => 'e.entity_type_id',
55
+ 'attribute_set_id' => 'e.attribute_set_id',
56
+ 'type_id' => 'e.type_id',
57
+ 'sku' => 'e.sku',
58
+ 'has_options' => 'e.has_options',
59
+ 'required_options' => 'e.required_options',
60
+ 'created_at' => 'e.created_at',
61
+ 'updated_at' => 'e.updated_at'
62
+ ))
63
+ ->where('parent_item_id IS NULL')
64
+ ->group('abandoned_items.product_id')
65
+ ->having('SUM(abandoned_items.qty) > ?', 0);
66
+ //->order('abandoned_item_qty', self::SORT_ORDER_DESC);
67
+ return $this;
68
+ }
69
+ }
app/code/local/Diennea/MagNews/Model/Custom/Reports/Products/Mostprofitable/Collection.php ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by IntelliJ IDEA.
4
+ * User: Carlo
5
+ * Date: 13/04/14
6
+ * Time: 20.29
7
+ */
8
+ class Diennea_MagNews_Model_Custom_Reports_Products_Mostprofitable_Collection extends Mage_Reports_Model_Resource_Product_Collection
9
+ {
10
+
11
+ public function setDateRange($from, $to)
12
+ {
13
+ $this->_reset()
14
+ ->addAttributeToSelect('*')
15
+ ->addTotProfit($from, $to)
16
+ ->setOrder('ordered_qty', self::SORT_ORDER_DESC);
17
+ return $this;
18
+ }
19
+
20
+ public function addTotProfit($from = '', $to = '')
21
+ {
22
+ $adapter = $this->getConnection();
23
+ $compositeTypeIds = Mage::getSingleton('catalog/product_type')->getCompositeTypes();
24
+ $orderTableAliasName = $adapter->quoteIdentifier('order');
25
+
26
+ $orderJoinCondition = array(
27
+ $orderTableAliasName . '.entity_id = order_items.order_id',
28
+ $adapter->quoteInto("{$orderTableAliasName}.state <> ?", Mage_Sales_Model_Order::STATE_CANCELED),
29
+
30
+ );
31
+
32
+ $productJoinCondition = array(
33
+ $adapter->quoteInto('(e.type_id NOT IN (?))', $compositeTypeIds),
34
+ 'e.entity_id = order_items.product_id',
35
+ $adapter->quoteInto('e.entity_type_id = ?', $this->getProductEntityTypeId())
36
+ );
37
+
38
+ if ($from != '' && $to != '') {
39
+ $fieldName = $orderTableAliasName . '.created_at';
40
+ $orderJoinCondition[] = $this->_prepareBetweenSql($fieldName, $from, $to);
41
+ }
42
+
43
+ $this->getSelect()->reset()
44
+ ->from(
45
+ array('order_items' => $this->getTable('sales/order_item')),
46
+ array(
47
+ 'ordered_qty' => 'SUM(order_items.qty_ordered*order_items.price)',
48
+ 'order_items_name' => 'order_items.name'
49
+ ))
50
+ ->joinInner(
51
+ array('order' => $this->getTable('sales/order')),
52
+ implode(' AND ', $orderJoinCondition),
53
+ array())
54
+ ->joinLeft(
55
+ array('e' => $this->getProductEntityTableName()),
56
+ implode(' AND ', $productJoinCondition),
57
+ array(
58
+ 'entity_id' => 'order_items.product_id',
59
+ 'entity_type_id' => 'e.entity_type_id',
60
+ 'attribute_set_id' => 'e.attribute_set_id',
61
+ 'type_id' => 'e.type_id',
62
+ 'sku' => 'e.sku',
63
+ 'has_options' => 'e.has_options',
64
+ 'required_options' => 'e.required_options',
65
+ 'created_at' => 'e.created_at',
66
+ 'updated_at' => 'e.updated_at'
67
+ ))
68
+ ->where('parent_item_id IS NULL')
69
+ ->group('order_items.product_id')
70
+ ->having('SUM(order_items.qty_ordered*order_items.price) > ?', 0);
71
+ return $this;
72
+ }
73
+ }
app/code/local/Diennea/MagNews/Model/Customerlogin/Api.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Diennea_MagNews_Model_Customerlogin_Api extends Mage_Api_Model_Resource_Abstract {
4
+ public function lastloginforcustomer($customer_id) {
5
+ $loginbyuser = Mage::getModel('log/customer')->loadByCustomer($customer_id);
6
+ $result = $loginbyuser->toArray();
7
+ if (count($result) === 0) {
8
+ return array("customer_id"=>$customer_id);
9
+ } else {
10
+ return $result;
11
+ }
12
+ }
13
+ }
app/code/local/Diennea/MagNews/Model/Customerqueries/Api.php ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by IntelliJ IDEA.
4
+ * User: Carlo
5
+ * Date: 12/04/14
6
+ * Time: 19.29
7
+ */
8
+
9
+ class Diennea_MagNews_Model_Customerqueries_Api extends Mage_Api_Model_Resource_Abstract {
10
+
11
+ static $maxRes=100;
12
+
13
+ public function getmostwishedproduct($customerId=null, $from=null, $to=null, $catId=0, $nres=20){
14
+ $collection = Mage::getResourceModel('reports/product_collection')->addAttributeToSelect('*');
15
+ if ($nres>self::$maxRes) $nres=self::$maxRes;
16
+ if ($nres<=0) $nres=self::$maxRes;
17
+ $collection = $this->addWishCount($collection,$customerId,$from,$to)->setPageSize($nres);
18
+ //error_log($collection->getSelectSql(true));
19
+ if ($catId!=0) {
20
+ $category=new Mage_Catalog_Model_Category();
21
+ $category->setId($catId);
22
+ $collection->addCategoryFilter($category);
23
+ }
24
+ $ret=$collection->load()->toArray();
25
+ return $ret;
26
+ }
27
+
28
+ protected function addWishCount($that,$customerId=null, $from = '', $to = '')
29
+ {
30
+ /**
31
+ * Getting event type id for catalog_product_view event
32
+ */
33
+ foreach (Mage::getModel('reports/event_type')->getCollection() as $eventType) {
34
+ if ($eventType->getEventName() == 'wishlist_add_product') {
35
+ $productWishEvent = (int)$eventType->getId();
36
+ break;
37
+ }
38
+ }
39
+
40
+ $that->getSelect()->reset()
41
+ ->from(
42
+ array('report_table_wishes' => $that->getTable('reports/event')),
43
+ array('wishes' => 'COUNT(report_table_wishes.event_id)'))
44
+ ->join(array('e' => $that->getProductEntityTableName()),
45
+ $that->getConnection()->quoteInto(
46
+ "e.entity_id = report_table_wishes.object_id AND e.entity_type_id = ?",
47
+ $that->getProductEntityTypeId()))
48
+ ->where('report_table_wishes.event_type_id = ?', $productWishEvent)
49
+ ->where('report_table_wishes.subject_id = ?', $customerId)
50
+ ->group('e.entity_id')
51
+ ->order('wishes ' . $that::SORT_ORDER_DESC)
52
+ ->having('COUNT(report_table_wishes.event_id) > ?', 0);
53
+
54
+ if ($from != '' && $to != '') {
55
+ $that->getSelect()
56
+ ->where('logged_at >= ?', $from)
57
+ ->where('logged_at <= ?', $to);
58
+ }
59
+
60
+ //$that->_useAnalyticFunction = true;
61
+ return $that;
62
+ }
63
+ }
app/code/local/Diennea/MagNews/Model/Customersbatch/Api.php ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Diennea_MagNews_Model_Customersbatch_Api extends Mage_Api_Model_Resource_Abstract {
4
+
5
+ public function getcustomersidpage($pageNum, $pageSize) {
6
+ $result = array();
7
+ $all = Mage::getModel('customer/customer')->getCollection();
8
+ $all->addAttributeToSort('entity_id', 'asc')
9
+ ->setPage($pageNum, $pageSize);
10
+ foreach ($all as $customer) {
11
+ $result[] = $customer["entity_id"];
12
+ }
13
+ return $result;
14
+ }
15
+
16
+ public function countcustomers() {
17
+ $all = Mage::getModel('customer/customer')->getCollection();
18
+ $all->getSelect()
19
+ ->reset(Zend_Db_Select::COLUMNS)
20
+ ->columns('COUNT(*) AS entitycount');
21
+ $stmt = $all->getSelect()->query();
22
+ $result = $stmt->fetchAll();
23
+ $first = current($result);
24
+ $count = $first['entitycount'];
25
+ return $count;
26
+ }
27
+
28
+ public function getdetailedinfo($customerId, $options = '') {
29
+ $customer = Mage::getModel('customer/customer')->load($customerId);
30
+ $allOrdersTotalAmount = 0;
31
+ $allOrdersDateTimes = array();
32
+ $allOrdersTotals = array();
33
+ $allOrdersIds = array();
34
+ $allProductsIds = array();
35
+ $hasorders = false;
36
+ $customer_productids = '';
37
+ $customer_lastorderdate = '';
38
+ $customer_lastordertotal = 0;
39
+ $customer_allorderstotal = 0;
40
+ $customer_company = '';
41
+ $customer_country = '';
42
+ $customer_city = '';
43
+ $customer_region = '';
44
+ $customer_postcode = '';
45
+ $customer_address = '';
46
+ $customer_fax = '';
47
+ $customer_phone = '';
48
+ $customer_lastorder_productsids = '';
49
+ $customer_lastorder_categoryids = '';
50
+ $customer_firstname = $customer->getData('firstname');
51
+ $customer_lastname = $customer->getData('lastname');
52
+ $customer_email = $customer->getData('email');
53
+ $customer_createdat = $customer->getData('created_at');
54
+ $customer_countorders = 0;
55
+
56
+ if (strlen($options) === 0 || strpos($options, 'address') !== false) {
57
+ // address
58
+ $customerAddressId = $customer->getDefaultBilling();
59
+ if ($customerAddressId) {
60
+ $address = Mage::getModel('customer/address')->load($customerAddressId);
61
+ $customer_company = $address->getData('company');
62
+ $customer_country = $address->getCountry();
63
+ $customer_city = $address->getData('city');
64
+ $customer_region = $address->getData('region');
65
+ $customer_postcode = $address->getData('postcode');
66
+ $customer_address = $address->getData('street');
67
+ $customer_fax = $address->getData('fax');
68
+ $customer_phone = $address->getData('telephone');
69
+ }
70
+ }
71
+ if (strlen($options) === 0 || strpos($options, 'order') !== false) {
72
+ // last order
73
+ $orders = Mage::getModel('sales/order')
74
+ ->getCollection()
75
+ ->addAttributeToFilter('customer_id', $customerId);
76
+ foreach ($orders as $order) {
77
+ if (in_array($order->getStatus(), array("closed", "complete", "processing"))) {
78
+ $hasorders = true;
79
+ $currentOrderTotal_number = floatval($order->getGrandTotal());
80
+ $allOrdersTotalAmount += $currentOrderTotal_number;
81
+ $currentOrderCreationDate = $order->getCreatedAt();
82
+ $currentOrderTotal = $currentOrderTotal_number;
83
+ $currentOrderId = $order->getIncrementId();
84
+ $allOrdersTotals[$currentOrderId] = $currentOrderTotal;
85
+ $allOrdersDateTimes[$currentOrderId] = $currentOrderCreationDate;
86
+ $allOrdersIds[$currentOrderId] = $currentOrderId;
87
+ $customer_countorders = $customer_countorders + 1;
88
+ $items = $order->getAllItems();
89
+ foreach ($items as $item) {
90
+ $allProductsIds[] = $item->getProductId();
91
+ }
92
+ }
93
+ }
94
+ if ($hasorders) {
95
+ ksort($allOrdersDateTimes);
96
+ ksort($allOrdersTotals);
97
+ ksort($allOrdersIds);
98
+ $customer_productids = implode(',', $allProductsIds);
99
+ $customer_lastorderdate = end($allOrdersDateTimes);
100
+ $customer_lastordertotal = end($allOrdersTotals);
101
+ $customer_allorderstotal = $allOrdersTotalAmount;
102
+ $lastOrder = Mage::getModel('sales/order')->loadByIncrementId(end($allOrdersIds));
103
+ $items = $lastOrder->getAllItems();
104
+ $productIds = array();
105
+ $categoryIds = array();
106
+ foreach ($items as $item) {
107
+ $productId = $item->getProductId();
108
+ $productIds[] = $productId;
109
+ $product = Mage::getModel('catalog/product')->load($productId);
110
+ if ($product->getCategoryIds()) {
111
+ $categoryIds[] = implode(',', $product->getCategoryIds());
112
+ }
113
+ }
114
+ $customer_lastorder_productsids = implode(',', $productIds);
115
+ $customer_lastorder_categoryids = implode(',', $categoryIds);
116
+ }
117
+ }
118
+
119
+ return array(
120
+ 'productids' => $customer_productids,
121
+ 'lastorder_categoryids' => $customer_lastorder_categoryids,
122
+ 'lastorder_productids' => $customer_lastorder_productsids,
123
+ 'lastorder_date' => $customer_lastorderdate,
124
+ 'lastorder_total' => $customer_lastordertotal,
125
+ 'allorders_total' => $customer_allorderstotal,
126
+ 'allorders_count' => $customer_countorders,
127
+ 'company' => $customer_company,
128
+ 'country' => $customer_country,
129
+ 'city' => $customer_city,
130
+ 'region' => $customer_region,
131
+ 'postcode' => $customer_postcode,
132
+ 'address' => $customer_address,
133
+ 'fax' => $customer_fax,
134
+ 'phone' => $customer_phone,
135
+ 'firstname' => $customer_firstname,
136
+ 'lastname' => $customer_lastname,
137
+ 'email' => $customer_email,
138
+ 'customer_id' => $customerId,
139
+ 'created_at' => $customer_createdat
140
+ );
141
+ }
142
+
143
+ }
app/code/local/Diennea/MagNews/Model/Globalqueries/Api.php ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by IntelliJ IDEA.
4
+ * User: Carlo
5
+ * Date: 12/04/14
6
+ * Time: 19.29
7
+ */
8
+
9
+ class Diennea_MagNews_Model_Globalqueries_Api extends Mage_Api_Model_Resource_Abstract {
10
+
11
+ static $maxRes=100;
12
+
13
+ public function getbestsellerproduct($from, $to, $catId=0, $nres=20){
14
+ $collection=Mage::getResourceModel('reports/product_sold_collection');
15
+ $collection->setDateRange($from, $to);
16
+ if ($catId!=0) {
17
+ $category=new Mage_Catalog_Model_Category();
18
+ $category->setId($catId);
19
+ $collection->addCategoryFilter($category);
20
+ }
21
+ if ($nres>self::$maxRes) $nres=self::$maxRes;
22
+ if ($nres<=0) $nres=self::$maxRes;
23
+ $res=$collection->setPageSize($nres)->load()->toArray();
24
+ return $res;
25
+ }
26
+
27
+ public function getmostprofitableproduct($from, $to, $catId=0, $nres=20){
28
+ $collection=new Diennea_MagNews_Model_Custom_Reports_Products_Mostprofitable_Collection();
29
+ $collection->setDateRange($from, $to);
30
+ if ($catId!=0) {
31
+ $category=new Mage_Catalog_Model_Category();
32
+ $category->setId($catId);
33
+ $collection->addCategoryFilter($category);
34
+ }
35
+ if ($nres>self::$maxRes) $nres=self::$maxRes;
36
+ if ($nres<=0) $nres=self::$maxRes;
37
+ $res=$collection->setPageSize($nres)->load()->toArray();
38
+ foreach ($res as $key=>$val){
39
+ foreach ($val as $k=>$v){
40
+ if ($k=="ordered_qty") {
41
+ unset($res[$key][$k]);
42
+ $res[$key]['tot_profit']=$v;
43
+ }
44
+ }
45
+ }
46
+ return $res;
47
+ }
48
+
49
+ public function getmostviewedproduct($from, $to, $catId=0, $nres=20){
50
+ if ($nres>self::$maxRes) $nres=self::$maxRes;
51
+ if ($nres<=0) $nres=self::$maxRes;
52
+ $collection = Mage::getResourceModel('reports/product_collection')->addAttributeToSelect('*')->addViewsCount($from,$to)
53
+ ->setPageSize($nres);
54
+ if ($catId!=0) {
55
+ $category=new Mage_Catalog_Model_Category();
56
+ $category->setId($catId);
57
+ $collection->addCategoryFilter($category);
58
+ }
59
+ $ret=$collection->load()->toArray();
60
+ return $ret;
61
+ }
62
+
63
+ public function getmostwishedproduct($from, $to, $catId=0, $nres=20){
64
+ $collection = Mage::getResourceModel('reports/product_collection')->addAttributeToSelect('*');
65
+ if ($nres>self::$maxRes) $nres=self::$maxRes;
66
+ if ($nres<=0) $nres=self::$maxRes;
67
+ $collection = $this->addWishCount($collection,$from,$to)->setPageSize($nres);
68
+ if ($catId!=0) {
69
+ $category=new Mage_Catalog_Model_Category();
70
+ $category->setId($catId);
71
+ $collection->addCategoryFilter($category);
72
+ }
73
+ $ret=$collection->load()->toArray();
74
+ return $ret;
75
+
76
+ }
77
+
78
+ public function getmostabandonedproduct($catId=0, $nres=20){
79
+ $collection=new Diennea_MagNews_Model_Custom_Reports_Products_Mostabandoned_Collection();
80
+ $collection->prepareAbandonedProductQuery();
81
+ if ($catId!=0) {
82
+ $category=new Mage_Catalog_Model_Category();
83
+ $category->setId($catId);
84
+ $collection->addCategoryFilter($category);
85
+ }
86
+ if ($nres>self::$maxRes) $nres=self::$maxRes;
87
+ if ($nres<=0) $nres=self::$maxRes;
88
+ $res=$collection->setPageSize($nres)->load()->toArray();
89
+ foreach ($res as $key=>$val){
90
+ foreach ($val as $k=>$v){
91
+ if ($k=="ordered_qty") {
92
+ unset($res[$key][$k]);
93
+ $res[$key]['abandoned_qty']=$v;
94
+ }
95
+ }
96
+ }
97
+ return $res;
98
+
99
+ }
100
+
101
+ protected function addWishCount($that, $from = '', $to = '')
102
+ {
103
+ /**
104
+ * Getting event type id for catalog_product_view event
105
+ */
106
+ foreach (Mage::getModel('reports/event_type')->getCollection() as $eventType) {
107
+ if ($eventType->getEventName() == 'wishlist_add_product') {
108
+ $productWishEvent = (int)$eventType->getId();
109
+ break;
110
+ }
111
+ }
112
+
113
+ $that->getSelect()->reset()
114
+ ->from(
115
+ array('report_table_wishes' => $that->getTable('reports/event')),
116
+ array('wishes' => 'COUNT(report_table_wishes.event_id)'))
117
+ ->join(array('e' => $that->getProductEntityTableName()),
118
+ $that->getConnection()->quoteInto(
119
+ "e.entity_id = report_table_wishes.object_id AND e.entity_type_id = ?",
120
+ $that->getProductEntityTypeId()))
121
+ ->where('report_table_wishes.event_type_id = ?', $productWishEvent)
122
+ ->group('e.entity_id')
123
+ ->order('wishes ' . $that::SORT_ORDER_DESC)
124
+ ->having('COUNT(report_table_wishes.event_id) > ?', 0);
125
+
126
+ if ($from != '' && $to != '') {
127
+ $that->getSelect()
128
+ ->where('logged_at >= ?', $from)
129
+ ->where('logged_at <= ?', $to);
130
+ }
131
+
132
+ //$that->_useAnalyticFunction = true;
133
+ return $that;
134
+ }
135
+ }
app/code/local/Diennea/MagNews/Model/Newslettersubscription/Api.php ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Diennea_MagNews_Model_Newslettersubscription_Api extends Mage_Api_Model_Resource_Abstract {
4
+
5
+ public function getnoncustomerspage($pageNum, $pageSize) {
6
+ $result = array();
7
+ $subscriptions = Mage::getModel('newsletter/subscriber')
8
+ ->getCollection()
9
+ ->addFieldToFilter("customer_id", 0);
10
+ $subscriptions->getSelect()->limit($pageSize, (($pageNum - 1) * $pageSize));
11
+ $subscriptions->load(false, true);
12
+ foreach ($subscriptions as $subscriber) {
13
+ $result[] = $subscriber->toArray();
14
+ }
15
+ return $result;
16
+ }
17
+
18
+ public function getallnoncustomers() {
19
+ $result = array();
20
+ $subscriptions = Mage::getModel('newsletter/subscriber')
21
+ ->getCollection();
22
+ $subscriptions->addFieldToFilter("customer_id", 0);
23
+ $subscriptions->load();
24
+ foreach ($subscriptions as $subscriber) {
25
+ $result[] = $subscriber->toArray();
26
+ }
27
+ return $result;
28
+ }
29
+
30
+ public function countnoncustomers() {
31
+ $all = Mage::getModel('newsletter/subscriber')->getCollection();
32
+ $all->addFieldToFilter("customer_id", 0);
33
+ $all->getSelect()
34
+ ->reset(Zend_Db_Select::COLUMNS)
35
+ ->columns('COUNT(*) AS entitycount');
36
+ $stmt = $all->getSelect()->query();
37
+ $result = $stmt->fetchAll();
38
+ $first = current($result);
39
+ $count = $first['entitycount'];
40
+ return $count;
41
+ }
42
+
43
+ public function customersubscription($customer_id) {
44
+ $subscriptions = Mage::getModel('newsletter/subscriber')
45
+ ->getCollection();
46
+ $subscriptions->addFieldToFilter("customer_id", $customer_id);
47
+ $subscriptions->load();
48
+ foreach ($subscriptions as $subscriber) {
49
+ return $subscriber->toArray();
50
+ }
51
+ return array("subscriber_id" => "0", "customer_id" => $customer_id);
52
+ }
53
+
54
+ public function subscribe($email) {
55
+ $subscriptions = Mage::getModel('newsletter/subscriber');
56
+ // this method already looks for a customer and uses it if it found
57
+ $subscriptions->subscribe($email);
58
+ return $subscriptions->toArray();
59
+ }
60
+ public function unsubscribe($email) {
61
+ $subscriptions = Mage::getModel('newsletter/subscriber');
62
+ $subscriptions->loadByEmail($email);
63
+ $subscriptions->unsubscribe();
64
+ return $subscriptions->toArray();
65
+ }
66
+
67
+ public function getbyemail($email) {
68
+ $subscriptions = Mage::getModel('newsletter/subscriber');
69
+ $subscriptions->loadByEmail($email);
70
+ return $subscriptions->toArray();
71
+ }
72
+
73
+ }
app/code/local/Diennea/MagNews/Model/Version/Api.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Diennea_MagNews_Model_Version_Api extends Mage_Api_Model_Resource_Abstract {
4
+
5
+ public function getpluginversion() {
6
+ $result = array('version'=>'2.0.0');
7
+ return $result;
8
+ }
9
+ }
app/code/local/Diennea/MagNews/etc/api.xml ADDED
@@ -0,0 +1,173 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ <config>
3
+ <api>
4
+ <resources>
5
+ <magnews_version translate="title" module="magnews">
6
+ <title>Plugin version info</title>
7
+ <model>Diennea_MagNews_Model_Version_Api</model>
8
+ <acl>magnews</acl>
9
+ <methods>
10
+ <getpluginversion translate="title" module="magnews">
11
+ <title>Get plugin version</title>
12
+ <method>getpluginversion</method>
13
+ <acl>magnews/useplugin</acl>
14
+ </getpluginversion>
15
+ </methods>
16
+ </magnews_version>
17
+ <magnews_abandonedcart translate="title" module="magnews">
18
+ <title>Abandoned Cart</title>
19
+ <model>Diennea_MagNews_Model_Abandonedcart_Api</model>
20
+ <acl>magnews</acl>
21
+ <methods>
22
+ <getlastbycustomer translate="title" module="magnews">
23
+ <title>Retrieve last abandoned cart for a customer</title>
24
+ <method>getlastbycustomer</method>
25
+ <acl>magnews/useplugin</acl>
26
+ </getlastbycustomer>
27
+ </methods>
28
+ </magnews_abandonedcart>
29
+ <magnews_newslettersubscription translate="title" module="magnews">
30
+ <title>Newsletter subscription</title>
31
+ <model>Diennea_MagNews_Model_Newslettersubscription_Api</model>
32
+ <acl>magnews</acl>
33
+ <methods>
34
+ <getallnoncustomers translate="title" module="magnews">
35
+ <title>Retrieve the whole list of Newsletter subscriptions for non customers</title>
36
+ <method>getallnoncustomers</method>
37
+ <acl>magnews/useplugin</acl>
38
+ </getallnoncustomers>
39
+ <getnoncustomerspage translate="title" module="magnews">
40
+ <title>Retrieve a page of Newsletter subscriptions for non customers</title>
41
+ <method>getnoncustomerspage</method>
42
+ <acl>magnews/useplugin</acl>
43
+ </getnoncustomerspage>
44
+ <countnoncustomers translate="title" module="magnews">
45
+ <title>Count Newsletter subscriptions for non customers</title>
46
+ <method>countnoncustomers</method>
47
+ <acl>magnews/useplugin</acl>
48
+ </countnoncustomers>
49
+ <customersubscription translate="title" module="magnews">
50
+ <title>Retrive Newsletter subscriptions for a customer</title>
51
+ <method>customersubscription</method>
52
+ <acl>magnews/useplugin</acl>
53
+ </customersubscription>
54
+ <subscribe translate="title" module="magnews">
55
+ <title>Subscribe an email address</title>
56
+ <method>subscribe</method>
57
+ <acl>magnews/useplugin</acl>
58
+ </subscribe>
59
+ <unsubscribe translate="title" module="magnews">
60
+ <title>Unsubscribe an email address</title>
61
+ <method>unsubscribe</method>
62
+ <acl>magnews/useplugin</acl>
63
+ </unsubscribe>
64
+ <getbyemail translate="title" module="magnews">
65
+ <title>Gets a subscription using email as key</title>
66
+ <method>getbyemail</method>
67
+ <acl>magnews/useplugin</acl>
68
+ </getbyemail>
69
+ </methods>
70
+ </magnews_newslettersubscription>
71
+ <magnews_customerlogin translate="title" module="magnews">
72
+ <title>Customer Login</title>
73
+ <model>Diennea_MagNews_Model_Customerlogin_Api</model>
74
+ <acl>magnews</acl>
75
+ <methods>
76
+ <lastloginforcustomer translate="title" module="magnews">
77
+ <title>Retrive last login for customer</title>
78
+ <method>lastloginforcustomer</method>
79
+ <acl>magnews/useplugin</acl>
80
+ </lastloginforcustomer>
81
+ </methods>
82
+ </magnews_customerlogin>
83
+ <magnews_customersbatch translate="title" module="magnews">
84
+ <title>Customer Batch find utils</title>
85
+ <model>Diennea_MagNews_Model_Customersbatch_Api</model>
86
+ <acl>magnews</acl>
87
+ <methods>
88
+ <getcustomersidpage translate="title" module="magnews">
89
+ <title>Retrieve customers list</title>
90
+ <method>getcustomersidpage</method>
91
+ <acl>magnews/useplugin</acl>
92
+ </getcustomersidpage>
93
+ <countcustomers translate="title" module="magnews">
94
+ <title>Retrieve customers count</title>
95
+ <method>countcustomers</method>
96
+ <acl>magnews/useplugin</acl>
97
+ </countcustomers>
98
+ <getdetailedinfo translate="title" module="magnews">
99
+ <title>Retrieve detailed info about a customer (main fields, last order, last address...)</title>
100
+ <method>getdetailedinfo</method>
101
+ <acl>magnews/useplugin</acl>
102
+ </getdetailedinfo>
103
+ </methods>
104
+ </magnews_customersbatch>
105
+ <magnews_global_queries translate="title" module="magnews">
106
+ <title>MagNews Global queries</title>
107
+ <model>Diennea_MagNews_Model_Globalqueries_Api</model>
108
+ <acl>magnews</acl>
109
+ <methods>
110
+ <getbestsellerproduct translate="title" module="magnews">
111
+ <title>Retrieve Best seller product</title>
112
+ <method>getbestsellerproduct</method>
113
+ <acl>magnews/useplugin</acl>
114
+ </getbestsellerproduct>
115
+ <getmostprofitableproduct translate="title" module="magnews">
116
+ <title>Retrieve Most profitable product</title>
117
+ <method>getmostprofitableproduct</method>
118
+ <acl>magnews/useplugin</acl>
119
+ </getmostprofitableproduct>
120
+ <getmostviewedproduct translate="title" module="magnews">
121
+ <title>Retrieve most viewed product</title>
122
+ <method>getmostviewedproduct</method>
123
+ <acl>magnews/useplugin</acl>
124
+ </getmostviewedproduct>
125
+ <getmostwishedproduct translate="title" module="magnews">
126
+ <title>Retrieve most wished product</title>
127
+ <method>getmostwishedproduct</method>
128
+ <acl>magnews/useplugin</acl>
129
+ </getmostwishedproduct>
130
+ <getmostabandonedproduct translate="title" module="magnews">
131
+ <title>Retrieve most abandoned product</title>
132
+ <method>getmostabandonedproduct</method>
133
+ <acl>magnews/useplugin</acl>
134
+ </getmostabandonedproduct>
135
+ </methods>
136
+ </magnews_global_queries>
137
+ <magnews_customer_queries translate="title" module="magnews">
138
+ <title>MagNews Customer Queries</title>
139
+ <model>Diennea_MagNews_Model_Customerqueries_Api</model>
140
+ <acl>magnews</acl>
141
+ <methods>
142
+ <getmostwishedproduct translate="title" module="magnews">
143
+ <title>Most wisehd product</title>
144
+ <method>getmostwishedproduct</method>
145
+ <acl>magnews/useplugin</acl>
146
+ </getmostwishedproduct>
147
+ </methods>
148
+ </magnews_customer_queries>
149
+ <magnews_catalog translate="title" module="magnews">
150
+ <title>Catalog</title>
151
+ <model>Diennea_MagNews_Model_Catalog_Api</model>
152
+ <acl>magnews</acl>
153
+ <methods>
154
+ <getmaxproductid translate="title" module="magnews">
155
+ <title>Retrieve current min and max database ids of catalog products</title>
156
+ <method>getminandmaxproductid</method>
157
+ <acl>magnews/useplugin</acl>
158
+ </getmaxproductid>
159
+ </methods>
160
+ </magnews_catalog>
161
+ </resources>
162
+ <acl>
163
+ <resources>
164
+ <magnews translate="title" module="magnews">
165
+ <title>MagNews</title>
166
+ <useplugin translate="title" module="magnews">
167
+ <title>Use MagNews Plugin API methods</title>
168
+ </useplugin>
169
+ </magnews>
170
+ </resources>
171
+ </acl>
172
+ </api>
173
+ </config>
app/code/local/Diennea/MagNews/etc/config.xml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Diennea_MagNews>
5
+ <version>2.0.0</version>
6
+ </Diennea_MagNews>
7
+ </modules>
8
+ <global>
9
+ <models>
10
+ <magnews>
11
+ <class>Diennea_MagNews_Model</class>
12
+ </magnews>
13
+ </models>
14
+ <helpers>
15
+ <magnews>
16
+ <class>Diennea_MagNews_Helper</class>
17
+ </magnews>
18
+ </helpers>
19
+ </global>
20
+ </config>
app/code/local/Diennea/MagNews/etc/system.xml ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <sections>
4
+ </sections>
5
+ </config>
app/etc/modules/Diennea_MagNews.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Diennea_MagNews>
5
+ <active>true</active>
6
+ <codePool>local</codePool>
7
+ </Diennea_MagNews>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>MagNews_Connector</name>
4
+ <version>2.0.1</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Relevant email marketing, thanks to automated targeted lifecycle promotions, based on chart recovery, up selling, cross selling, whishlists</summary>
10
+ <description>MagNews Connector for Magento was developed to integrate the information contained on your Ecommerce (customer lists, product descriptions, orders, click, shopping carts and whishlists) with the Email Marketing platform MagNews. &#xD;
11
+ &#xD;
12
+ Our connector allows you to create promos containing information relevant to the user in few clicks.</description>
13
+ <notes>MagNews Connector for Magento was developed to integrate the information contained on your Ecommerce (customer lists, product descriptions, orders, click, shopping carts and whishlists) with the Email Marketing platform MagNews. &#xD;
14
+ &#xD;
15
+ Our connector allows you to create promos containing information relevant to the user in few clicks.&#xD;
16
+ &#xD;
17
+ =============================&#xD;
18
+ &#xD;
19
+ Il connettore MagNews per Magento nasce dall'esigenza di integrare le informazioni contenute sul tuo ecommerce Magento (lista clienti, iscritti alla newsletter, descrizione prodotti, ordini, prodotti visualizzati/cliccati, carrelli abbandonati e lista desideri) con la tua piattaforma per l'Email Marketing MagNews.&#xD;
20
+ &#xD;
21
+ Il nostro connettore ti permette di creare promozioni contenenti informazioni rilevanti per l'utente in pochi click.&#xD;
22
+ </notes>
23
+ <authors><author><name>MagNews Development Team</name><user>magnews</user><email>info@magnews.it</email></author></authors>
24
+ <date>2014-09-22</date>
25
+ <time>14:47:17</time>
26
+ <contents><target name="magelocal"><dir name="Diennea"><dir name="MagNews"><dir name="Helper"><file name="Data.php" hash="e987ec7fdf08772f87c9a6b6d5cf896b"/></dir><dir name="Model"><dir name="Abandonedcart"><file name="Api.php" hash="70dc4d31662c7114ed8381aeeed2570a"/></dir><dir name="Catalog"><file name="Api.php" hash="ce310ce76c7a6037e45650fed8dd65a0"/></dir><dir name="Custom"><dir name="Reports"><dir name="Products"><dir name="Mostabandoned"><file name="Collection.php" hash="25ee2293c9d33763706b614abc506410"/></dir><dir name="Mostprofitable"><file name="Collection.php" hash="9ac2b1aa23aaa5332fb7ae02a3977fee"/></dir></dir></dir></dir><dir name="Customerlogin"><file name="Api.php" hash="b5ed4c3e391db440d873462949306e38"/></dir><dir name="Customerqueries"><file name="Api.php" hash="65320aeeae57fa6d7eac5bae81daf417"/></dir><dir name="Customersbatch"><file name="Api.php" hash="ae08720149dd9099eda8bf675d98be60"/></dir><dir name="Globalqueries"><file name="Api.php" hash="bde93356d2946f0c1e99de13bc68ebdf"/></dir><dir name="Newslettersubscription"><file name="Api.php" hash="bd31b3dcf7ec58b426b675757965821c"/></dir><dir name="Version"><file name="Api.php" hash="36fdffb22d3e5ce184779375358dcd4e"/></dir></dir><dir name="etc"><file name="api.xml" hash="e35f9cf57f573a9962f0cdb079ca7230"/><file name="config.xml" hash="7459764707770ec6b4268b291cc4151d"/><file name="system.xml" hash="35d8f0b103721dd4fce9e0d1237d46de"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Diennea_MagNews.xml" hash="32805294b3f2834fd8c1806b5a6b241f"/></dir></target></contents>
27
+ <compatible/>
28
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
29
+ </package>