MagNews_Connector - Version 2.0.3

Version Notes

version 2.0.3 stable

Download this release

Release Info

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


Code changes from version 2.0.2 to 2.0.3

Files changed (21) hide show
  1. app/code/{local → community}/Diennea/MagNews/Helper/Data.php +0 -0
  2. app/code/{local → community}/Diennea/MagNews/Model/Abandonedcart/Api.php +0 -0
  3. app/code/community/Diennea/MagNews/Model/Catalog/Api.php +82 -0
  4. app/code/community/Diennea/MagNews/Model/Custom/Reports/Products/Mostabandoned/Collection.php +88 -0
  5. app/code/community/Diennea/MagNews/Model/Custom/Reports/Products/Mostprofitable/Collection.php +93 -0
  6. app/code/{local → community}/Diennea/MagNews/Model/Customerlogin/Api.php +0 -0
  7. app/code/{local → community}/Diennea/MagNews/Model/Customerqueries/Api.php +0 -0
  8. app/code/{local → community}/Diennea/MagNews/Model/Customersbatch/Api.php +15 -3
  9. app/code/community/Diennea/MagNews/Model/Globalqueries/Api.php +269 -0
  10. app/code/{local → community}/Diennea/MagNews/Model/Newslettersubscription/Api.php +20 -5
  11. app/code/community/Diennea/MagNews/Model/Store/Api.php +34 -0
  12. app/code/{local → community}/Diennea/MagNews/Model/Version/Api.php +1 -1
  13. app/code/{local → community}/Diennea/MagNews/etc/api.xml +30 -3
  14. app/code/{local → community}/Diennea/MagNews/etc/config.xml +1 -1
  15. app/code/{local → community}/Diennea/MagNews/etc/system.xml +0 -0
  16. app/code/local/Diennea/MagNews/Model/Catalog/Api.php +0 -22
  17. app/code/local/Diennea/MagNews/Model/Custom/Reports/Products/Mostabandoned/Collection.php +0 -69
  18. app/code/local/Diennea/MagNews/Model/Custom/Reports/Products/Mostprofitable/Collection.php +0 -73
  19. app/code/local/Diennea/MagNews/Model/Globalqueries/Api.php +0 -135
  20. app/etc/modules/Diennea_MagNews.xml +8 -9
  21. package.xml +7 -18
