AdvertiseCommunity - Version 1.2.0

Version Notes

v1.2.0

This version now has the common elements from the cross-sell, up-sell and related products extensions.
These elements are not active unless those packages are installed. So if you only have Advertise Colors, this extra code will not be used.

Download this release

Release Info

Developer Michael Oxley
Extension AdvertiseCommunity
Version 1.2.0
Comparing to
See all releases


Code changes from version 1.0.3 to 1.2.0

Files changed (29) hide show
  1. app/code/community/Advertise/Dataexport/Block/Adminhtml/Dataexportbackend.php +74 -0
  2. app/code/community/Advertise/Dataexport/Block/Index.php +5 -0
  3. app/code/community/Advertise/Dataexport/Helper/Data.php +124 -0
  4. app/code/community/Advertise/Dataexport/Model/Config.php +160 -0
  5. app/code/community/Advertise/Dataexport/Model/Exporter.php +168 -0
  6. app/code/community/Advertise/Dataexport/Model/Exporter/Cart.php +121 -0
  7. app/code/community/Advertise/Dataexport/Model/Exporter/Customer.php +58 -0
  8. app/code/community/Advertise/Dataexport/Model/Exporter/Interface.php +27 -0
  9. app/code/community/Advertise/Dataexport/Model/Exporter/Order.php +177 -0
  10. app/code/community/Advertise/Dataexport/Model/Modelname.php +12 -0
  11. app/code/community/Advertise/Dataexport/Model/Mysql4/Modelname.php +9 -0
  12. app/code/community/Advertise/Dataexport/Model/Mysql4/Modelname/Collection.php +9 -0
  13. app/code/community/Advertise/Dataexport/Model/Orderstatus.php +19 -0
  14. app/code/community/Advertise/Dataexport/Model/Scheduler.php +67 -0
  15. app/code/community/Advertise/Dataexport/Model/Xmlwriter.php +209 -0
  16. app/code/community/Advertise/Dataexport/controllers/Adminhtml/DataexportbackendController.php +78 -0
  17. app/code/community/Advertise/Dataexport/controllers/IndexController.php +41 -0
  18. app/code/community/Advertise/Dataexport/controllers/TestController.php +238 -0
  19. app/code/community/Advertise/Dataexport/etc/adminhtml.xml +43 -0
  20. app/code/community/Advertise/Dataexport/etc/config.xml +189 -0
  21. app/code/community/Advertise/Dataexport/etc/system.xml +138 -0
  22. app/code/community/Advertise/Dataexport/sql/dataexport_setup/mysql4-install-0.1.0.php +12 -0
  23. app/design/adminhtml/default/default/layout/dataexport.xml +14 -0
  24. app/design/adminhtml/default/default/template/dataexport/dataexportbackend.phtml +142 -0
  25. app/design/frontend/base/default/layout/dataexport.xml +12 -0
  26. app/design/frontend/base/default/template/dataexport/index.phtml +8 -0
  27. app/etc/modules/Advertise_Dataexport.xml +10 -0
  28. package.xml +7 -6
  29. var/advertisedata/{empty.txt → empty.file} +0 -0
app/code/community/Advertise/Dataexport/Block/Adminhtml/Dataexportbackend.php ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Advertise_Dataexport_Block_Adminhtml_Dataexportbackend extends Mage_Adminhtml_Block_Template
4
+ {
5
+ /**
6
+ * @var Advertise_Dataexport_Model_Config
7
+ */
8
+ protected $_config;
9
+
10
+ /**
11
+ * Get the config model
12
+ *
13
+ * @return Advertise_Dataexport_Model_Config
14
+ */
15
+ protected function _getConfig()
16
+ {
17
+ if($this->_config === NULL) {
18
+ $this->_config = Mage::getModel('dataexport/config');
19
+ }
20
+
21
+ return $this->_config;
22
+ }
23
+
24
+ /**
25
+ * Are the orders enabled
26
+ *
27
+ * @return string
28
+ */
29
+ protected function _isOrdersEnabledText()
30
+ {
31
+ return $this->_getConfig()->isOrderExportEnabled() ? 'Enabled' : 'Disabled';
32
+ }
33
+
34
+ /**
35
+ * Are the customers export enabled?
36
+ *
37
+ * @return string
38
+ */
39
+ protected function _isCustomersEnabledText()
40
+ {
41
+ return $this->_getConfig()->isCustomerExportEnabled() ? 'Enabled' : 'Disabled';
42
+ }
43
+
44
+
45
+ /**
46
+ * Are the customers export enabled?
47
+ *
48
+ * @return string
49
+ */
50
+ protected function _isCartsEnabledText()
51
+ {
52
+ return $this->_getConfig()->isCartExportEnabled() ? 'Enabled' : 'Disabled';
53
+ }
54
+
55
+ /**
56
+ * Is th emodule enabled??
57
+ *
58
+ * @return string
59
+ */
60
+ protected function _isEnabled()
61
+ {
62
+ return $this->_getConfig()->getIsEnabled() ? 'Enabled' : 'Disabled';
63
+ }
64
+
65
+ /**
66
+ * Get the form action
67
+ *
68
+ * @return string
69
+ */
70
+ protected function _getFormAction()
71
+ {
72
+ return Mage::getUrl('*/*/export');
73
+ }
74
+ }
app/code/community/Advertise/Dataexport/Block/Index.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+ class Advertise_Dataexport_Block_Index extends Mage_Core_Block_Template
3
+ {
4
+
5
+ }
app/code/community/Advertise/Dataexport/Helper/Data.php ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Data.php
4
+ */
5
+ class Advertise_Dataexport_Helper_Data extends Mage_Core_Helper_Abstract
6
+ {
7
+
8
+ protected $_initialVector = '0123456789123456';
9
+ protected $_secretKey = 'S1xt33NcHaRsl0Ng';
10
+
11
+ public function getAdvertiseHeaderScript()
12
+ {
13
+ if(Mage::registry('current_product')) {
14
+ $prodid = Mage::registry('current_product')->getId();
15
+ } else {
16
+ $prodid = '';
17
+ }
18
+ if(Mage::getModel('dataexport/config')->isHeadProductIdsEnabled()) {
19
+ $basket=$this->getProductDataString();
20
+ } else {
21
+ $basket = '';
22
+ }
23
+
24
+ $jsoutput = "
25
+ var adv_store_base_url = '".Mage::getBaseUrl()."';
26
+ var adv_reload = true;
27
+ adv_upsell_reload = true;
28
+ adv_crosssell_reload = true;
29
+ var adv_productid = '".$prodid."';
30
+ var adv_bsk = '".$basket."';
31
+ ";
32
+ // var cartcount = '".Mage::helper('checkout/cart')->getCart()->getItemsCount()."';
33
+
34
+ return $jsoutput;
35
+ }
36
+
37
+ /**
38
+ * Get the product IDs to output, but first check we want to show them
39
+ * just a shortcut for displaying inside template files
40
+ *
41
+ * @return string
42
+ */
43
+ public function getHeaderProductIds()
44
+ {
45
+ if(Mage::getModel('dataexport/config')->isHeadProductIdsEnabled()) {
46
+ return $this->getProductDataString();
47
+ }
48
+
49
+ return "";
50
+ }
51
+
52
+ /**
53
+ * Get product data as a string
54
+ *
55
+ * @return string|FALSE
56
+ */
57
+ public function getProductDataString()
58
+ {
59
+ if(Mage::helper('checkout/cart')->getCart()->getItemsCount() < 1) {
60
+ return FALSE;
61
+ }
62
+
63
+ //$cartHelper = Mage::helper('checkout/cart');
64
+ //$items = $cartHelper->getCart()->getItems();
65
+ //$cart = Mage::helper('checkout/cart')->getCart()->getItemsCount();
66
+ $session = Mage::getSingleton('checkout/session');
67
+ $products = array();
68
+ //$productIds = Mage::getModel('checkout/cart')->getProductIds();
69
+ //return implode(',', $productIds);
70
+
71
+ // getAllItems OR getAllVisibleItems()
72
+ foreach ($session->getQuote()->getAllVisibleItems() as $item) {
73
+ $products[] = $item->getProductId();
74
+ }
75
+
76
+ if( ! empty($products)) {
77
+ //return Mage::helper('core')->encrypt(implode(',', $products));
78
+ $encrypted = $this->encrypt('['.implode(',', $products).']', $this->_initialVector, $this->_secretKey);
79
+ return $encrypted;
80
+ }
81
+
82
+ return FALSE;
83
+ }
84
+
85
+ /**
86
+ * Get product ids from encrypted string
87
+ *
88
+ * @param string
89
+ * @return array|FALSE
90
+ */
91
+ public function getProductIdsFromString($dataString)
92
+ {
93
+ $return = array();
94
+ $productString = $this->decrypt($dataString);
95
+
96
+ if( ! empty($productString)) {
97
+ $return = explode(',', $productString);
98
+ }
99
+
100
+ return $return;
101
+ }
102
+
103
+ function encrypt($message, $initialVector, $secretKey) {
104
+ return base64_encode(
105
+ mcrypt_encrypt(
106
+ MCRYPT_RIJNDAEL_128,
107
+ md5($secretKey),
108
+ $message,
109
+ MCRYPT_MODE_CFB,
110
+ $initialVector
111
+ )
112
+ );
113
+ }
114
+
115
+ function decrypt($message, $initialVector, $secretKey) {
116
+ return mcrypt_decrypt(
117
+ MCRYPT_RIJNDAEL_128,
118
+ md5($secretKey),
119
+ base64_decode($message),
120
+ MCRYPT_MODE_CFB,
121
+ $initialVector
122
+ );
123
+ }
124
+ }
app/code/community/Advertise/Dataexport/Model/Config.php ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Config.php
4
+ *
5
+ * @package Dataexport
6
+ */
7
+ class Advertise_Dataexport_Model_Config extends Varien_Object
8
+ {
9
+ /**
10
+ * Config keys
11
+ */
12
+ const ENABLED = 'dataexport/dataexport_group/enabled';
13
+ const ENABLED_CRON = 'dataexport/dataexport_group/enabled_cron';
14
+ const EXPORT_URL = 'dataexport/dataexport_group/export_url';
15
+ const CUSTOMERS_ENABLED = 'dataexport/dataexport_group/export_customers';
16
+ const ORDERS_ENABLED = 'dataexport/dataexport_group/export_orders';
17
+ const ORDER_STATUS = 'dataexport/dataexport_group/order_status';
18
+ const CARTS_ENABLED = 'dataexport/dataexport_group/export_carts';
19
+ const ADVERTISE_EMAIL = 'advertise_settings/settings/settings_email';
20
+
21
+ // No need for this as use ORDERS_ENABLED for same thing
22
+ //const ENABLE_IDS_HEAD = 'dataexport/dataexport_group/export_productids';
23
+
24
+ /**
25
+ * Is the module enabled?
26
+ *
27
+ * @return bool
28
+ */
29
+ public function getIsEnabled()
30
+ {
31
+ return (bool) Mage::getStoreConfig(self::ENABLED);
32
+ }
33
+
34
+ /**
35
+ * Is the module enabled?
36
+ *
37
+ * @return bool
38
+ */
39
+ public function isCronEnabled()
40
+ {
41
+ return (bool) Mage::getStoreConfig(self::ENABLED_CRON);
42
+ }
43
+
44
+ /**
45
+ * Do we want to output the product ids to the head of the doc?
46
+ *
47
+ * @return bool
48
+ */
49
+ public function isHeadProductIdsEnabled()
50
+ {
51
+ //return (bool) Mage::getStoreConfig(self::ENABLE_IDS_HEAD);
52
+ return (bool) Mage::getStoreConfig(self::ORDERS_ENABLED);
53
+ }
54
+
55
+ /**
56
+ * Customer exportr enabled?
57
+ *
58
+ * @return bool
59
+ */
60
+ public function isCustomerExportEnabled()
61
+ {
62
+ return (bool) Mage::getStoreConfig(self::CUSTOMERS_ENABLED);
63
+ }
64
+
65
+ /**
66
+ * orders exportr enabled?
67
+ *
68
+ * @return bool
69
+ */
70
+ public function isOrderExportEnabled()
71
+ {
72
+ return (bool) Mage::getStoreConfig(self::ORDERS_ENABLED);
73
+ }
74
+
75
+ /**
76
+ * cart exportr enabled?
77
+ *
78
+ * @return bool
79
+ */
80
+ public function isCartExportEnabled()
81
+ {
82
+ return (bool) Mage::getStoreConfig(self::CARTS_ENABLED);
83
+ }
84
+
85
+ /**
86
+ * Get the advertise Email settings.
87
+ *
88
+ * @return string
89
+ */
90
+ public function getAdvertiseEmail()
91
+ {
92
+ return Mage::getStoreConfig(self::ADVERTISE_EMAIL);
93
+ }
94
+
95
+ /**
96
+ * Get the status we want to download products as
97
+ *
98
+ * @return array
99
+ */
100
+ public function getOrderExportStatus()
101
+ {
102
+ $status = Mage::getStoreConfig(self::ORDER_STATUS);
103
+
104
+ return explode(',', $status);
105
+ }
106
+
107
+ /**
108
+ * Get the base url
109
+ *
110
+ * @return string
111
+ */
112
+ public function getBaseUrl()
113
+ {
114
+ return str_replace('http://', '', Mage::getStoreConfig('web/unsecure/base_url'));
115
+ }
116
+
117
+ /**
118
+ * Get export URL
119
+ *
120
+ * @return string
121
+ */
122
+ public function getExportUrl()
123
+ {
124
+ // Hard-coded URL to export data for all stores to
125
+ return 'http://related.adverti.se:8888/servlets/uploadfiles';
126
+
127
+ // Use this version to take export URL from config settings
128
+ //return Mage::getStoreConfig(self::EXPORT_URL);
129
+ }
130
+
131
+ /**
132
+ * GEt a temp folder we'll use to store the exported data.
133
+ *
134
+ * @return string
135
+ */
136
+ public function getTempFolder()
137
+ {
138
+ return Mage::getBaseDir('var') . DS . 'advertisedata';
139
+ }
140
+
141
+ /**
142
+ * Is the temp folder there and writable??
143
+ *
144
+ * @return bool
145
+ */
146
+ public function tempFolderWritable()
147
+ {
148
+ return is_writable($this->getTempFolder());
149
+ }
150
+
151
+ /**
152
+ * Create the temp folder we need
153
+ */
154
+ public function createTempFolder()
155
+ {
156
+ if( ! is_dir($this->getTempFolder())) {
157
+ mkdir($this->getTempFolder(), 0777);
158
+ }
159
+ }
160
+ }
app/code/community/Advertise/Dataexport/Model/Exporter.php ADDED
@@ -0,0 +1,168 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ set_time_limit(0);
3
+ ini_set('memory_limit', '512M');
4
+ //Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
5
+ /**
6
+ * Exporter.php
7
+ *
8
+ * @package Dataexport
9
+ */
10
+ class Advertise_Dataexport_Model_Exporter extends Varien_Object
11
+ {
12
+ /**
13
+ * @var Xmlwriter
14
+ */
15
+ protected $_writer;
16
+ /**
17
+ * @var Advertise_Dataexort_Model_Config
18
+ */
19
+ protected $_config;
20
+ /**
21
+ * Exporters to use
22
+ *
23
+ * @var array
24
+ */
25
+ protected $_exporters = array();
26
+ /**
27
+ * @var string
28
+ */
29
+ protected $_filname;
30
+ /**
31
+ * Remove temp data files after import?
32
+ *
33
+ * @var bool
34
+ */
35
+ protected $_removeTempFiles = FALSE;
36
+
37
+ /**
38
+ * Constructor
39
+ */
40
+ public function __construct()
41
+ {
42
+ parent::__construct();
43
+
44
+ /**
45
+ * @todo change this!!
46
+ */
47
+ $this->_filename = Mage::getModel('dataexport/config')->getTempFolder() . DS . 'generate_' . time() . '.xml';
48
+
49
+ $this->_writer = new Advertise_Dataexport_Model_Xmlwriter($this->_filename);
50
+ $this->_config = Mage::getModel('dataexport/config');
51
+ }
52
+
53
+ /**
54
+ * Do the export! GO GO GO
55
+ *
56
+ * @return void
57
+ */
58
+ public function export()
59
+ {
60
+ $totalItems = 0;
61
+ /**
62
+ * 1) Generate the XML feed as a file
63
+ */
64
+ foreach($this->_getExporters() as $exporter) {
65
+ /* @var $exporter Advertise_Dataexport_Model_Exporter_Interface */
66
+ $totalItems += $exporter->write($this->_getWriter());
67
+ }
68
+ $this->_getWriter()->writeDocument();
69
+ /**
70
+ * 2) Send the feed
71
+ */
72
+ $this->_sendFeed($this->_filename);
73
+ Mage::log('Data export Completed.');
74
+
75
+ return $totalItems;
76
+ }
77
+
78
+ /**
79
+ * Send the feed!
80
+ *
81
+ * @param filename
82
+ */
83
+ protected function _sendFeed($filename)
84
+ {
85
+ if( ! file_exists($filename)) {
86
+ Mage::throwException($this->__('Feed Not Found! ' . $filename));
87
+ }
88
+
89
+ $target = $this->_getConfig()->getExportUrl();
90
+ //$filename = $this->_getConfig()->getTempFolder() . DS . 'test.xml';
91
+ $putFileSize = filesize($filename);
92
+ $putFileHandle = fopen($filename, "r");
93
+
94
+ $adapter = new Zend_Http_Client_Adapter_Curl();
95
+ $client = new Zend_Http_Client($target);
96
+ $client->setAdapter($adapter);
97
+ //$client->setHeaders('Content-Type','text/xml');
98
+
99
+ $adapter->setConfig(array(
100
+ 'curloptions' => array(
101
+ CURLOPT_INFILE => $putFileHandle,
102
+ CURLOPT_INFILESIZE => (string) $putFileSize,
103
+ //CURLOPT_SSL_VERIFYHOST => 0,
104
+ //CURLOPT_SSL_VERIFYPEER => 0,
105
+ )
106
+ ));
107
+
108
+ $response = $client->request(Zend_Http_Client::PUT);
109
+ }
110
+
111
+ /**
112
+ * Add an exporter
113
+ *
114
+ * @param Advertise_Dataexport_Model_Exporter_Interface
115
+ */
116
+ public function addExporter(Advertise_Dataexport_Model_Exporter_Interface $exporter)
117
+ {
118
+ $this->_exporters[] = $exporter;
119
+
120
+ return $this;
121
+ }
122
+
123
+ /**
124
+ * Get our exporters
125
+ *
126
+ * @return array
127
+ */
128
+ protected function _getExporters()
129
+ {
130
+ return $this->_exporters;
131
+ }
132
+
133
+ /**
134
+ * Get all sotre ids
135
+ *
136
+ * @return array
137
+ */
138
+ protected function _getAllStoreIds()
139
+ {
140
+ $allStores = Mage::app()->getStores();
141
+ $ids = array();
142
+ foreach ($allStores as $_eachStoreId => $val) {
143
+ $ids[] = Mage::app()->getStore($_eachStoreId)->getId();
144
+ }
145
+
146
+ return $ids;
147
+ }
148
+
149
+ /**
150
+ * Get the config model
151
+ *
152
+ * @return Advertise_Dataexport_Model_Config
153
+ */
154
+ protected function _getConfig()
155
+ {
156
+ return $this->_config;
157
+ }
158
+
159
+ /**
160
+ * Get the writer
161
+ *
162
+ * @return Xmlwriter
163
+ */
164
+ protected function _getWriter()
165
+ {
166
+ return $this->_writer;
167
+ }
168
+ }
app/code/community/Advertise/Dataexport/Model/Exporter/Cart.php ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Cart.php
4
+ *
5
+ * @package Dataexport
6
+ */
7
+ class Advertise_Dataexport_Model_Exporter_Cart extends Varien_Object implements Advertise_Dataexport_Model_Exporter_Interface
8
+ {
9
+ /**
10
+ * @var string
11
+ */
12
+ protected $_from;
13
+ /**
14
+ * @var string
15
+ */
16
+ protected $_to;
17
+
18
+ /**
19
+ * Get the abandoned carts
20
+ */
21
+ public function getCollection()
22
+ {
23
+ $collection = Mage::getResourceModel('reports/quote_collection');
24
+ $data = array();
25
+ $storeIds = $this->_getAllStoreIds();
26
+
27
+ $collection->prepareForAbandonedReport($storeIds); // $data param can be passed too
28
+
29
+ /**
30
+ * Handle to and from dates!
31
+ */
32
+ if($this->_from || $this->_to) {
33
+ $dateParams = array('date' => true);
34
+ if($this->_from) {
35
+ $dateParams['from'] = date('Y-m-d', strtotime($this->_from));
36
+ }
37
+ if($this->_to) {
38
+ $dateParams['to'] = date('Y-m-d', strtotime($this->_to));
39
+ }
40
+ $collection->addAttributeToFilter('created_at', $dateParams);
41
+ }
42
+
43
+ return $collection;
44
+ }
45
+
46
+ /**
47
+ * Write any items to the given writer
48
+ *
49
+ * @param XMLWriter
50
+ * @return int
51
+ */
52
+ public function write(XMLWriter $writer)
53
+ {
54
+ $writer->startElement('Carts');
55
+ $count = 0;
56
+
57
+ foreach($this->getCollection() as $cart) {
58
+ /* @var $cart Mage_Sales_Model_Quote */
59
+ $data = $cart->toArray();
60
+ $writer->writeArray($data, 'Cart');
61
+ $this->_writeItems($writer, $cart);
62
+ $count++;
63
+ }
64
+
65
+ $writer->endElement(); // Carts
66
+
67
+ return $count;
68
+ }
69
+
70
+ /**
71
+ * Write the queote items.
72
+ *
73
+ * @param Xmlwriter
74
+ * @param Mage_Sales_Model_Quote
75
+ */
76
+ protected function _writeItems($writer, $cart)
77
+ {
78
+ $writer->startElement('QuoteItems');
79
+
80
+ foreach($cart->getItemsCollection() as $item) {
81
+ /* @var $cart Mage_Sales_Model_Quote_Item */
82
+ $data = $item->getData();
83
+ $writer->writeArray($data, 'Item');
84
+ }
85
+
86
+ $writer->endElement(); // OrderItems
87
+ }
88
+
89
+ /**
90
+ * Get all sotre ids
91
+ *
92
+ * @return array
93
+ */
94
+ protected function _getAllStoreIds()
95
+ {
96
+ $allStores = Mage::app()->getStores();
97
+ $ids = array();
98
+ foreach ($allStores as $_eachStoreId => $val) {
99
+ //$_storeCode = Mage::app()->getStore($_eachStoreId)->getCode();
100
+ //$_storeName = Mage::app()->getStore($_eachStoreId)->getName();
101
+ //$_storeId = Mage::app()->getStore($_eachStoreId)->getId();
102
+ $ids[] = Mage::app()->getStore($_eachStoreId)->getId();
103
+ }
104
+
105
+ return $ids;
106
+ }
107
+
108
+ /**
109
+ * Set the date range
110
+ *
111
+ * @param string
112
+ * @param string
113
+ */
114
+ public function setDateRange($from, $to)
115
+ {
116
+ $this->_from = $from;
117
+ $this->_to = $to;
118
+
119
+ return $this;
120
+ }
121
+ }
app/code/community/Advertise/Dataexport/Model/Exporter/Customer.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Customer.php
4
+ *
5
+ * @package Dataexport
6
+ */
7
+ class Advertise_Dataexport_Model_Exporter_Customer extends Varien_Object implements Advertise_Dataexport_Model_Exporter_Interface
8
+ {
9
+ /**
10
+ * Get the collection
11
+ *
12
+ * @return
13
+ */
14
+ public function getCollection()
15
+ {
16
+ $collection = Mage::getModel('customer/customer')
17
+ ->getCollection()
18
+ ->addAttributeToSelect('*')
19
+ ;
20
+
21
+ return $collection;
22
+ }
23
+
24
+ /**
25
+ * Write any items to the given writer
26
+ *
27
+ * @param XMLWriter
28
+ * @return int
29
+ */
30
+ public function write(XMLWriter $writer)
31
+ {
32
+ $writer->startElement('Customers');
33
+ $count = 0;
34
+
35
+ foreach($this->getCollection() as $customer) {
36
+ /* @var $customer Mage_Customer_Model_Customer */
37
+ $data = $customer->toArray();
38
+ $billing = $customer->getDefaultBillingAddress();
39
+ $billing = $billing === FALSE
40
+ ? FALSE
41
+ : $billing->toArray();
42
+
43
+ $shipping = $customer->getDefaultShippingAddress();
44
+ $shipping = $shipping === FALSE
45
+ ? FALSE
46
+ : $shipping->toArray();
47
+
48
+ $data['billing_address'] = $billing;
49
+ $data['shipping_address'] = $shipping;
50
+ $writer->writeArray($data, 'Customer');
51
+ $count++;
52
+ }
53
+
54
+ $writer->endElement(); // Customer
55
+
56
+ return $count;
57
+ }
58
+ }
app/code/community/Advertise/Dataexport/Model/Exporter/Interface.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Interface.php
4
+ *
5
+ * Interface for export "adapters"
6
+ *
7
+ * @package Dataexport
8
+ */
9
+ interface Advertise_Dataexport_Model_Exporter_Interface
10
+ {
11
+ //public function getCollection();
12
+
13
+ /**
14
+ * Write any items to the given writer
15
+ *
16
+ * @param XMLWriter
17
+ * @return int
18
+ */
19
+ public function write(XMLWriter $writer);
20
+
21
+ /**
22
+ * Get the name of the items we're writing in this adpater.
23
+ *
24
+ * @return string
25
+ */
26
+ //public function getObjectName();
27
+ }
app/code/community/Advertise/Dataexport/Model/Exporter/Order.php ADDED
@@ -0,0 +1,177 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Order.php
4
+ *
5
+ * @package Dataexport
6
+ */
7
+ class Advertise_Dataexport_Model_Exporter_Order extends Varien_Object implements Advertise_Dataexport_Model_Exporter_Interface
8
+ {
9
+ /**
10
+ * @var string
11
+ */
12
+ protected $_from;
13
+ /**
14
+ * @var string
15
+ */
16
+ protected $_to;
17
+
18
+ /**
19
+ * Set the date range
20
+ *
21
+ * @param string
22
+ * @param string
23
+ */
24
+ public function setDateRange($from, $to)
25
+ {
26
+ $this->_from = $from;
27
+ $this->_to = $to;
28
+
29
+ return $this;
30
+ }
31
+
32
+ /**
33
+ * Get the orders we need as a collection
34
+ *
35
+ * @param int
36
+ * @return Varien_Data_Collection
37
+ */
38
+ public function getCollection($storeId = NULL)
39
+ {
40
+ //$storeId = Mage::app()->getStore($storeId)->getId();
41
+ $downloadStatus = Mage::getModel('dataexport/config')->getOrderExportStatus(); //array('complete', 'pending');
42
+ $orderCollection = Mage::getResourceModel('sales/order_collection')
43
+ ->addAttributeToSelect('*')
44
+ ->addFieldToFilter('status', array('or' => $downloadStatus))
45
+ //->addFieldToFilter('store_id', array('eq' => $storeId))
46
+ ;
47
+ /**
48
+ * Handle to and from dates!
49
+ */
50
+ if($this->_from || $this->_to) {
51
+ $dateParams = array('date' => true);
52
+ if($this->_from) {
53
+ $dateParams['from'] = date('Y-m-d', strtotime($this->_from));
54
+ }
55
+ if($this->_to) {
56
+ $dateParams['to'] = date('Y-m-d', strtotime($this->_to));
57
+ }
58
+ $orderCollection->addAttributeToFilter('created_at', $dateParams);
59
+ }
60
+
61
+ return $orderCollection;
62
+ }
63
+
64
+ /**
65
+ * Write any items to the given writer
66
+ *
67
+ * @param XMLWriter
68
+ * @return int
69
+ */
70
+ public function write(XMLWriter $writer)
71
+ {
72
+ $writer->startElement('Orders');
73
+ $count = 0;
74
+
75
+ foreach($this->getCollection() as $order) {
76
+ /* @var $order Mage_Sales_Model_Order */
77
+ //$customer = Mage::getModel('customer/customer')->load($order->getCustomerId());
78
+ /*$data = array(
79
+ 'Id' => $order->getCustomerId(),
80
+ 'CompanyName' => $order->getBillingAddress()->getCompany(),
81
+ 'CustomerInvoiceAddress' => $this->_getConvertedAddress($order->getBillingAddress()),
82
+ 'CustomerDeliveryAddress' => $this->_getConvertedAddress($order->getShippingAddress()),
83
+ );*/
84
+ $data = $order->toArray();
85
+ $writer->writeArray($data, 'Order');
86
+ $this->_writeOrderItems($writer, $order);
87
+ $count++;
88
+ }
89
+
90
+ $writer->endElement(); // Order
91
+
92
+ return $count;
93
+ }
94
+
95
+ /**
96
+ * Convert the address from Magento format to an array we need
97
+ *
98
+ * @param Mage_Sales_Model_Order_Address $address
99
+ * @return array
100
+ */
101
+ protected function _getConvertedAddress(Mage_Sales_Model_Order_Address $address)
102
+ {
103
+ $company = $address->getCompany();
104
+ $company = ! empty($company)
105
+ ? $address->getCompany()
106
+ : $address->getFirstname() . ' ' . $address->getLastname();
107
+
108
+ return array(
109
+ 'Id' => $address->getId(),
110
+ 'Title' => $address->getPrefix(),
111
+ 'Forename' => $address->getFirstname(),
112
+ 'Surname' => $address->getLastname(),
113
+ 'Company' => $company,
114
+ 'Address1' => $address->getStreet1(),
115
+ 'Address2' => $address->getStreet2(),
116
+ 'Town' => $address->getCity(),
117
+ 'County' => $address->getRegion(),
118
+ 'Country' => $address->getData('country_id'), //getCountry()?
119
+ 'Postcode' => $address->getPostcode(),
120
+ 'Email' => $address->getCustomerEmail(),
121
+ 'Telephone' => $address->getTelephone(),
122
+ );
123
+ }
124
+
125
+ /**
126
+ * Write iterms out too
127
+ *
128
+ * @param XmlWriter
129
+ * @param Mage_Core_Sales_Order
130
+ */
131
+ protected function _writeOrderItems($writer, $order)
132
+ {
133
+ $writer->startElement('OrderItems');
134
+ //foreach($order->getItemsCollection() as $item) {
135
+ foreach($order->getAllVisibleItems() as $item) {
136
+ //$totalNet = $item->getQtyOrdered() * $item->getPrice(); // basePrice breaks with multi-currency
137
+ //$to = Varien_Object_Mapper::accumulateByMap($from, $to, $map); // example mapper
138
+ /*$data = array(
139
+ 'Id' => $item->getId(),
140
+ 'Sku' => $this->_getItemSkuCode($item),
141
+ 'Name' => $item->getName(),
142
+ 'QtyOrdered' => $item->getQtyOrdered(),
143
+ 'TaxRate' => $item->getData('tax_percent'),
144
+ 'UnitPrice' => $item->getPrice(),
145
+ 'UnitDiscountAmount' => $item->getData('discount_amount'),
146
+ 'UnitDiscountPercentage'=> $item->getData('discount_percent'),
147
+ );*/
148
+
149
+ $data = $item->getData();
150
+ $writer->writeArray($data, 'Item');
151
+ }
152
+ $writer->endElement(); // OrderItems
153
+ }
154
+
155
+ /**
156
+ * Get the Sku code to use for a particular item.
157
+ * If we are using bundles / configurable items we need to search
158
+ * because by default we get the parents Sku...
159
+ *
160
+ * @param Mage_Sales_Model_Order_Item
161
+ * @return string
162
+ */
163
+ protected function _getItemSkuCode($item)
164
+ {
165
+ /**
166
+ * Use Child SKU if it's a configurable product..etc
167
+ */
168
+ if($options = $item->getData('product_options')) {
169
+ $optionsData = unserialize($options);
170
+ if(isset($optionsData['simple_sku'])) {
171
+ return $optionsData['simple_sku'];
172
+ }
173
+ }
174
+
175
+ return $item->getSku();
176
+ }
177
+ }
app/code/community/Advertise/Dataexport/Model/Modelname.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Advertise_Dataexport_Model_Modelname extends Mage_Core_Model_Abstract
4
+ {
5
+ protected function _construct(){
6
+
7
+ $this->_init("dataexport/modelname");
8
+
9
+ }
10
+
11
+ }
12
+
app/code/community/Advertise/Dataexport/Model/Mysql4/Modelname.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Advertise_Dataexport_Model_Mysql4_Modelname extends Mage_Core_Model_Mysql4_Abstract
3
+ {
4
+ protected function _construct()
5
+ {
6
+ $this->_init("dataexport/modelname", "tablename_id");
7
+ }
8
+ }
9
+
app/code/community/Advertise/Dataexport/Model/Mysql4/Modelname/Collection.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Advertise_Dataexport_Model_Mysql4_Modelname_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
3
+ {
4
+
5
+ public function _construct(){
6
+ $this->_init("dataexport/modelname");
7
+ }
8
+ }
9
+
app/code/community/Advertise/Dataexport/Model/Orderstatus.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Orderstatus.php
4
+ *
5
+ * @package dataexport
6
+ */
7
+ class Advertise_Dataexport_Model_Orderstatus
8
+ {
9
+ /**
10
+ * Options getter
11
+ *
12
+ * @return array
13
+ */
14
+ public function toOptionArray()
15
+ {
16
+ $collection = Mage::getResourceModel('sales/order_status_collection');
17
+ return $collection->toOptionArray();
18
+ }
19
+ }
app/code/community/Advertise/Dataexport/Model/Scheduler.php ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ set_time_limit(0);
3
+ ini_set('memory_limit', '512M');
4
+ Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
5
+ /**
6
+ * Scheduler.php
7
+ *
8
+ * @package Dataexport
9
+ */
10
+ class Advertise_Dataexport_Model_Scheduler extends Varien_Object
11
+ {
12
+ /**
13
+ * Lets do this!
14
+ */
15
+ public static function export()
16
+ {
17
+ $config = Mage::getModel('dataexport/config');
18
+
19
+ if( ! ($config->getIsEnabled() && $config->isCronEnabled())) {
20
+ return;
21
+ //Mage::throwException($this->__('Module Disabled!'));
22
+ }
23
+
24
+ try {
25
+ //$post = $this->getRequest()->getPost();
26
+ $exporter = Mage::getModel('dataexport/exporter');
27
+ /* @var $exporter Advertise_Dataexport_Model_Exporter */
28
+ /**
29
+ * Add Order Export
30
+ */
31
+ if($config->isOrderExportEnabled()) {
32
+ //$toDate = $this->getRequest()->getParam('date_to', NULL);
33
+ //$fromDate = $this->getRequest()->getParam('date_from', NULL);
34
+
35
+ $exportAdapter = Mage::getModel('dataexport/exporter_order');
36
+ //$exportAdapter->setDateRange($fromDate, $toDate);
37
+ $exporter->addExporter($exportAdapter);
38
+ }
39
+ /**
40
+ * Add Customer Export
41
+ */
42
+ if($config->isCustomerExportEnabled()) {
43
+ $exportAdapter = Mage::getModel('dataexport/exporter_customer');
44
+ $exporter->addExporter($exportAdapter);
45
+ }
46
+ /**
47
+ * Add Cart Export
48
+ */
49
+ if($config->isCartExportEnabled()) {
50
+ $exportAdapter = Mage::getModel('dataexport/exporter_cart');
51
+ $exporter->addExporter($exportAdapter);
52
+ }
53
+
54
+ /**
55
+ * Do it!
56
+ */
57
+ $totalItems = $exporter->export();
58
+
59
+ $message = $this->__('Your form has been submitted successfully.');
60
+ Mage::getSingleton('adminhtml/session')->addSuccess($message);
61
+ Mage::getSingleton('adminhtml/session')->addSuccess("{$totalItems} Items successfully Exported.");
62
+ }
63
+ catch (Exception $e) {
64
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
65
+ }
66
+ }
67
+ }
app/code/community/Advertise/Dataexport/Model/Xmlwriter.php ADDED
@@ -0,0 +1,209 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Xmlwriter.php
4
+ *
5
+ * Extension to PHPs native XML Writer.
6
+ * We are writing directly to the output buffer every X elements.
7
+ * We are only counting Objects or Arrays in the flush count as "elements"
8
+ *
9
+ * We are currently using the MemoryBuffer, but we could use
10
+ * direct output if we wanted, maybe tinker with this in the future:
11
+ * out->openURI('php://output')
12
+ * We are using memorybuffers as it's easier to change to file writing
13
+ * for debug/loggin.
14
+ *
15
+ * @package Dataexport
16
+ */
17
+ class Advertise_Dataexport_Model_Xmlwriter extends XMLWriter
18
+ {
19
+ /**
20
+ * Number of entries before each flush
21
+ * @var int
22
+ */
23
+ protected $_flushAfter = 20;
24
+ /**
25
+ * Keep count of written elements before we flush
26
+ * @var int
27
+ */
28
+ protected $_flushCount = 0;
29
+ /**
30
+ * Enable flushing buffer? If we disable
31
+ * we won't write the buffer until the end!
32
+ * @var bool
33
+ */
34
+ protected $_flushEnabled = TRUE;
35
+ /**
36
+ * Name of our root element
37
+ * @var string
38
+ */
39
+ protected $_rootElement = 'Advertise';
40
+ /**
41
+ * filename
42
+ * @var string
43
+ */
44
+ protected $_filename;
45
+
46
+ /**
47
+ * Constructor
48
+ *
49
+ * @param string
50
+ */
51
+ public function __construct($filename)
52
+ {
53
+ $this->_filename = $filename;
54
+
55
+ $this->openMemory();
56
+ //$this->openURI($this->_getFilename());
57
+ $this->startDocument('1.0', 'UTF-8');
58
+ /** only indent in development mode **/
59
+ if(Mage::getIsDeveloperMode()) {
60
+ $this->setIndent(TRUE);
61
+ $this->setIndentString(' ');
62
+ }
63
+ else {
64
+ $this->setIndent(FALSE);
65
+ }
66
+ $this->startElement($this->_rootElement);
67
+ }
68
+
69
+ /**
70
+ * Get the filename we'll use
71
+ *
72
+ * @return string
73
+ */
74
+ protected function _getFilename()
75
+ {
76
+ //if($this->_filename === NULL) {
77
+ // generate??
78
+ //}
79
+
80
+ return $this->_filename;
81
+ }
82
+
83
+ /**
84
+ * Set the filename to use
85
+ *
86
+ * @param string
87
+ */
88
+ public function setFilename($filename)
89
+ {
90
+ $this->_filename = $filename;
91
+
92
+ return $this;
93
+ }
94
+
95
+ /**
96
+ * Write a collection to the XML stream
97
+ *
98
+ * @param Varien_Data_Collection
99
+ * @param string node name
100
+ * @return $this
101
+ */
102
+ public function writeCollection(Varien_Data_Collection $collection, $nodeName)
103
+ {
104
+ $this->startElement($nodeName);
105
+ foreach($collection as $item) {
106
+ $this->writeObject($item, $this->_getSingularName($nodeName));
107
+ }
108
+ $this->endElement();
109
+
110
+ return $this;
111
+ }
112
+
113
+ /**
114
+ * Just an alias to save me hunting through the code and changing
115
+ * references to write array.. lazy
116
+ *
117
+ * @param mixed
118
+ * @param string
119
+ */
120
+ public function writeArray($item, $nodeName = NULL)
121
+ {
122
+ $this->writeObject($item, $nodeName);
123
+ }
124
+
125
+ /**
126
+ * Recursive function to replace the garbage above..
127
+ *
128
+ * @param mixed
129
+ * @param string
130
+ */
131
+ public function writeObject($item, $nodeName = NULL)
132
+ {
133
+ if(isset($nodeName)) {
134
+ $this->startElement($nodeName);
135
+ }
136
+ /** Array **/
137
+ if(is_array($item)) {
138
+ foreach($item as $field => $val) {
139
+ $this->writeObject($val, $field);
140
+ }
141
+ }
142
+ /** Object */
143
+ elseif($item instanceof Varien_Object) {
144
+ foreach($item->getData() as $field => $val) {
145
+ $this->writeObject($val, $field);
146
+ }
147
+ }
148
+ /** collection **/
149
+ elseif($item instanceof Varien_Data_Collection) {
150
+
151
+ }
152
+ /** node **/
153
+ else {
154
+ $this->text((string) $item);
155
+ }
156
+
157
+ if(isset($nodeName)) {
158
+ $this->endElement();
159
+ }
160
+ $this->_doFlush();
161
+
162
+ return $this;
163
+ }
164
+
165
+ /**
166
+ * Generate the Xml document
167
+ */
168
+ public function writeDocument()
169
+ {
170
+ $this->endElement();
171
+ $this->endDocument();
172
+
173
+ //return $this->outputMemory();
174
+
175
+ /**
176
+ * @todo if Writing to file:
177
+ */
178
+ file_put_contents($this->_getFilename(), $this->flush(true), FILE_APPEND);
179
+ //return $this->flush();
180
+ }
181
+
182
+ /**
183
+ * Check if we need to flush, if we do then
184
+ * let's do it!
185
+ */
186
+ protected function _doFlush()
187
+ {
188
+ if($this->_flushEnabled && $this->_flushCount >= $this->_flushAfter) {
189
+ //echo $this->outputMemory();
190
+ file_put_contents($this->_getFilename(), $this->flush(true), FILE_APPEND);
191
+ $this->_flushCount = 0;
192
+ }
193
+
194
+ $this->_flushCount++;
195
+ }
196
+
197
+ /**
198
+ * Get the singular version of a collection
199
+ * eg. Customers will return Customer
200
+ *
201
+ * @param string $name
202
+ * @return string - singlular name
203
+ */
204
+ protected function _getSingularName($name)
205
+ {
206
+ /** not handle irregular names yet.. **/
207
+ return rtrim($name, 's');
208
+ }
209
+ }
app/code/community/Advertise/Dataexport/controllers/Adminhtml/DataexportbackendController.php ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * DataexportbackendController.php
4
+ */
5
+ class Advertise_Dataexport_Adminhtml_DataexportbackendController extends Mage_Adminhtml_Controller_Action
6
+ {
7
+ /**
8
+ * index action
9
+ */
10
+ public function indexAction()
11
+ {
12
+ $this->loadLayout();
13
+ $this->_title($this->__("Adverti.se Retail Intelligence"));
14
+ $this->renderLayout();
15
+ }
16
+
17
+ /**
18
+ * Run the export
19
+ */
20
+ public function exportAction()
21
+ {
22
+ $config = Mage::getModel('dataexport/config');
23
+
24
+ if( ! $config->getIsEnabled()) {
25
+ Mage::throwException($this->__('Module Disabled!'));
26
+ }
27
+
28
+ if($this->getRequest()->isPost()) {
29
+ try {
30
+ //$post = $this->getRequest()->getPost();
31
+ $exporter = Mage::getModel('dataexport/exporter');
32
+ /* @var $exporter Advertise_Dataexport_Model_Exporter */
33
+ /**
34
+ * Add Order Export
35
+ */
36
+ if($config->isOrderExportEnabled()) {
37
+ $toDate = $this->getRequest()->getParam('date_to', NULL);
38
+ $fromDate = $this->getRequest()->getParam('date_from', NULL);
39
+
40
+ $exportAdapter = Mage::getModel('dataexport/exporter_order');
41
+ $exportAdapter->setDateRange($fromDate, $toDate);
42
+ $exporter->addExporter($exportAdapter);
43
+ }
44
+ /**
45
+ * Add Customer Export
46
+ */
47
+ if($config->isCustomerExportEnabled()) {
48
+ $exportAdapter = Mage::getModel('dataexport/exporter_customer');
49
+ $exporter->addExporter($exportAdapter);
50
+ }
51
+ /**
52
+ * Add Cart Export
53
+ */
54
+ if($config->isCartExportEnabled()) {
55
+ $exportAdapter = Mage::getModel('dataexport/exporter_cart');
56
+ $exporter->addExporter($exportAdapter);
57
+ }
58
+
59
+ /**
60
+ * Do it!
61
+ */
62
+ $totalItems = $exporter->export();
63
+
64
+ $message = $this->__('Your form has been submitted successfully.');
65
+ Mage::getSingleton('adminhtml/session')->addSuccess($message);
66
+ Mage::getSingleton('adminhtml/session')->addSuccess("{$totalItems} Items successfully Exported.");
67
+ }
68
+ catch (Exception $e) {
69
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
70
+ }
71
+
72
+ $this->_redirect('*/*');
73
+ }
74
+ else {
75
+ Mage::throwException($this->__('Invalid form data.'));
76
+ }
77
+ }
78
+ }
app/code/community/Advertise/Dataexport/controllers/IndexController.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * IndexController.php
4
+ */
5
+ class Advertise_Dataexport_IndexController extends Mage_Core_Controller_Front_Action
6
+ {
7
+ /**
8
+ * index action
9
+ */
10
+ public function indexAction()
11
+ {
12
+ exit;
13
+ }
14
+
15
+ /**
16
+ * We will post data here as a test.
17
+ * We can juust log it!
18
+ */
19
+ public function debugAction()
20
+ {
21
+ $config = Mage::getModel('dataexport/config');
22
+ $post = file_get_contents('php://input');
23
+
24
+ //echo $post;
25
+
26
+ if(empty($post)) {
27
+ die('nothing to do.');
28
+ }
29
+
30
+ if( !is_dir($config->getTempFolder())) {
31
+ mkdir($config->getTempFolder(), 0777);
32
+ }
33
+
34
+ $filename = $config->getTempFolder() . DS . 'debug_' . time() . '.xml';
35
+ if( ! file_put_contents($filename, $post)) {
36
+ Mage::log('Error writing debug file: ' . $filename);
37
+ }
38
+
39
+ unset($post);
40
+ }
41
+ }
app/code/community/Advertise/Dataexport/controllers/TestController.php ADDED
@@ -0,0 +1,238 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * IndexController.php
4
+ */
5
+ class Advertise_Dataexport_TestController extends Mage_Core_Controller_Front_Action
6
+ {
7
+ /**
8
+ * Predispatch: should set layout area
9
+ *
10
+ * @return Mage_Core_Controller_Front_Action
11
+ */
12
+ public function preDispatch()
13
+ {
14
+ if( ! Mage::getIsDeveloperMode()) {
15
+ die('no access.');
16
+ }
17
+
18
+ parent::preDispatch();
19
+
20
+ return $this;
21
+ }
22
+
23
+ /**
24
+ * Test product string
25
+ */
26
+ public function stringAction()
27
+ {
28
+ // shortcut method, to be used inside a template
29
+ echo Mage::helper('advertise_relatedproducts')->getHeaderProductIds();
30
+
31
+ // output encoded string
32
+ $string = Mage::helper('advertise_relatedproducts')->getProductDataString();
33
+ echo $string . "<br />";
34
+
35
+ // get back the value we want
36
+ var_dump(Mage::helper('advertise_relatedproducts')->getProductIdsFromString($string));
37
+ }
38
+
39
+ /**
40
+ * index action
41
+ */
42
+ public function indexAction()
43
+ {
44
+ try {
45
+ //$target = 'http://www.google.com/';
46
+ $config = Mage::getModel('dataexport/config');
47
+ $target = $config->getExportUrl();
48
+ $adapter = new Zend_Http_Client_Adapter_Curl();
49
+ $client = new Zend_Http_Client($target);
50
+ $client->setAdapter($adapter);
51
+
52
+ $adapter->setConfig(array(
53
+ 'timeout' => 60,
54
+ 'curloptions' => array(
55
+ CURLOPT_SSL_VERIFYHOST => 0,
56
+ CURLOPT_SSL_VERIFYPEER => 0,
57
+ CURLOPT_TIMEOUT => 60,
58
+ //CURLOPT_ENCODING => 'gzip',
59
+ //CURLOPT_CONNECTTIMEOUT => 60,
60
+ //CURLOPT_POSTFIELDS => 'data',
61
+ //CURLOPT_FOLLOWLOCATION => true
62
+ //CURLOPT_INFILE => $putFileHandle,
63
+ //CURLOPT_INFILESIZE => $putFileSize
64
+ )
65
+ ));
66
+ //$client->setParameterPost('name', 'value');
67
+ $client->setHeaders('Content-Type','text/xml');
68
+ $client->setRawData('THIS IS A TEST!', 'text/xml');
69
+
70
+ $response = $client->request(Zend_Http_Client::POST);
71
+ //echo $client->read();
72
+ echo $response->getBody();
73
+ }
74
+ catch(Exception $e) {
75
+ $debug['http_error'] = array(
76
+ 'error' => $e->getMessage(),
77
+ 'code' => $e->getCode()
78
+ );
79
+ var_dump($debug);
80
+ //throw $e;
81
+ }
82
+ exit;
83
+ }
84
+
85
+ /**
86
+ * Test sending a file.
87
+ */
88
+ public function sendFileAction()
89
+ {
90
+ $config = Mage::getModel('dataexport/config');
91
+ $target = $config->getExportUrl();
92
+
93
+ $filename = $config->getTempFolder() . DS . 'test.xml';
94
+
95
+ $putFileSize = filesize($filename);
96
+ $putFileHandle = fopen($filename, "r");
97
+
98
+ $adapter = new Zend_Http_Client_Adapter_Curl();
99
+ $client = new Zend_Http_Client($target);
100
+ $client->setAdapter($adapter);
101
+
102
+ $adapter->setConfig(array(
103
+ 'curloptions' => array(
104
+ CURLOPT_INFILE => $putFileHandle,
105
+ CURLOPT_INFILESIZE => (string) $putFileSize,
106
+ //CURLOPT_SSL_VERIFYHOST => 0,
107
+ //CURLOPT_SSL_VERIFYPEER => 0,
108
+ )
109
+ ));
110
+
111
+ $response = $client->request(Zend_Http_Client::PUT);
112
+ //echo $response->getBody();
113
+
114
+ //$client->request("PUT");
115
+ }
116
+
117
+ /**
118
+ * Test the customer feed
119
+ */
120
+ public function customerAction()
121
+ {
122
+ $collection = Mage::getModel('customer/customer')
123
+ ->getCollection()
124
+ ->addAttributeToSelect('*')
125
+ ;
126
+
127
+ $result = array();
128
+
129
+ foreach ($collection as $customer) {
130
+ /* @var $customer Mage_Customer_Model_Customer */
131
+ $data = $customer->toArray();
132
+ $data['billing_address'] = $customer->getDefaultBillingAddress()->toArray();
133
+ $data['shipping_address'] = $customer->getDefaultShippingAddress()->toArray();
134
+ $result[] = $data;
135
+ }
136
+
137
+ var_dump($result);
138
+ }
139
+
140
+ /**
141
+ * Test getting order feed.
142
+ */
143
+ public function orderAction()
144
+ {
145
+ //$post = $this->getRequest()->getPost();
146
+ $exporter = Mage::getModel('dataexport/exporter');
147
+ /* @var $exporter Advertise_Dataexport_Model_Exporter */
148
+
149
+ $toDate = $this->getRequest()->getParam('date_to', NULL);
150
+ $fromDate = $this->getRequest()->getParam('date_from', NULL);
151
+
152
+ $exportAdapter = Mage::getModel('dataexport/exporter_order');
153
+ $exportAdapter->setDateRange($fromDate, $toDate);
154
+ $exporter->addExporter($exportAdapter);
155
+
156
+ /**
157
+ * Do it!
158
+ */
159
+ $totalItems = $exporter->export();
160
+ }
161
+
162
+ /**
163
+ * Get the orders we need as a collection
164
+ *
165
+ * @param int
166
+ * @return Varien_Data_Collection
167
+ */
168
+ protected function _getOrderCollection($storeId = NULL)
169
+ {
170
+ $storeId = Mage::app()->getStore($storeId)->getId();
171
+ $downloadStatus = Mage::getModel('dataexport/config')->getOrderExportStatus(); //array('complete', 'pending');
172
+ $orderCollection = Mage::getResourceModel('sales/order_collection')
173
+ ->addAttributeToSelect('*')
174
+ ->addFieldToFilter('status', array('or' => $downloadStatus))
175
+ ->addFieldToFilter('store_id', array('eq' => $storeId))
176
+ ;
177
+ /**
178
+ * Handle to and from dates
179
+ * @todo refactor away from here...
180
+ */
181
+ $fromDate = $this->getRequest()->getParam('from', FALSE);
182
+ $toDate = $this->getRequest()->getParam('to', FALSE);
183
+ if($fromDate || $toDate) {
184
+ $dateParams = array('date' => true);
185
+ if($fromDate) {
186
+ $dateParams['from'] = date('Y-m-d', strtotime($fromDate));
187
+ }
188
+ if($toDate) {
189
+ $dateParams['to'] = date('Y-m-d', strtotime($toDate));
190
+ }
191
+ $orderCollection->addAttributeToFilter('created_at', $dateParams);
192
+ }
193
+
194
+ return $orderCollection;
195
+ }
196
+
197
+ /**
198
+ * List abandoned carts!
199
+ */
200
+ public function cartAction()
201
+ {
202
+ $collection = Mage::getResourceModel('reports/quote_collection');
203
+ $data = array();
204
+ $storeIds = $this->_getAllStoreIds();
205
+
206
+ if (!empty($data)) {
207
+ $collection->prepareForAbandonedReport($storeIds, $data);
208
+ } else {
209
+ $collection->prepareForAbandonedReport($storeIds);
210
+ }
211
+
212
+ foreach($collection as $cart) {
213
+ /* @var $cart Mage_Sales_Model_Quote */
214
+ $cart->getItemsCollection();
215
+
216
+ var_dump($cart->getData());
217
+ }
218
+ }
219
+
220
+ /**
221
+ * Get all sotre ids
222
+ *
223
+ * @return array
224
+ */
225
+ protected function _getAllStoreIds()
226
+ {
227
+ $allStores = Mage::app()->getStores();
228
+ $ids = array();
229
+ foreach ($allStores as $_eachStoreId => $val) {
230
+ //$_storeCode = Mage::app()->getStore($_eachStoreId)->getCode();
231
+ //$_storeName = Mage::app()->getStore($_eachStoreId)->getName();
232
+ //$_storeId = Mage::app()->getStore($_eachStoreId)->getId();
233
+ $ids[] = Mage::app()->getStore($_eachStoreId)->getId();
234
+ }
235
+
236
+ return $ids;
237
+ }
238
+ }
app/code/community/Advertise/Dataexport/etc/adminhtml.xml ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+
3
+ <config>
4
+ <menu>
5
+ <catalog>
6
+ <children>
7
+ <!-- Add Adverti.se to 'Catalog' top menu -->
8
+ <advertise_menu translate="title">
9
+ <title>Adverti.se</title>
10
+ <sort_order>199</sort_order>
11
+ <!-- Add Retail Intelligence to Adverti.se sub-menu -->
12
+ <children>
13
+ <advertise_retailintelligence translate="title" module="dataexport">
14
+ <title>Retail Intelligence</title>
15
+ <sort_order>2</sort_order>
16
+ <action>dataexport/adminhtml_dataexportbackend</action>
17
+ </advertise_retailintelligence>
18
+ </children>
19
+ </advertise_menu>
20
+ </children>
21
+ </catalog>
22
+ </menu>
23
+ <acl>
24
+ <resources>
25
+ <admin>
26
+ <children>
27
+ <catalog>
28
+ <children>
29
+ <advertise_menu translate="title">
30
+ <title>Adverti.se</title>
31
+ <children>
32
+ <advertise_retailintelligence translate="title" module="dataexport">
33
+ <title>Retail Intelligence</title>
34
+ </advertise_retailintelligence>
35
+ </children>
36
+ </advertise_menu>
37
+ </children>
38
+ </catalog>
39
+ </children>
40
+ </admin>
41
+ </resources>
42
+ </acl>
43
+ </config>
app/code/community/Advertise/Dataexport/etc/config.xml ADDED
@@ -0,0 +1,189 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Advertise_Dataexport>
5
+ <version>0.1.0</version>
6
+ </Advertise_Dataexport>
7
+ </modules>
8
+
9
+ <frontend>
10
+ <routers>
11
+ <dataexport>
12
+ <use>standard</use>
13
+ <args>
14
+ <module>Advertise_Dataexport</module>
15
+ <frontName>dataexport</frontName>
16
+ </args>
17
+ </dataexport>
18
+ </routers>
19
+ <layout>
20
+ <updates>
21
+ <dataexport>
22
+ <file>dataexport.xml</file>
23
+ </dataexport>
24
+ </updates>
25
+ </layout>
26
+ </frontend>
27
+ <global>
28
+ <helpers>
29
+ <dataexport>
30
+ <class>Advertise_Dataexport_Helper</class>
31
+ </dataexport>
32
+ <advertise_retailintelligence>
33
+ <class>Advertise_Dataexport_Helper</class>
34
+ </advertise_retailintelligence>
35
+ </helpers>
36
+ <blocks>
37
+ <dataexport>
38
+ <class>Advertise_Dataexport_Block</class>
39
+ </dataexport>
40
+ </blocks>
41
+ <models>
42
+ <dataexport>
43
+ <class>Advertise_Dataexport_Model</class>
44
+ <resourceModel>dataexport_mysql4</resourceModel>
45
+ </dataexport>
46
+ <dataexport_mysql4>
47
+ <class>Advertise_Dataexport_Model_Mysql4</class>
48
+ <entities>
49
+ <modelname>
50
+ <table>tablename</table>
51
+ </modelname>
52
+ </entities>
53
+ </dataexport_mysql4>
54
+ </models>
55
+ <resources>
56
+ <dataexport_setup>
57
+ <setup>
58
+ <module>Advertise_Dataexport</module>
59
+ </setup>
60
+ <connection>
61
+ <use>core_setup</use>
62
+ </connection>
63
+ </dataexport_setup>
64
+ <dataexport_write>
65
+ <connection>
66
+ <use>core_write</use>
67
+ </connection>
68
+ </dataexport_write>
69
+ <dataexport_read>
70
+ <connection>
71
+ <use>core_read</use>
72
+ </connection>
73
+ </dataexport_read>
74
+ </resources>
75
+ <!-- events -->
76
+ <!-- <events>
77
+ <advertise_export_event>
78
+ <observers>
79
+ <advertise_export_observer>
80
+ <type>singleton</type>
81
+ <class>dataexport/observer</class>
82
+ <method>something</method>
83
+ </advertise_export_observer>
84
+ </observers>
85
+ </advertise_export_event>
86
+ </events>
87
+ -->
88
+ </global>
89
+ <admin>
90
+ <routers>
91
+ <dataexport>
92
+ <use>admin</use>
93
+ <args>
94
+ <module>Advertise_Dataexport</module>
95
+ <frontName>dataexport</frontName>
96
+ </args>
97
+ </dataexport>
98
+ </routers>
99
+ </admin>
100
+ <adminhtml>
101
+ <!-- REMOVE EXTRA MENU ITEM
102
+ <menu>
103
+ <dataexport module="dataexport">
104
+ <title>Advertise Data Export</title>
105
+ <sort_order>100</sort_order>
106
+ <children>
107
+ <dataexportbackend module="dataexport">
108
+ <title>Export Data</title>
109
+ <sort_order>0</sort_order>
110
+ <action>dataexport/adminhtml_dataexportbackend</action>
111
+ </dataexportbackend>
112
+ </children>
113
+ </dataexport>
114
+ </menu>
115
+ -->
116
+
117
+ <!-- acl -->
118
+ <acl>
119
+ <resources>
120
+ <all>
121
+ <title>Allow Everything</title>
122
+ </all>
123
+ <admin>
124
+ <children>
125
+ <!--
126
+ <dataexport translate="title" module="dataexport">
127
+ <title>Dataexport</title>
128
+ <sort_order>1000</sort_order>
129
+ <children>
130
+ <dataexportbackend translate="title">
131
+ <title>Data Export</title>
132
+ </dataexportbackend>
133
+ </children>
134
+ </dataexport>
135
+ -->
136
+ <system>
137
+ <children>
138
+ <config>
139
+ <children>
140
+ <dataexport>
141
+ <title>Data Export Module</title>
142
+ </dataexport>
143
+ </children>
144
+ </config>
145
+ </children>
146
+ </system>
147
+ </children>
148
+ </admin>
149
+ </resources>
150
+ </acl>
151
+
152
+ <layout>
153
+ <updates>
154
+ <dataexport>
155
+ <file>dataexport.xml</file>
156
+ </dataexport>
157
+ </updates>
158
+ </layout>
159
+ </adminhtml>
160
+ <!-- cron jobs -->
161
+ <crontab>
162
+ <jobs>
163
+ <advertise_dataexport>
164
+ <schedule>
165
+ <!--<cron_expr>0,15,30,45 * * * *</cron_expr>-->
166
+ <cron_expr>0 0 * * *</cron_expr><!-- each day at midnight! -->
167
+ </schedule>
168
+ <run>
169
+ <model>dataexport/Scheduler::export</model>
170
+ </run>
171
+ </advertise_dataexport>
172
+ </jobs>
173
+ </crontab>
174
+ <!-- defaults -->
175
+ <default>
176
+ <dataexport><!-- section -->
177
+ <dataexport_group><!-- group -->
178
+ <enabled>1</enabled>
179
+ <enabled_cron>0</enabled_cron>
180
+ <enable_gzip>0</enable_gzip>
181
+ <export_carts>1</export_carts>
182
+ <export_orders>1</export_orders>
183
+ <order_status>complete</order_status>
184
+ <export_customers>1</export_customers>
185
+ <export_url></export_url>
186
+ </dataexport_group>
187
+ </dataexport>
188
+ </default>
189
+ </config>
app/code/community/Advertise/Dataexport/etc/system.xml ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <!-- This Adverti.se tab is used by all Adverti.se extensions for config menu!
4
+ So if you change it then need to change in ALL extensions! -->
5
+
6
+ <!-- Top Level Tab -->
7
+ <tabs>
8
+ <Advertise translate="label">
9
+ <label>Advertise</label>
10
+ <sort_order>405</sort_order>
11
+ </Advertise>
12
+ </tabs>
13
+
14
+ <!-- Sections under Adverti.se tab -->
15
+ <sections>
16
+ <dataexport translate="label" module="dataexport">
17
+ <tab>Advertise</tab>
18
+ <label>Retail Intelligence</label>
19
+ <frontend_type>text</frontend_type>
20
+ <sort_order>500</sort_order>
21
+ <show_in_default>1</show_in_default>
22
+ <show_in_website>1</show_in_website>
23
+ <show_in_store>1</show_in_store>
24
+ <groups>
25
+ <dataexport_group translate="label">
26
+ <label>Retail Intelligence Options</label>
27
+ <frontend_type>text</frontend_type>
28
+ <sort_order>1</sort_order>
29
+ <show_in_default>1</show_in_default>
30
+ <show_in_website>1</show_in_website>
31
+ <show_in_store>1</show_in_store>
32
+ <fields>
33
+ <enabled translate="label">
34
+ <label>Enable Retail Intelligence</label>
35
+ <frontend_type>select</frontend_type>
36
+ <sort_order>1</sort_order>
37
+ <show_in_default>1</show_in_default>
38
+ <show_in_website>1</show_in_website>
39
+ <show_in_store>1</show_in_store>
40
+ <source_model>adminhtml/system_config_source_yesno</source_model>
41
+ <comment>Retail Intelligence needs to be enabled for Adverti.se Related, Upsell and Cross-Sell Product modules.</comment>
42
+ </enabled>
43
+ <enabled_cron translate="label">
44
+ <label>Enable Scheduled Exports</label>
45
+ <frontend_type>select</frontend_type>
46
+ <sort_order>2</sort_order>
47
+ <show_in_default>1</show_in_default>
48
+ <show_in_website>1</show_in_website>
49
+ <show_in_store>1</show_in_store>
50
+ <source_model>adminhtml/system_config_source_yesno</source_model>
51
+ <comment>Scheduled exports help us to keep your Related, Upsell and Cross-Sell products fresh.</comment>
52
+ </enabled_cron>
53
+ <!--
54
+ <enable_gzip translate="label">
55
+ <label>Enable GZip Compression</label>
56
+ <frontend_type>select</frontend_type>
57
+ <sort_order>2</sort_order>
58
+ <show_in_default>1</show_in_default>
59
+ <show_in_website>1</show_in_website>
60
+ <show_in_store>1</show_in_store>
61
+ <source_model>adminhtml/system_config_source_yesno</source_model>
62
+ <comment>Exported data can be compressed before being sent</comment>
63
+ </enable_gzip>
64
+ -->
65
+ <!--
66
+ <export_url>
67
+ <label>Data Export Endpoint URL</label>
68
+ <frontend_type>text</frontend_type>
69
+ <sort_order>3</sort_order>
70
+ <show_in_default>1</show_in_default>
71
+ <show_in_website>1</show_in_website>
72
+ <show_in_store>1</show_in_store>
73
+ <comment>location the data will be exported to **to be removed**</comment>
74
+ </export_url>
75
+ -->
76
+ <export_orders translate="label">
77
+ <label>Export Orders?</label>
78
+ <frontend_type>select</frontend_type>
79
+ <sort_order>10</sort_order>
80
+ <show_in_default>1</show_in_default>
81
+ <show_in_website>1</show_in_website>
82
+ <show_in_store>1</show_in_store>
83
+ <source_model>adminhtml/system_config_source_yesno</source_model>
84
+ <comment>Sending us your order information will allow us to suggest "Customers who bought this also bought..." products.</comment>
85
+ </export_orders>
86
+
87
+ <order_status translate="label">
88
+ <label>Order Export Status</label>
89
+ <comment>Only orders with this status will be exported.</comment>
90
+ <frontend_type>multiselect</frontend_type>
91
+ <sort_order>11</sort_order>
92
+ <!-- for multiselects! -->
93
+ <show_in_default>1</show_in_default>
94
+ <show_in_website>1</show_in_website>
95
+ <show_in_store>1</show_in_store>
96
+ <source_model>dataexport/orderstatus</source_model>
97
+ </order_status>
98
+
99
+ <export_customers translate="label">
100
+ <label>Export Customers?</label>
101
+ <frontend_type>select</frontend_type>
102
+ <sort_order>20</sort_order>
103
+ <show_in_default>1</show_in_default>
104
+ <show_in_website>1</show_in_website>
105
+ <show_in_store>1</show_in_store>
106
+ <source_model>adminhtml/system_config_source_yesno</source_model>
107
+ <comment>Exporting your customers enables us to do social targeting.</comment>
108
+ </export_customers>
109
+ <export_carts translate="label">
110
+ <label>Export Abandoned Carts?</label>
111
+ <frontend_type>select</frontend_type>
112
+ <sort_order>30</sort_order>
113
+ <show_in_default>1</show_in_default>
114
+ <show_in_website>1</show_in_website>
115
+ <show_in_store>1</show_in_store>
116
+ <source_model>adminhtml/system_config_source_yesno</source_model>
117
+ <comment>Exporting your abandoned carts gives us additional data on which products are chosen together.</comment>
118
+ </export_carts>
119
+
120
+ <!-- This is covered by "Export Orders" - no need for extra field.
121
+ <export_productids translate="label">
122
+ <label>Export Product IDs to Header?</label>
123
+ <frontend_type>select</frontend_type>
124
+ <sort_order>10</sort_order>
125
+ <show_in_default>1</show_in_default>
126
+ <show_in_website>1</show_in_website>
127
+ <show_in_store>1</show_in_store>
128
+ <source_model>adminhtml/system_config_source_yesno</source_model>
129
+ <comment>Product ID hash will be added to the head of the document.</comment>
130
+ </export_productids>
131
+ -->
132
+
133
+ </fields>
134
+ </dataexport_group>
135
+ </groups>
136
+ </dataexport>
137
+ </sections>
138
+ </config>
app/code/community/Advertise/Dataexport/sql/dataexport_setup/mysql4-install-0.1.0.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $installer = $this;
3
+ $installer->startSetup();
4
+ //$installer->run("create table tablename(tablename_id int not null auto_increment, name varchar(100), primary key(tablename_id));
5
+ // insert into tablename values(1,'tablename1');
6
+ // insert into tablename values(2,'tablename2');
7
+ //");
8
+ //demo
9
+ //Mage::getModel('core/url_rewrite')->setId(null);
10
+ //demo
11
+ $installer->endSetup();
12
+
app/design/adminhtml/default/default/layout/dataexport.xml ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <dataexport_adminhtml_dataexportbackend_index>
4
+ <reference name="content">
5
+ <block type="dataexport/adminhtml_dataexportbackend" name="dataexportbackend" template="dataexport/dataexportbackend.phtml"/>
6
+ </reference>
7
+ </dataexport_adminhtml_dataexportbackend_index>
8
+
9
+ <dataexport_adminhtml_dataexportbackend_export>
10
+ <reference name="content">
11
+ <block type="dataexport/adminhtml_dataexportbackend" name="dataexportbackend" template="dataexport/dataexportbackend.phtml"/>
12
+ </reference>
13
+ </dataexport_adminhtml_dataexportbackend_export>
14
+ </layout>
app/design/adminhtml/default/default/template/dataexport/dataexportbackend.phtml ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package dataexport
4
+ *
5
+ */
6
+ ?>
7
+ <div class="content-header">
8
+ <table cellspacing="0">
9
+ <tbody>
10
+ <tr>
11
+ <td style="width:50%;">
12
+ <h3 class="icon-head head-cms-page">Adverti.se Retail Intelligence</h3>
13
+ </td>
14
+ <td class="form-buttons">
15
+
16
+ </td>
17
+ </tr>
18
+ </tbody>
19
+ </table>
20
+ </div>
21
+
22
+ <table class="form-list">
23
+ <tr>
24
+ <td class="label">
25
+ Retail Intelligence Module
26
+ </td>
27
+ <td class="value">
28
+ <strong><?php echo $this->_isEnabled() ?></strong>
29
+ </td>
30
+ </tr>
31
+ <tr>
32
+ <td class="label">
33
+ Order Export
34
+ </td>
35
+ <td class="value">
36
+ <strong><?php echo $this->_isOrdersEnabledText() ?></strong>
37
+ </td>
38
+ </tr>
39
+ <tr>
40
+ <td class="label">
41
+ Customer Export
42
+ </td>
43
+ <td class="value">
44
+ <strong><?php echo $this->_isCustomersEnabledText() ?></strong>
45
+ </td>
46
+ </tr>
47
+ <tr>
48
+ <td class="label">
49
+ Abandoned Carts Export
50
+ </td>
51
+ <td class="value">
52
+ <strong><?php echo $this->_isCartsEnabledText() ?></strong>
53
+ </td>
54
+ </tr>
55
+ <!-- Placeholder for when gzip is implemented
56
+ <tr>
57
+ <td class="label">
58
+ Gzip Compression
59
+ </td>
60
+ <td class="value">
61
+ <strong>Disabled</strong>
62
+ </td>
63
+ </tr>
64
+ -->
65
+ </table>
66
+
67
+ <div class="content-header">
68
+ <h3>Export Options</h3>
69
+ </div>
70
+
71
+ <form id="dataexportForm" action="<?php echo $this->_getFormAction() ?>" method="post">
72
+ <input name="form_key" type="hidden" value="<?php echo Mage::getSingleton('core/session')->getFormKey() ?>" />
73
+ <table class="form-list">
74
+ <tr>
75
+ <td class="label">
76
+ <label for="date_from">Date from</label>
77
+ </td>
78
+ <td class="value">
79
+ <input id="date_from" name="date_from" type="text" class="text-input" value="" />
80
+ <img title="Select date" id="fromTrigger"
81
+ src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN) . 'adminhtml/default/default/images/grid-cal.gif' ?>"
82
+ class="v-middle"
83
+ />
84
+ </td>
85
+ </tr>
86
+ <tr>
87
+ <td class="label">
88
+ <label for="date_to">Date To</label>
89
+ </td>
90
+ <td class="value">
91
+ <input id="date_to" name="date_to" type="text" class="text-input" value="" />
92
+ <img title="Select date" id="toTrigger"
93
+ src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN) . 'adminhtml/default/default/images/grid-cal.gif' ?>"
94
+ class="v-middle"
95
+ />
96
+ </td>
97
+ </tr>
98
+ <tr>
99
+ <td colspan="2">
100
+ <?php $disabled = $this->_getConfig()->getIsEnabled() ? '' : ' disabled="disabled"' ?>
101
+ <?php $classDisabled = $this->_getConfig()->getIsEnabled() ? '' : ' disabled' ?>
102
+ <button<?php echo $disabled ?> onclick="" class="scalable<?php echo $classDisabled ?>" type="submit" title="Run Export" id="exportBtn">
103
+ <span><span><span>Run Export</span></span></span>
104
+ </button>
105
+ </td>
106
+ </tr>
107
+ </table>
108
+ </form>
109
+
110
+ <script type="text/javascript">
111
+ //<![CDATA[
112
+ //var editForm = new varienForm('dataexportForm');
113
+ Calendar.setup({
114
+ inputField : 'date_from',
115
+ ifFormat : '%m/%e/%y',
116
+ button : 'fromTrigger',
117
+ align : 'Bl',
118
+ singleClick : true
119
+ });
120
+
121
+ Calendar.setup({
122
+ inputField : 'date_to',
123
+ ifFormat : '%m/%e/%y',
124
+ button : 'toTrigger',
125
+ align : 'Bl',
126
+ singleClick : true
127
+ });
128
+ //]]>
129
+
130
+ /*var reloadurl = '<?php echo $this->getUrl('router/controller/action') ?>';
131
+ Element.show('loadingmask');
132
+ new Ajax.Request(reloadurl, {
133
+ method: 'post',
134
+ parameters: "Params_Here",
135
+ onComplete: function(transport) {
136
+ Element.hide('loadingmask');
137
+ $('output-div').innerHTML = "";
138
+ $('output-div').innerHTML = transport.responseText;
139
+
140
+ }
141
+ });*/
142
+ </script>
app/design/frontend/base/default/layout/dataexport.xml ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <dataexport_index_index>
4
+ <reference name="root">
5
+ <action method="setTemplate"><template>page/1column.phtml</template></action>
6
+ </reference>
7
+
8
+ <reference name="content">
9
+ <block type="dataexport/index" name="dataexport_index" template="dataexport/index.phtml"/>
10
+ </reference>
11
+ </dataexport_index_index>
12
+ </layout>
app/design/frontend/base/default/template/dataexport/index.phtml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * To change this template, choose Tools | Templates
5
+ * and open the template in the editor.
6
+ */
7
+ ?>
8
+ TEST
app/etc/modules/Advertise_Dataexport.xml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Advertise_Dataexport>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ <version>0.1.0</version>
8
+ </Advertise_Dataexport>
9
+ </modules>
10
+ </config>
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>AdvertiseCommunity</name>
4
- <version>1.0.3</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">OSL</license>
7
  <channel>community</channel>