app/code/{local → community}/Diennea/MagNews/Helper/Data.php RENAMED
File without changes
app/code/{local → community}/Diennea/MagNews/Model/Abandonedcart/Api.php RENAMED
File without changes
app/code/community/Diennea/MagNews/Model/Catalog/Api.php ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Estensione metodi sul catalogo.
5
+ *
6
+ * @author Andrea Mallegni
7
+ * @version $Id$
8
+ */
9
+ class Diennea_MagNews_Model_Catalog_Api extends Mage_Api_Model_Resource_Abstract {
10
+
11
+ /**
12
+ * Restituisce il min e il max id della tabella dei prodotti.
13
+ *
14
+ * @return int max id prodotto
15
+ */
16
+ public function getminandmaxproductid() {
17
+ $resource = Mage::getSingleton('core/resource');
18
+ $readConnection = $resource->getConnection('core_read');
19
+ $query = 'SELECT MIN(entity_id) AS min_id, MAX(entity_id) as max_id FROM ' . $resource->getTableName('catalog/product');
20
+ return $readConnection->fetchAll($query);
21
+ }
22
+
23
+ /**
24
+ * Restituisce i prodotti appartenenti a categorie su cui lo store fornito
25
+ * ha visibilità.
26
+ *
27
+ * @param type $storeId
28
+ * @param type $filters
29
+ * @return type
30
+ */
31
+ public function getproductsbystore($storeId, $filters) {
32
+ if (empty($storeId) || $storeId < 0) {
33
+ die('YOU MUST SUPPLY A STORE ID');
34
+ }
35
+
36
+ $resource = Mage::getSingleton('core/resource');
37
+
38
+ $idFrom = $filters["product_id"]["from"];
39
+ $idTo = $filters["product_id"]["to"];
40
+
41
+ $query = 'SELECT DISTINCT p.entity_id AS product_id '
42
+ . 'FROM ' . $resource->getTableName('catalog/product') . ' p '
43
+ . 'INNER JOIN ' . $resource->getTableName('catalog/category_product') . ' cp ON p.entity_id=cp.product_id '
44
+ . 'INNER JOIN ' . $resource->getTableName('catalog/category') . ' c ON cp.category_id=c.entity_id '
45
+ . 'WHERE 1=1';
46
+
47
+ if (!empty($idFrom)) {
48
+ $query .= ' AND p.entity_id >= ' . $idFrom;
49
+ }
50
+ if (!empty($idTo)) {
51
+ $query .= ' AND p.entity_id <= ' . $idTo;
52
+ }
53
+
54
+ $rootId = Mage::app()->getStore($storeId)->getRootCategoryId();
55
+ $catSubquery = 'SELECT cat.entity_id FROM ' . $resource->getTableName('catalog/category') . ' cat '
56
+ . 'WHERE (cat.path = \'1/' . $rootId . '\' OR cat.path LIKE \'1/' . $rootId . '/%\')';
57
+ $query .= ' AND c.entity_id IN (' . $catSubquery . ') '
58
+ . 'GROUP BY p.entity_id';
59
+
60
+ $value = $resource->getConnection('core_read')->query($query);
61
+ $rows = $value->fetchAll();
62
+
63
+ return $rows;
64
+ }
65
+
66
+ /**
67
+ * Restituisce l'id dei prodotti figli per il prodotto configurabile fornito.
68
+ *
69
+ * @param type $parentProductId
70
+ * @return type
71
+ */
72
+ public function getproductrelation($parentProductId) {
73
+ $resource = Mage::getSingleton('core/resource');
74
+ $query = 'SELECT child_id FROM ' . $resource->getTableName('catalog/product_relation') . ' WHERE parent_id = ' . $parentProductId;
75
+
76
+ $value = $resource->getConnection('core_read')->query($query);
77
+ $rows = $value->fetchAll();
78
+
79
+ return $rows;
80
+ }
81
+
82
+ }
app/code/community/Diennea/MagNews/Model/Custom/Reports/Products/Mostabandoned/Collection.php ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Created by IntelliJ IDEA.
5
+ * User: Carlo
6
+ * Date: 14/04/14
7
+ * Time: 19.27
8
+ */
9
+ class Diennea_MagNews_Model_Custom_Reports_Products_Mostabandoned_Collection extends Mage_Reports_Model_Resource_Product_Collection {
10
+
11
+ public function prepareAbandonedProductQuery($storeId = -1) {
12
+ $this->_reset()
13
+ ->addAttributeToSelect('*')
14
+ ->addAbandonedProducts($storeId)
15
+ ->setOrder('ordered_qty', self::SORT_ORDER_DESC);
16
+ return $this;
17
+ }
18
+
19
+ public function addAbandonedProducts($storeId = -1) {
20
+ $adapter = $this->getConnection();
21
+ $compositeTypeIds = Mage::getSingleton('catalog/product_type')->getCompositeTypes();
22
+ $orderTableAliasName = $adapter->quoteIdentifier('abandoned');
23
+ $categoryProductAliasName = $adapter->quoteIdentifier('category_product');
24
+ $categoryAliasName = $adapter->quoteIdentifier('category');
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
+ $productJoinCondition = array(
32
+ $adapter->quoteInto('(e.type_id NOT IN (?))', $compositeTypeIds),
33
+ 'e.entity_id = abandoned_items.product_id',
34
+ $adapter->quoteInto('e.entity_type_id = ?', $this->getProductEntityTypeId())
35
+ );
36
+
37
+ $storeWhere = '';
38
+ if ($storeId > -1) {
39
+ $categoryProductJoinCondition = array(
40
+ $categoryProductAliasName . '.product_id = e.entity_id'
41
+ );
42
+ $categoryJoinCondition = array(
43
+ $categoryAliasName . '.entity_id = ' . $categoryProductAliasName . '.category_id'
44
+ );
45
+
46
+ $catRootId = Mage::app()->getStore($storeId)->getRootCategoryId();
47
+ $catSubquery = 'SELECT cat.entity_id FROM ' . Mage::getSingleton('core/resource')->getTableName('catalog/category') . ' cat '
48
+ . 'WHERE (cat.path = \'1/' . $catRootId . '\' OR cat.path LIKE \'1/' . $catRootId . '/%\')';
49
+ $storeWhere = ' AND ' . $categoryAliasName . '.entity_id IN (' . $catSubquery . ')';
50
+ }
51
+
52
+
53
+ $select = $this->getSelect();
54
+ $select->reset()
55
+ ->from(
56
+ array('abandoned_items' => $this->getTable('sales/quote_item')), array(
57
+ 'ordered_qty' => 'SUM(abandoned_items.qty)'
58
+ ))
59
+ ->joinInner(
60
+ array('abandoned' => $this->getTable('sales/quote')), implode(' AND ', $orderJoinCondition), array())
61
+ ->joinLeft(
62
+ array('e' => $this->getProductEntityTableName()), implode(' AND ', $productJoinCondition), array(
63
+ 'entity_id' => 'abandoned_items.product_id',
64
+ 'entity_type_id' => 'e.entity_type_id',
65
+ 'attribute_set_id' => 'e.attribute_set_id',
66
+ 'type_id' => 'e.type_id',
67
+ 'sku' => 'e.sku',
68
+ 'has_options' => 'e.has_options',
69
+ 'required_options' => 'e.required_options',
70
+ 'created_at' => 'e.created_at',
71
+ 'updated_at' => 'e.updated_at'
72
+ ));
73
+
74
+ if ($storeId > -1) {
75
+ $select->joinInner(
76
+ array('category_product' => $this->getTable('catalog/category_product')), implode(' AND ', $categoryProductJoinCondition), array())
77
+ ->joinInner(
78
+ array('category' => $this->getTable('catalog/category')), implode(' AND ', $categoryJoinCondition), array());
79
+ }
80
+
81
+ $select->where('parent_item_id IS NULL' . $storeWhere)
82
+ ->group('abandoned_items.product_id')
83
+ ->having('SUM(abandoned_items.qty) > ?', 0);
84
+ //->order('abandoned_item_qty', self::SORT_ORDER_DESC);
85
+ return $this;
86
+ }
87
+
88
+ }
app/code/community/Diennea/MagNews/Model/Custom/Reports/Products/Mostprofitable/Collection.php ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Created by IntelliJ IDEA.
5
+ * User: Carlo
6
+ * Date: 13/04/14
7
+ * Time: 20.29
8
+ */
9
+ class Diennea_MagNews_Model_Custom_Reports_Products_Mostprofitable_Collection extends Mage_Reports_Model_Resource_Product_Collection {
10
+
11
+ public function setParameters($from, $to, $storeId) {
12
+ $this->_reset()
13
+ ->addAttributeToSelect('*')
14
+ ->addTotProfit($from, $to, $storeId)
15
+ ->setOrder('ordered_qty', self::SORT_ORDER_DESC);
16
+ return $this;
17
+ }
18
+
19
+ public function addTotProfit($from = '', $to = '', $storeId = -1) {
20
+ $adapter = $this->getConnection();
21
+ $compositeTypeIds = Mage::getSingleton('catalog/product_type')->getCompositeTypes();
22
+ $orderTableAliasName = $adapter->quoteIdentifier('order');
23
+ $categoryProductAliasName = $adapter->quoteIdentifier('category_product');
24
+ $categoryAliasName = $adapter->quoteIdentifier('category');
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
+ $productJoinCondition = array(
32
+ $adapter->quoteInto('(e.type_id NOT IN (?))', $compositeTypeIds),
33
+ 'e.entity_id = order_items.product_id',
34
+ $adapter->quoteInto('e.entity_type_id = ?', $this->getProductEntityTypeId())
35
+ );
36
+
37
+ if ($from != '' && $to != '') {
38
+ $fieldName = $orderTableAliasName . '.created_at';
39
+ $orderJoinCondition[] = $this->_prepareBetweenSql($fieldName, $from, $to);
40
+ }
41
+
42
+ $storeWhere = '';
43
+ if ($storeId > -1) {
44
+ $categoryProductJoinCondition = array(
45
+ $categoryProductAliasName . '.product_id = e.entity_id'
46
+ );
47
+ $categoryJoinCondition = array(
48
+ $categoryAliasName . '.entity_id = ' . $categoryProductAliasName . '.category_id'
49
+ );
50
+
51
+ $catRootId = Mage::app()->getStore($storeId)->getRootCategoryId();
52
+ $catSubquery = 'SELECT cat.entity_id FROM ' . Mage::getSingleton('core/resource')->getTableName('catalog/category') . ' cat '
53
+ . 'WHERE (cat.path = \'1/' . $catRootId . '\' OR cat.path LIKE \'1/' . $catRootId . '/%\')';
54
+ $storeWhere = ' AND ' . $categoryAliasName . '.entity_id IN (' . $catSubquery . ')';
55
+ }
56
+
57
+ $select = $this->getSelect();
58
+ $select->reset()
59
+ ->from(
60
+ array('order_items' => $this->getTable('sales/order_item')), array(
61
+ 'ordered_qty' => 'SUM(order_items.qty_ordered*order_items.price)',
62
+ 'order_items_name' => 'order_items.name'
63
+ ))
64
+ ->joinInner(
65
+ array('order' => $this->getTable('sales/order')), implode(' AND ', $orderJoinCondition), array());
66
+
67
+ $select->joinLeft(
68
+ array('e' => $this->getProductEntityTableName()), implode(' AND ', $productJoinCondition), array(
69
+ 'entity_id' => 'order_items.product_id',
70
+ 'entity_type_id' => 'e.entity_type_id',
71
+ 'attribute_set_id' => 'e.attribute_set_id',
72
+ 'type_id' => 'e.type_id',
73
+ 'sku' => 'e.sku',
74
+ 'has_options' => 'e.has_options',
75
+ 'required_options' => 'e.required_options',
76
+ 'created_at' => 'e.created_at',
77
+ 'updated_at' => 'e.updated_at'
78
+ ))
79
+ ->where('parent_item_id IS NULL' . $storeWhere)
80
+ ->group('order_items.product_id')
81
+ ->having('SUM(order_items.qty_ordered*order_items.price) > ?', 0);
82
+
83
+ if ($storeId > -1) {
84
+ $select->joinInner(
85
+ array('category_product' => $this->getTable('catalog/category_product')), implode(' AND ', $categoryProductJoinCondition), array())
86
+ ->joinInner(
87
+ array('category' => $this->getTable('catalog/category')), implode(' AND ', $categoryJoinCondition), array());
88
+ }
89
+
90
+ return $this;
91
+ }
92
+
93
+ }
app/code/{local → community}/Diennea/MagNews/Model/Customerlogin/Api.php RENAMED
File without changes
app/code/{local → community}/Diennea/MagNews/Model/Customerqueries/Api.php RENAMED
File without changes
app/code/{local → community}/Diennea/MagNews/Model/Customersbatch/Api.php RENAMED
@@ -2,22 +2,34 @@
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);
2
 