@@ -17,13 +17,14 @@
17
  &#xD;
18
  &lt;p&gt;Learn more about how Adverti.se can help your magento store at &lt;a href="http://www.adverti.se"&gt;Adverti.se&lt;/a&gt;&#xD;
19
  &lt;/p&gt;</description>
20
- <notes>v1.0.3&#xD;
21
  &#xD;
22
- Add a phone number.</notes>
 
23
  <authors><author><name>Michael Oxley</name><user>advertise</user><email>mike@adverti.se</email></author></authors>
24
- <date>2012-09-26</date>
25
- <time>13:53:45</time>
26
- <contents><target name="mage"><dir name="lib"><dir name="Varien"><dir name="Data"><dir name="Form"><dir name="Element"><file name="Advertisetemplate.php" hash="93d8c1f2ace06bd46e68857b9b98ec52"/><file name="Advertiselicense.php" hash="26d50ff2d280db94e4d0eb7187376880"/></dir></dir></dir></dir></dir><dir name="app"><dir name="etc"><dir name="modules"><file name="Advertise_Account.xml" hash="2bd58af0a4999bc2fe80a1d6e8a07d57"/></dir></dir><dir name="code"><dir name="community"><dir name="Advertise"><dir name="Account"><dir name="Helper"><file name="Data.php" hash="9b22d8f7156cd9f694774d7e29e2b5a8"/></dir><dir name="Model"><file name="Account.php" hash="605e33ef9c956852cd9f0357cb10776c"/><dir name="Config"><dir name="Source"><file name="Onoff.php" hash="684e42d40da3b47053bf345f201df140"/></dir></dir><file name="Config.php" hash="ee470d4c5a46a0221456b31b85c7473c"/><file name="MyAccountModel.php" hash="d7abbf976d96028ece0331db2ba40559"/><file name="Settings.php" hash="d41d8cd98f00b204e9800998ecf8427e"/></dir><dir name="controllers"><file name="IndexController.php" hash="50eea849547a732c20462da19029e432"/><file name="LicenseController.php" hash="b83f323609fecefa4ff6dbab911468ce"/><file name="WebserviceController.php" hash="675d33aa04d1c01c34fdea086d73ce85"/></dir><dir name="etc"><file name="config.xml" hash="1008af4062018449215a14f21dc1235f"/><file name="system.xml" hash="9f8480290a07f87bb568e4b0db33a330"/></dir><dir name="sql"><dir name="advertise_setup"><file name="mysql4-install-4.0.0.php" hash="b4535b5068d6b72999c94e91d487bc62"/><file name="mysql4-install-5.0.0.php" hash="b4535b5068d6b72999c94e91d487bc62"/></dir><dir name="setup"><file name="mysql4-install-0.1.0.php" hash="452925d5182994846dbe3b9518db84d8"/></dir></dir></dir></dir></dir></dir></dir><dir name="var"><dir name="advertisedata"><file name="empty.txt" hash="d41d8cd98f00b204e9800998ecf8427e"/></dir></dir></target></contents>
27
  <compatible/>
28
  <dependencies><required><php><min>5.0.0</min><max>6.0.0</max></php></required></dependencies>
29
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>AdvertiseCommunity</name>
4
+ <version>1.2.0</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">OSL</license>
7
  <channel>community</channel>
17
  &#xD;
18
  &lt;p&gt;Learn more about how Adverti.se can help your magento store at &lt;a href="http://www.adverti.se"&gt;Adverti.se&lt;/a&gt;&#xD;
19
  &lt;/p&gt;</description>
20
+ <notes>v1.2.0&#xD;
21
  &#xD;
22
+ This version now has the common elements from the cross-sell, up-sell and related products extensions. &#xD;
23
+ These elements are not active unless those packages are installed. So if you only have Advertise Colors, this extra code will not be used.</notes>
24
  <authors><author><name>Michael Oxley</name><user>advertise</user><email>mike@adverti.se</email></author></authors>
25
+ <date>2012-10-07</date>
26
+ <time>13:14:58</time>
27
+ <contents><target name="mage"><dir name="lib"><dir name="Varien"><dir name="Data"><dir name="Form"><dir name="Element"><file name="Advertisetemplate.php" hash="93d8c1f2ace06bd46e68857b9b98ec52"/><file name="Advertiselicense.php" hash="26d50ff2d280db94e4d0eb7187376880"/></dir></dir></dir></dir></dir><dir name="app"><dir name="etc"><dir name="modules"><file name="Advertise_Account.xml" hash="2bd58af0a4999bc2fe80a1d6e8a07d57"/><file name="Advertise_Dataexport.xml" hash="85b7c6199506488967c6951b513da65e"/></dir></dir><dir name="code"><dir name="community"><dir name="Advertise"><dir name="Account"><dir name="Helper"><file name="Data.php" hash="9b22d8f7156cd9f694774d7e29e2b5a8"/></dir><dir name="Model"><file name="Account.php" hash="605e33ef9c956852cd9f0357cb10776c"/><dir name="Config"><dir name="Source"><file name="Onoff.php" hash="684e42d40da3b47053bf345f201df140"/></dir></dir><file name="Config.php" hash="ee470d4c5a46a0221456b31b85c7473c"/><file name="MyAccountModel.php" hash="d7abbf976d96028ece0331db2ba40559"/><file name="Settings.php" hash="d41d8cd98f00b204e9800998ecf8427e"/></dir><dir name="controllers"><file name="IndexController.php" hash="50eea849547a732c20462da19029e432"/><file name="LicenseController.php" hash="b83f323609fecefa4ff6dbab911468ce"/><file name="WebserviceController.php" hash="675d33aa04d1c01c34fdea086d73ce85"/></dir><dir name="etc"><file name="config.xml" hash="1008af4062018449215a14f21dc1235f"/><file name="system.xml" hash="9f8480290a07f87bb568e4b0db33a330"/></dir><dir name="sql"><dir name="advertise_setup"><file name="mysql4-install-4.0.0.php" hash="b4535b5068d6b72999c94e91d487bc62"/><file name="mysql4-install-5.0.0.php" hash="b4535b5068d6b72999c94e91d487bc62"/></dir><dir name="setup"><file name="mysql4-install-0.1.0.php" hash="452925d5182994846dbe3b9518db84d8"/></dir></dir></dir><dir name="Dataexport"><dir name="Block"><dir name="Adminhtml"><file name="Dataexportbackend.php" hash="89c075c9a224a327e1e0816ab9efeddf"/></dir><file name="Index.php" hash="e504da66a574a5df674b5d8385ce4108"/></dir><dir name="Helper"><file name="Data.php" hash="a46d6039d81a0c3ec8182c05688729db"/></dir><dir name="Model"><file name="Config.php" hash="abb4f8739e9fa07dbe041a0129211eb7"/><dir name="Exporter"><file name="Cart.php" hash="6164c971932885d2cafc86275a4c0649"/><file name="Customer.php" hash="e8ffc864fb2ec2757d3517d3e179c12a"/><file name="Interface.php" hash="1b311d997c503d5e6ec567f703491306"/><file name="Order.php" hash="48aef9cea01c358b81e4d8469e237169"/></dir><file name="Exporter.php" hash="3fe694e544ee2a2f4d51f07f22b57596"/><file name="Modelname.php" hash="c5d3ff7a7c9443ec43c84a8d8c07cfc1"/><dir name="Mysql4"><dir name="Modelname"><file name="Collection.php" hash="7829fb805cf36d108d97e22175419c97"/></dir><file name="Modelname.php" hash="4ffa0d7fa31b0e6544d66e41d0239410"/></dir><file name="Orderstatus.php" hash="d3f17637413ea2417a3080435215ac26"/><file name="Scheduler.php" hash="be3d416160a7b4973907ef58a42306e3"/><file name="Xmlwriter.php" hash="a86b81bcb8964935410738643de32e8f"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="DataexportbackendController.php" hash="914467bd702962ee5a082a6d1d756469"/></dir><file name="IndexController.php" hash="8be7143d4a93cd96fa37c7ae7cb735e2"/><file name="TestController.php" hash="74d89fd194029ae654a3cec3b39c9778"/></dir><dir name="etc"><file name="adminhtml.xml" hash="e3ccc4047ca0ece4295e156e986f3019"/><file name="config.xml" hash="e3776aee6bb28d50e4baf14e5b38dc64"/><file name="system.xml" hash="61e86cd66dca0851ae203867b36e0a33"/></dir><dir name="sql"><dir name="dataexport_setup"><file name="mysql4-install-0.1.0.php" hash="b01d2c1aefe3ec69dc1799d3b682cc3b"/></dir></dir></dir></dir></dir></dir><dir name="design"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="dataexport.xml" hash="2da004f9cbaeee331a62b9592692e2c1"/></dir><dir name="template"><dir name="dataexport"><file name="dataexportbackend.phtml" hash="6c21dd0709ac1a09bb77f4a4ae3ff867"/></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="dataexport.xml" hash="5b8bdfdb430b0d0e9be0c4deb2a355a0"/></dir><dir name="template"><dir name="dataexport"><file name="index.phtml" hash="4b88ef0e0ac3d19787f9fc7b4da2e91b"/></dir></dir></dir></dir></dir></dir></dir><dir name="var"><dir name="advertisedata"><file name="empty.file" hash="d41d8cd98f00b204e9800998ecf8427e"/></dir></dir></target></contents>
28
  <compatible/>
29
  <dependencies><required><php><min>5.0.0</min><max>6.0.0</max></php></required></dependencies>
30
  </package>
var/advertisedata/{empty.txt → empty.file} RENAMED
File without changes