3
  class Diennea_MagNews_Model_Customersbatch_Api extends Mage_Api_Model_Resource_Abstract {
4
 
5
+ public function getcustomersidpage($pageNum, $pageSize, $storeId = -1) {
6
  $result = array();
7
  $all = Mage::getModel('customer/customer')->getCollection();
8
+
9
+ if ($storeId > -1) {
10
+ $all->addFieldToFilter("store_id", $storeId);
11
+ }
12
+
13
  $all->addAttributeToSort('entity_id', 'asc')
14
  ->setPage($pageNum, $pageSize);
15
+
16
  foreach ($all as $customer) {
17
  $result[] = $customer["entity_id"];
18
  }
19
  return $result;
20
  }
21
 
22
+ public function countcustomers($storeId = -1) {
23
  $all = Mage::getModel('customer/customer')->getCollection();
24
+
25
+ if ($storeId > -1) {
26
+ $all->addFieldToFilter("store_id", $storeId);
27
+ }
28
+
29
  $all->getSelect()
30
  ->reset(Zend_Db_Select::COLUMNS)
31
+ ->columns('COUNT(*) AS entitycount');
32
+
33
  $stmt = $all->getSelect()->query();
34
  $result = $stmt->fetchAll();
35
  $first = current($result);
app/code/community/Diennea/MagNews/Model/Globalqueries/Api.php ADDED
@@ -0,0 +1,269 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Created by IntelliJ IDEA.
5
+ * User: Carlo
6
+ * Date: 12/04/14
7
+ * Time: 19.29
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, $term = '', $catId = 0, $storeId = -1, $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
+
22
+ if ($nres > self::$maxRes)
23
+ $nres = self::$maxRes;
24
+ if ($nres <= 0)
25
+ $nres = self::$maxRes;
26
+ $collection->setPageSize($nres);
27
+
28
+ if ($storeId > -1) {
29
+ $adapter = $collection->getConnection();
30
+ $categoryProductAliasName = $adapter->quoteIdentifier('category_product');
31
+ $categoryAliasName = $adapter->quoteIdentifier('category');
32
+
33
+ $categoryProductJoinCondition = array(
34
+ $categoryProductAliasName . '.product_id = e.entity_id'
35
+ );
36
+ $categoryJoinCondition = array(
37
+ $categoryAliasName . '.entity_id = ' . $categoryProductAliasName . '.category_id'
38
+ );
39
+
40
+ $select = $collection->getSelect();
41
+
42
+ $select->joinInner(
43
+ array('category_product' => $collection->getTable('catalog/category_product')), implode(' AND ', $categoryProductJoinCondition), array())
44
+ ->joinInner(
45
+ array('category' => $collection->getTable('catalog/category')), implode(' AND ', $categoryJoinCondition), array());
46
+
47
+ $catRootId = Mage::app()->getStore($storeId)->getRootCategoryId();
48
+ $catSubquery = 'SELECT cat.entity_id FROM ' . Mage::getSingleton('core/resource')->getTableName('catalog/category') . ' cat '
49
+ . 'WHERE (cat.path = \'1/' . $catRootId . '\' OR cat.path LIKE \'1/' . $catRootId . '/%\')';
50
+ $storeWhere = $categoryAliasName . '.entity_id IN (' . $catSubquery . ')';
51
+
52
+ $select->where($storeWhere);
53
+ }
54
+
55
+ if (!empty($term)) {
56
+ $productNameAttribute = Mage::getModel('eav/entity_attribute')->loadByCode('4', 'name');
57
+ $collection->getSelect()->joinLeft(
58
+ array('cpev' => Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')), 'cpev.entity_id = e.entity_id', array('name' => 'value'));
59
+ $collection->getSelect()->where('e.sku like \'%' . $term . '%\' OR (cpev.attribute_id=' . $productNameAttribute->getAttributeId() . ' AND cpev.value like \'%' . $term . '%\')');
60
+ }
61
+
62
+ $res = $collection->load()->toArray();
63
+ return $res;
64
+ }
65
+
66
+ public function getmostprofitableproduct($from, $to, $term = '', $catId = 0, $storeId = -1, $nres = 20) {
67
+ $collection = new Diennea_MagNews_Model_Custom_Reports_Products_Mostprofitable_Collection();
68
+ $collection->setParameters($from, $to, $storeId);
69
+
70
+ if ($catId != 0) {
71
+ $category = new Mage_Catalog_Model_Category();
72
+ $category->setId($catId);
73
+ $collection->addCategoryFilter($category);
74
+ }
75
+
76
+ if (!empty($term)) {
77
+ $productNameAttribute = Mage::getModel('eav/entity_attribute')->loadByCode('4', 'name');
78
+ $collection->getSelect()->joinLeft(
79
+ array('cpev' => Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')), 'cpev.entity_id = e.entity_id', array('name' => 'value'));
80
+ $collection->getSelect()->where('e.sku like \'%' . $term . '%\' OR (cpev.attribute_id=' . $productNameAttribute->getAttributeId() . ' AND cpev.value like \'%' . $term . '%\')');
81
+ }
82
+
83
+ if ($nres > self::$maxRes)
84
+ $nres = self::$maxRes;
85
+ if ($nres <= 0)
86
+ $nres = self::$maxRes;
87
+
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]['tot_profit'] = $v;
94
+ }
95
+ }
96
+ }
97
+ return $res;
98
+ }
99
+
100
+ public function getmostviewedproduct($from, $to, $term = '', $catId = 0, $storeId = -1, $nres = 20) {
101
+ if ($nres > self::$maxRes)
102
+ $nres = self::$maxRes;
103
+ if ($nres <= 0)
104
+ $nres = self::$maxRes;
105
+ $collection = Mage::getResourceModel('reports/product_collection')->addAttributeToSelect('*')->addViewsCount($from, $to)
106
+ ->setPageSize($nres);
107
+
108
+ if ($catId != 0) {
109
+ $category = new Mage_Catalog_Model_Category();
110
+ $category->setId($catId);
111
+ $collection->addCategoryFilter($category);
112
+ }
113
+
114
+ if ($storeId > -1) {
115
+ $adapter = $collection->getConnection();
116
+ $categoryProductAliasName = $adapter->quoteIdentifier('category_product');
117
+ $categoryAliasName = $adapter->quoteIdentifier('category');
118
+
119
+ $categoryProductJoinCondition = array(
120
+ $categoryProductAliasName . '.product_id = e.entity_id'
121
+ );
122
+ $categoryJoinCondition = array(
123
+ $categoryAliasName . '.entity_id = ' . $categoryProductAliasName . '.category_id'
124
+ );
125
+
126
+ $select = $collection->getSelect();
127
+
128
+ $select->joinInner(
129
+ array('category_product' => $collection->getTable('catalog/category_product')), implode(' AND ', $categoryProductJoinCondition), array())
130
+ ->joinInner(
131
+ array('category' => $collection->getTable('catalog/category')), implode(' AND ', $categoryJoinCondition), array());
132
+
133
+ $catRootId = Mage::app()->getStore($storeId)->getRootCategoryId();
134
+ $catSubquery = 'SELECT cat.entity_id FROM ' . Mage::getSingleton('core/resource')->getTableName('catalog/category') . ' cat '
135
+ . 'WHERE (cat.path = \'1/' . $catRootId . '\' OR cat.path LIKE \'1/' . $catRootId . '/%\')';
136
+ $storeWhere = $categoryAliasName . '.entity_id IN (' . $catSubquery . ')';
137
+
138
+ $select->where($storeWhere);
139
+ }
140
+
141
+ if (!empty($term)) {
142
+ $productNameAttribute = Mage::getModel('eav/entity_attribute')->loadByCode('4', 'name');
143
+ $collection->getSelect()->joinLeft(
144
+ array('cpev' => Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')), 'cpev.entity_id = e.entity_id', array('name' => 'value'));
145
+ $collection->getSelect()->where('e.sku like \'%' . $term . '%\' OR (cpev.attribute_id=' . $productNameAttribute->getAttributeId() . ' AND cpev.value like \'%' . $term . '%\')');
146
+ }
147
+
148
+ $ret = $collection->load()->toArray();
149
+ return $ret;
150
+ }
151
+
152
+ public function getmostwishedproduct($from, $to, $term = '', $catId = 0, $storeId = -1, $nres = 20) {
153
+ $collection = Mage::getResourceModel('reports/product_collection')->addAttributeToSelect('*');
154
+ if ($nres > self::$maxRes)
155
+ $nres = self::$maxRes;
156
+ if ($nres <= 0)
157
+ $nres = self::$maxRes;
158
+
159
+ $collection = $this->addWishCount($collection, $from, $to)->setPageSize($nres);
160
+
161
+ if ($catId != 0) {
162
+ $category = new Mage_Catalog_Model_Category();
163
+ $category->setId($catId);
164
+ $collection->addCategoryFilter($category);
165
+ }
166
+
167
+ if ($storeId > -1) {
168
+ $adapter = $collection->getConnection();
169
+ $categoryProductAliasName = $adapter->quoteIdentifier('category_product');
170
+ $categoryAliasName = $adapter->quoteIdentifier('category');
171
+
172
+ $categoryProductJoinCondition = array(
173
+ $categoryProductAliasName . '.product_id = e.entity_id'
174
+ );
175
+ $categoryJoinCondition = array(
176
+ $categoryAliasName . '.entity_id = ' . $categoryProductAliasName . '.category_id'
177
+ );
178
+
179
+ $select = $collection->getSelect();
180
+
181
+ $select->joinInner(
182
+ array('category_product' => $collection->getTable('catalog/category_product')), implode(' AND ', $categoryProductJoinCondition), array())
183
+ ->joinInner(
184
+ array('category' => $collection->getTable('catalog/category')), implode(' AND ', $categoryJoinCondition), array());
185
+
186
+ $catRootId = Mage::app()->getStore($storeId)->getRootCategoryId();
187
+ $catSubquery = 'SELECT cat.entity_id FROM ' . Mage::getSingleton('core/resource')->getTableName('catalog/category') . ' cat '
188
+ . 'WHERE (cat.path = \'1/' . $catRootId . '\' OR cat.path LIKE \'1/' . $catRootId . '/%\')';
189
+ $storeWhere = $categoryAliasName . '.entity_id IN (' . $catSubquery . ')';
190
+
191
+ $select->where($storeWhere);
192
+ }
193
+
194
+ if (!empty($term)) {
195
+ $productNameAttribute = Mage::getModel('eav/entity_attribute')->loadByCode('4', 'name');
196
+ $collection->getSelect()->joinLeft(
197
+ array('cpev' => Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')), 'cpev.entity_id = e.entity_id', array('name' => 'value'));
198
+ $collection->getSelect()->where('e.sku like \'%' . $term . '%\' OR (cpev.attribute_id=' . $productNameAttribute->getAttributeId() . ' AND cpev.value like \'%' . $term . '%\')');
199
+ }
200
+
201
+ $ret = $collection->load()->toArray();
202
+ return $ret;
203
+ }
204
+
205
+ public function getmostabandonedproduct($term = '', $catId = 0, $storeId = -1, $nres = 20) {
206
+ $collection = new Diennea_MagNews_Model_Custom_Reports_Products_Mostabandoned_Collection();
207
+ $collection->prepareAbandonedProductQuery($storeId);
208
+ if ($catId != 0) {
209
+ $category = new Mage_Catalog_Model_Category();
210
+ $category->setId($catId);
211
+ $collection->addCategoryFilter($category);
212
+ }
213
+
214
+ if (!empty($term)) {
215
+ $productNameAttribute = Mage::getModel('eav/entity_attribute')->loadByCode('4', 'name');
216
+ $collection->getSelect()->joinLeft(
217
+ array('cpev' => Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')), 'cpev.entity_id = e.entity_id', array('name' => 'value'));
218
+ $collection->getSelect()->where('e.sku like \'%' . $term . '%\' OR (cpev.attribute_id=' . $productNameAttribute->getAttributeId() . ' AND cpev.value like \'%' . $term . '%\')');
219
+ }
220
+
221
+ if ($nres > self::$maxRes)
222
+ $nres = self::$maxRes;
223
+ if ($nres <= 0)
224
+ $nres = self::$maxRes;
225
+
226
+ $res = $collection->setPageSize($nres)->load()->toArray();
227
+ foreach ($res as $key => $val) {
228
+ foreach ($val as $k => $v) {
229
+ if ($k == "ordered_qty") {
230
+ unset($res[$key][$k]);
231
+ $res[$key]['abandoned_qty'] = $v;
232
+ }
233
+ }
234
+ }
235
+ return $res;
236
+ }
237
+
238
+ protected function addWishCount($that, $from = '', $to = '') {
239
+ /**
240
+ * Getting event type id for catalog_product_view event
241
+ */
242
+ foreach (Mage::getModel('reports/event_type')->getCollection() as $eventType) {
243
+ if ($eventType->getEventName() == 'wishlist_add_product') {
244
+ $productWishEvent = (int) $eventType->getId();
245
+ break;
246
+ }
247
+ }
248
+
249
+ $that->getSelect()->reset()
250
+ ->from(
251
+ array('report_table_wishes' => $that->getTable('reports/event')), array('wishes' => 'COUNT(report_table_wishes.event_id)'))
252
+ ->join(array('e' => $that->getProductEntityTableName()), $that->getConnection()->quoteInto(
253
+ "e.entity_id = report_table_wishes.object_id AND e.entity_type_id = ?", $that->getProductEntityTypeId()))
254
+ ->where('report_table_wishes.event_type_id = ?', $productWishEvent)
255
+ ->group('e.entity_id')
256
+ ->order('wishes ' . $that::SORT_ORDER_DESC)
257
+ ->having('COUNT(report_table_wishes.event_id) > ?', 0);
258
+
259
+ if ($from != '' && $to != '') {
260
+ $that->getSelect()
261
+ ->where('logged_at >= ?', $from)
262
+ ->where('logged_at <= ?', $to);
263
+ }
264
+
265
+ //$that->_useAnalyticFunction = true;
266
+ return $that;
267
+ }
268
+
269
+ }
app/code/{local → community}/Diennea/MagNews/Model/Newslettersubscription/Api.php RENAMED
@@ -2,11 +2,16 @@
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) {
@@ -15,11 +20,16 @@ class Diennea_MagNews_Model_Newslettersubscription_Api extends Mage_Api_Model_Re
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();
@@ -27,9 +37,14 @@ class Diennea_MagNews_Model_Newslettersubscription_Api extends Mage_Api_Model_Re
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');
2
 
3
  class Diennea_MagNews_Model_Newslettersubscription_Api extends Mage_Api_Model_Resource_Abstract {
4
 
5
+ public function getnoncustomerspage($pageNum, $pageSize, $storeId = -1) {
6
  $result = array();
7
  $subscriptions = Mage::getModel('newsletter/subscriber')
8
  ->getCollection()
9
  ->addFieldToFilter("customer_id", 0);
10
+
11
+ if ($storeId > -1) {
12
+ $subscriptions->addFieldToFilter("store_id", $storeId);
13
+ }
14
+
15
  $subscriptions->getSelect()->limit($pageSize, (($pageNum - 1) * $pageSize));
16
  $subscriptions->load(false, true);
17
  foreach ($subscriptions as $subscriber) {
20
  return $result;
21
  }
22
 
23
+ public function getallnoncustomers($storeId = -1) {
24
  $result = array();
25
+
26
+ $subscriptions = Mage::getModel('newsletter/subscriber')->getCollection();
27
  $subscriptions->addFieldToFilter("customer_id", 0);
28
+
29
+ if ($storeId > -1) {
30
+ $subscriptions->addFieldToFilter("store_id", $storeId);
31
+ }
32
+
33
  $subscriptions->load();
34
  foreach ($subscriptions as $subscriber) {
35
  $result[] = $subscriber->toArray();
37
  return $result;
38
  }
39
 
40
+ public function countnoncustomers($storeId = -1) {
41
  $all = Mage::getModel('newsletter/subscriber')->getCollection();
42
  $all->addFieldToFilter("customer_id", 0);
43
+
44
+ if ($storeId > -1) {
45
+ $all->addFieldToFilter("store_id", $storeId);
46
+ }
47
+
48
  $all->getSelect()
49
  ->reset(Zend_Db_Select::COLUMNS)
50
  ->columns('COUNT(*) AS entitycount');
app/code/community/Diennea/MagNews/Model/Store/Api.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Created by IntelliJ IDEA.
5
+ * User: Carlo
6
+ * Date: 12/04/14
7
+ * Time: 19.29
8
+ */
9
+ class Diennea_MagNews_Model_Store_Api extends Mage_Api_Model_Resource_Abstract {
10
+
11
+ /**
12
+ * Restituisce la tabella dei tassi di conversione da una valuta ad un'altra.
13
+ *
14
+ * @return type
15
+ */
16
+ public function getcurrencyrates() {
17
+ $baseCurrencyCode = Mage::app()->getBaseCurrencyCode();
18
+ $allowedCurrencies = Mage::getModel('directory/currency')->getConfigAllowCurrencies();
19
+ $currencyRates = Mage::getModel('directory/currency')->getCurrencyRates($baseCurrencyCode, array_values($allowedCurrencies));
20
+ return $currencyRates;
21
+ }
22
+
23
+ /**
24
+ * Restituisce la valuta di default per lo store richiesto o quella di
25
+ * default del website se niente è stato trovato.
26
+ *
27
+ * @param type $storeid
28
+ * @return type
29
+ */
30
+ public function getstoredefaultcurrency($storeid = 0) {
31
+ return Mage::app()->getStore($storeid)->getCurrentCurrencyCode();
32
+ }
33
+
34
+ }
app/code/{local → community}/Diennea/MagNews/Model/Version/Api.php RENAMED
@@ -3,7 +3,7 @@
3
  class Diennea_MagNews_Model_Version_Api extends Mage_Api_Model_Resource_Abstract {
4
 
5
  public function getpluginversion() {
6
- $result = array('version'=>'2.0.2');
7
  return $result;
8
  }
9
  }
3
  class Diennea_MagNews_Model_Version_Api extends Mage_Api_Model_Resource_Abstract {
4
 
5
  public function getpluginversion() {
6
+ $result = array('version'=>'2.0.3');
7
  return $result;
8
  }
9
  }
app/code/{local → community}/Diennea/MagNews/etc/api.xml RENAMED
@@ -1,4 +1,4 @@
1
-
2
  <config>
3
  <api>
4
  <resources>
@@ -152,12 +152,39 @@
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>
1
+ <?xml version="1.0"?>
2
  <config>
3
  <api>
4
  <resources>
152
  <acl>magnews</acl>
153
  <methods>
154
  <getmaxproductid translate="title" module="magnews">
155
+ <title>Retrieves current min and max database ids of catalog products</title>
156
  <method>getminandmaxproductid</method>
157
  <acl>magnews/useplugin</acl>
158
+ </getmaxproductid>
159
+ <getproductsbystore translate="title" module="magnews">
160
+ <title>Retrieves products associated to specific store view</title>
161
+ <method>getproductsbystore</method>
162
+ <acl>magnews/useplugin</acl>
163
+ </getproductsbystore>
164
+ <getproductrelation translate="title" module="magnews">
165
+ <title>Retrieves child products of supplied configurable product</title>
166
+ <method>getproductrelation</method>
167
+ <acl>magnews/useplugin</acl>
168
+ </getproductrelation>
169
  </methods>
170
  </magnews_catalog>
171
+ <magnews_store translate="title" module="magnews">
172
+ <title>MagNews Store queries</title>
173
+ <model>Diennea_MagNews_Model_Store_Api</model>
174
+ <acl>magnews</acl>
175
+ <methods>
176
+ <getcurrencyrates translate="title" module="magnews">
177
+ <title>Retrieves Currency Rates</title>
178
+ <method>getcurrencyrates</method>
179
+ <acl>magnews/useplugin</acl>
180
+ </getcurrencyrates>
181
+ <getstoredefaultcurrency translate="title" module="magnews">
182
+ <title>Retrieves Store Default Currency </title>
183
+ <method>getstoredefaultcurrency</method>
184
+ <acl>magnews/useplugin</acl>
185
+ </getstoredefaultcurrency>
186
+ </methods>
187
+ </magnews_store>
188
  </resources>
189
  <acl>
190
  <resources>
app/code/{local → community}/Diennea/MagNews/etc/config.xml RENAMED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <Diennea_MagNews>
5
- <version>2.0.2</version>
6
  </Diennea_MagNews>
7
  </modules>
8
  <global>
2
  <config>
3
  <modules>
4
  <Diennea_MagNews>
5
+ <version>2.0.3</version>
6
  </Diennea_MagNews>
7
  </modules>
8
  <global>
app/code/{local → community}/Diennea/MagNews/etc/system.xml RENAMED
File without changes
app/code/local/Diennea/MagNews/Model/Catalog/Api.php DELETED
@@ -1,22 +0,0 @@
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 DELETED
@@ -1,69 +0,0 @@
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 DELETED
@@ -1,73 +0,0 @@
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/Globalqueries/Api.php DELETED
@@ -1,135 +0,0 @@
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/etc/modules/Diennea_MagNews.xml CHANGED
@@ -1,9 +1,8 @@
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>
1
+ <config>
2
+ <modules>
3
+ <Diennea_MagNews>
4
+ <active>true</active>
5
+ <codePool>community</codePool>
6
+ </Diennea_MagNews>
7
+ </modules>
8
+ </config>
 
package.xml CHANGED
@@ -1,29 +1,18 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>MagNews_Connector</name>
4
- <version>2.0.2</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>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>MagNews_Connector</name>
4
+ <version>2.0.3</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>MagNews integration</summary>
10
+ <description>Relevant emails by automated targeted lifecycle promotions (chart recovery,upselling,crossselling, whishlists)</description>
11
+ <notes>version 2.0.3 stable</notes>
 
 
 
 
 
 
 
 
 
 
 
12
  <authors><author><name>MagNews Development Team</name><user>magnews</user><email>info@magnews.it</email></author></authors>
13
+ <date>2015-01-08</date>
14
+ <time>08:31:48</time>
15
+ <contents><target name="magecommunity"><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="f1df47b33fc40753f0a1b88a9feeb2ee"/></dir><dir name="Custom"><dir name="Reports"><dir name="Products"><dir name="Mostabandoned"><file name="Collection.php" hash="eadc4aab644727a34acf8a8a6f4a3ce9"/></dir><dir name="Mostprofitable"><file name="Collection.php" hash="a7169ff3e60939f244a3d26ceedccb94"/></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="6c79fa92190fb80e1eb677c69c35f437"/></dir><dir name="Globalqueries"><file name="Api.php" hash="60f6723247f7d952dff4ebaccaf64b46"/></dir><dir name="Newslettersubscription"><file name="Api.php" hash="ce3294946b010c3581cfa4b723482be7"/></dir><dir name="Store"><file name="Api.php" hash="1d5cafbbacf864d0731dd98c00c5f8e7"/></dir><dir name="Version"><file name="Api.php" hash="a1236d44170d4e1118d5a409e4ca0a83"/></dir></dir><dir name="etc"><file name="api.xml" hash="baf621b6425b6eb3ed0877b23bd4e90c"/><file name="config.xml" hash="49d90866ee479e3fef57382dc3a977d5"/><file name="system.xml" hash="35d8f0b103721dd4fce9e0d1237d46de"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Diennea_MagNews.xml" hash="412fb5437a0983360ecf098850b43d18"/></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
18
  </package>