Lister_Greyferret - Version 0.0.1

Version Notes

Initial Stable release

Download this release

Release Info

Developer Lister Technologies (P) Ltd
Extension Lister_Greyferret
Version 0.0.1
Comparing to
See all releases


Version 0.0.1

app/code/community/Lister/Greyferret/Block/Adminhtml/System/Config/Date.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Repesents Lister_Greyferret Api.
4
+ *
5
+ * PHP version 5.5
6
+ *
7
+ * @category PHP
8
+ * @package Lister_Greyferret_Block_Adminhtml_System_Config_Date
9
+ * @author Vellaidurai R <vellaidurai.rajendran@listertechnologies.com>
10
+ * @copyright 2015 Lister Technologies Pvt Ltd
11
+ * @license copyright @ listertechnologies.com
12
+ * @link https://greyferret.com/
13
+ */
14
+
15
+ class Lister_Greyferret_Block_Adminhtml_System_Config_Date extends Mage_Adminhtml_Block_System_Config_Form_Field
16
+ {
17
+ /**
18
+ * Date display in admin panel.
19
+ * @param object $element varient data form element object.
20
+ * @return array
21
+ */
22
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
23
+ {
24
+ $date = new Varien_Data_Form_Element_Date;
25
+ $format = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
26
+
27
+ $data = array(
28
+ 'name' => $element->getName(),
29
+ 'html_id' => $element->getId(),
30
+ 'image' => $this->getSkinUrl('images/grid-cal.gif'),
31
+ );
32
+ $date->setData($data);
33
+ $date->setValue($element->getValue(), $format);
34
+ $date->setFormat(Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT));
35
+ $date->setClass($element->getFieldConfig()->validate->asArray());
36
+ $date->setForm($element->getForm());
37
+
38
+ return $date->getElementHtml();
39
+ }
40
+ }
app/code/community/Lister/Greyferret/Helper/Data.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Repesents Lister_Greyferret Api.
4
+ *
5
+ * PHP version 5.5
6
+ *
7
+ * @category PHP
8
+ * @package Lister_Greyferret_Helper_Data
9
+ * @author info@listertechnologies.com
10
+ * @license General Public License
11
+ * @link https://greyferret.com/
12
+ */
13
+
14
+ class Lister_Greyferret_Helper_Data extends Mage_Core_Helper_Abstract
15
+ {
16
+ }
app/code/community/Lister/Greyferret/Model/Adminhtml/System/Config/Category/List.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Repesents Lister_Greyferret Api.
4
+ *
5
+ * PHP version 5.5
6
+ *
7
+ * @category PHP
8
+ * @package Lister_Greyferret_Model_Adminhtml_System_Config_Category_List
9
+ * @author info@listertechnologies.com
10
+ * @copyright 2015 Lister Technologies Pvt Ltd
11
+ * @license copyright @ listertechnologies.com
12
+ * @link https://greyferret.com/
13
+ */
14
+
15
+ class Lister_Greyferret_Model_Adminhtml_System_Config_Category_List
16
+ {
17
+ /**
18
+ * Greyferret api list.
19
+ * @return void
20
+ */
21
+ public function toOptionArray()
22
+ {
23
+ return array(
24
+ array('value'=>1, 'label'=>Mage::helper('greyferret')->__('Customer')),
25
+ array('value'=>2, 'label'=>Mage::helper('greyferret')->__('Category')),
26
+ array('value'=>3, 'label'=>Mage::helper('greyferret')->__('Order')),
27
+ );
28
+ }
29
+ /**
30
+ * Greyferret api list.
31
+ * @return void
32
+ */
33
+ public function toArray()
34
+ {
35
+ return array(
36
+ 1 => Mage::helper('greyferret')->__('Customer'),
37
+ 2 => Mage::helper('greyferret')->__('Category'),
38
+ 3 => Mage::helper('greyferret')->__('Order'),
39
+ );
40
+ }
41
+ }
app/code/community/Lister/Greyferret/Model/Adminhtml/System/Config/Cron/Schedule.php ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Repesents Lister_Greyferret Api.
4
+ *
5
+ * PHP version 5.5
6
+ *
7
+ * @category PHP
8
+ * @package Lister_Greyferret_Model_Adminhtml_System_Config_Cron_Schedule
9
+ * @author info@listertechnologies.com
10
+ * @license General Public License
11
+ * @link https://greyferret.com/
12
+ */
13
+
14
+
15
+ class Lister_Greyferret_Model_Adminhtml_System_Config_Cron_Schedule extends Mage_Core_Model_Config_Data
16
+ {
17
+ const CRON_STRING_PATH = 'crontab/jobs/greyferret_cron/schedule/cron_expr';
18
+
19
+ /**
20
+ * Set cron with expression
21
+ * @return string
22
+ */
23
+ protected function _afterSave()
24
+ {
25
+ $Status = $this->getData('groups/configurable_cron/fields/greyferret_cron/value');
26
+ if ($Status == true) {
27
+ $Time = $this->getData('groups/configurable_cron/fields/greyferret_time/value');
28
+ $Calender = $this->getData('groups/configurable_cron/fields/greyferret_date/value');
29
+ $DateArray = explode('/', $Calender);
30
+ $cronExprArray = array(
31
+ intval($Time[1]),
32
+ intval($Time[0]),
33
+ intval($DateArray[1]),
34
+ intval($DateArray[0]),
35
+ '*',
36
+ intval($DateArray[2]),
37
+ );
38
+ $cronExprString = join(' ', $cronExprArray);
39
+ } else {
40
+ $cronExprString = "";
41
+ }
42
+ try {
43
+ Mage::getModel('core/config_data')
44
+ ->load(self::CRON_STRING_PATH, 'path')
45
+ ->setValue($cronExprString)
46
+ ->setPath(self::CRON_STRING_PATH)
47
+ ->save();
48
+ if ($Status == false) {
49
+ Mage::getModel('core/config')->saveConfig('greyferret_options/configurable_cron/greyferret_state', 'Disable');
50
+ } else if ($Status == true) {
51
+ Mage::getModel('core/config')->saveConfig('greyferret_options/configurable_cron/greyferret_state', 'Yet to start');
52
+ }
53
+ }
54
+ catch (Exception $e) {
55
+ Mage::throwException(Mage::helper('cron')->__('Unable to save the cron expression.'));
56
+
57
+ }
58
+ }
59
+ }
app/code/community/Lister/Greyferret/Model/Api.php ADDED
@@ -0,0 +1,696 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Repesents Lister_Greyferret Api.
4
+ *
5
+ * PHP version 5.5
6
+ *
7
+ * @category PHP
8
+ * @package Lister_Greyferret_Model_Api
9
+ * @author info@listertechnologies.com
10
+ * @license General Public License
11
+ * @link https://greyferret.com/
12
+ */
13
+
14
+ class Lister_Greyferret_Model_Api extends Mage_Core_Model_Abstract
15
+ {
16
+ /**
17
+ * The greyferret url.
18
+ *
19
+ * @var string
20
+ */
21
+ private $_url;
22
+
23
+ /**
24
+ * The greyferret client key.
25
+ *
26
+ * @var string
27
+ */
28
+ private $_clientKey;
29
+
30
+ /**
31
+ * The time out of api call.
32
+ *
33
+ * @var integer
34
+ */
35
+ private $_timeOut;
36
+
37
+ /**
38
+ * Category object.
39
+ *
40
+ * @var object
41
+ */
42
+ private $_categoryObj;
43
+
44
+ /**
45
+ * Order object.
46
+ *
47
+ * @var object
48
+ */
49
+ private $_orderObj;
50
+
51
+ /**
52
+ * Order collection Url.
53
+ *
54
+ * @var object
55
+ */
56
+ private $_orderCollectionObj;
57
+
58
+ /**
59
+ * Customer object.
60
+ *
61
+ * @var object
62
+ */
63
+ private $_customerObj;
64
+
65
+ /**
66
+ * Cron status flag.
67
+ *
68
+ * @var string
69
+ */
70
+ protected $cronStatus = false;
71
+
72
+ /**
73
+ * Log status flag.
74
+ *
75
+ * @var string
76
+ */
77
+ protected $apiLog = false;
78
+
79
+ /**
80
+ * Category list (Order,Customer,Category).
81
+ *
82
+ * @var integer
83
+ */
84
+ protected $categoryList;
85
+
86
+ /**
87
+ * Api State (true/false)
88
+ *
89
+ * @var boolean
90
+ */
91
+ protected $apiState = false;
92
+
93
+ /**
94
+ * The country object.
95
+ *
96
+ * @var object
97
+ */
98
+ protected $countryObj;
99
+
100
+ /**
101
+ * The primary id.
102
+ *
103
+ * @var int
104
+ */
105
+ protected $currentId;
106
+
107
+ /**
108
+ * The primary id.
109
+ *
110
+ * @var int
111
+ */
112
+ protected $_userObj;
113
+
114
+ /**
115
+ * The primary id.
116
+ *
117
+ * @var int
118
+ */
119
+ protected $entityTypeArray = array("customerEntity" => "customer", "catalogEntity" => 'category', "orderEntity" => "order");
120
+
121
+ /**
122
+ * The primary id.
123
+ *
124
+ * @var int
125
+ */
126
+ protected $entityStatusArray = array("initiate" => "Initiated", "inprogress" => "Inprogress", "pending" => "Pending", "complete" => 'Completed');
127
+
128
+ const MODULE_NAME = 'Greyferret';
129
+ const LOGFILE = 'greyferret.log';
130
+ const CONFIG_DIR_API = 'greyferret_options/configurable_cron/%s';
131
+ const API_URL = 'greyferret_api_url';
132
+ const USER_NAME = 'greyferret_use_name';
133
+ const CLIENT_KEY = 'greyferret_api_key';
134
+ const TIME_OUT = 'greyferret_timeout';
135
+ const CRON_STATUS = 'greyferret_cron';
136
+ const CATEGORY_LIST = 'greyferret_list';
137
+ const API_STATE = 'greyferret_state';
138
+ const DEBUG_MODE = 'greyferret_debug';
139
+ const CATEGORY_URL = 'category';
140
+ const CUSTOMER_URL = 'customer';
141
+ const ORDER_URL = 'order';
142
+
143
+ /**
144
+ * Prepare a Greyferret API call.
145
+ * @param array $options CURL option array.
146
+ * @return void
147
+ */
148
+ public function _construct($options = array())
149
+ {
150
+ parent::_construct();
151
+ $this->_init('greyferret/api');
152
+ $this->cronStatus=self::getConfig(self::CONFIG_DIR_API, self::CRON_STATUS);
153
+ $this->categoryList = self::getConfig(self::CONFIG_DIR_API, self::CATEGORY_LIST);
154
+ $this->apiState = self::getConfig(self::CONFIG_DIR_API, self::API_STATE);
155
+ $this->apiLog = self::getConfig(self::CONFIG_DIR_API, self::DEBUG_MODE);
156
+ $this->_timeOut = self::getConfig(self::CONFIG_DIR_API, self::TIME_OUT);
157
+ $this->_url = self::getConfig(self::CONFIG_DIR_API, self::API_URL);
158
+ $this->_userName = self::getConfig(self::CONFIG_DIR_API, self::USER_NAME);
159
+ $this->_clientKey = self::getConfig(self::CONFIG_DIR_API, self::CLIENT_KEY);
160
+ $this->_orderObj = Mage::getModel('sales/order');
161
+ $this->_categoryObj = Mage::getModel('catalog/category');
162
+ $this->_customerObj = Mage::getResourceModel('customer/customer_collection');
163
+ $this->_userObj = Mage::getModel('customer/customer');
164
+ $this->countryObj = Mage::getModel('directory/country');
165
+ $this->extractVar($this->entityTypeArray);
166
+ $this->extractVar($this->entityStatusArray);
167
+ $this->_handler = new Varien_Http_Adapter_Curl();
168
+ $opt = array(
169
+ 'timeout' => $this->_timeOut,
170
+ 'verifypeer' => false,
171
+ 'verifyhost' => false
172
+ );
173
+ if (!empty($options)) {
174
+ $opt = array_merge($opt, $options);
175
+ }
176
+ $this->_handler->setConfig($opt);
177
+ $this->_handler->addOption(CURLINFO_HEADER_OUT, true);
178
+ $this->_handler->addOption(CURLOPT_RETURNTRANSFER, true);
179
+ unset($opt);
180
+ }
181
+
182
+ /**
183
+ * Run the greyferret service for the order,customer,category.
184
+ * @return string
185
+ */
186
+ public function run()
187
+ {
188
+ $option = explode(',', $this->categoryList);
189
+ if ($this->cronStatus) {
190
+ foreach ($option as $list) {
191
+ switch ($list) {
192
+ case 1:
193
+ $this->getCustomerList();
194
+ $this->selectGreyferretLog($this->customerEntity);
195
+ $customerStatus = $this->entityStatus;
196
+ break;
197
+
198
+ case 2:
199
+ $this->getCategoryList();
200
+ $this->selectGreyferretLog($this->catalogEntity);
201
+ $catalogStatus = $this->entityStatus;
202
+ break;
203
+
204
+ case 3:
205
+ $this->getOrderList();
206
+ $this->selectGreyferretLog($this->orderEntity);
207
+ $orderStatus = $this->entityStatus;
208
+ break;
209
+ }
210
+ }
211
+ if($customerStatus == $this->complete && $catalogStatus == $this->complete && $orderStatus == $this->complete) {
212
+ Mage::getModel('core/config')->saveConfig('greyferret_options/configurable_cron/greyferret_state', 'Completed');
213
+ } else {
214
+ Mage::getModel('core/config')->saveConfig('greyferret_options/configurable_cron/greyferret_state', 'Completed with errors');
215
+ }
216
+ Mage::getModel('core/config')->saveConfig('greyferret_options/configurable_cron/greyferret_cron', '0');
217
+ } else {
218
+ return false;
219
+ }
220
+ }
221
+ /**
222
+ * Run the greyferret service with complete category list .
223
+ * @return string
224
+ */
225
+ public function getCategoryList()
226
+ {
227
+ $categoryArray = array();
228
+ $tree = $this->_categoryObj->getTreeModel();
229
+ $tree->load();
230
+ $collection = $tree->getCollection();
231
+ $this->selectGreyferretLog($this->catalogEntity);
232
+ $this->saveLog($this->entityLastId,$this->catalogEntity,$this->entityId,$this->initiate);
233
+ if(!is_null($this->entityId)) {
234
+ $collection->addAttributeToFilter(array(
235
+ array(
236
+ 'attribute' => 'entity_id',
237
+ 'gt' => is_null($this->entityLastId)?0:$this->entityLastId
238
+ ),
239
+ array(
240
+ 'attribute' => 'entity_id',
241
+ 'in' => is_null($this->entityId)?'':$this->entityId
242
+ )
243
+ ));
244
+ $this->saveLog($this->entityLastId,$this->catalogEntity,null,$this->inprogress);
245
+ } else {
246
+ $ids = $collection->getAllIds();
247
+ }
248
+ if ($ids) {
249
+ foreach ($ids as $id) {
250
+ $this->_categoryObj->load($id);
251
+ $categoryArray = $this->createCategoryArray($this->_categoryObj);
252
+ $this->call($categoryArray, $this->catalogEntity);
253
+ }
254
+ }
255
+ $this->selectGreyferretLog($this->catalogEntity);
256
+ if(is_null($this->entityId)) {
257
+ $this->saveLog($this->entityLastId,$this->catalogEntity,null,$this->complete);
258
+ }
259
+ }
260
+ /**
261
+ * Create category array.
262
+ * @param object $catObj category object.
263
+ * @return array
264
+ */
265
+ public function createCategoryArray($catObj)
266
+ {
267
+ $returnArray = array();
268
+ $entityId = $catObj->getId();
269
+ $name = $catObj->getName();
270
+ $description = $catObj->getDescription()?$catObj->getDescription():"";
271
+ $parentId = $catObj->getParentId();
272
+ $returnArray['categoryId'] = $entityId;
273
+ $returnArray['categoryName'] = $name;
274
+ $returnArray['categoryDesc'] = $description;
275
+ $returnArray['parentCategoryId'] = $parentId;
276
+ $returnArray['createdBy'] = 'Magento Ecommerce';
277
+ return $returnArray;
278
+ }
279
+ /**
280
+ * Run the greyferret service for complete list of orders.
281
+ * @return string
282
+ */
283
+ public function getOrderList()
284
+ {
285
+ $orderArray = array();
286
+ $collection = $this->_orderObj->getCollection();
287
+ $collection->addFieldToFilter('status', array('eq' => array('complete')));
288
+ $this->selectGreyferretLog($this->orderEntity);
289
+ $this->saveLog($this->entityLastId,$this->orderEntity,$this->entityId,$this->initiate);
290
+ if(!is_null($this->entityId)) {
291
+ $collection->addFieldToFilter('entity_id',
292
+ array(
293
+ array('in' => explode(',',$this->entityId)),
294
+ array('gt' => $this->entityLastId)
295
+ )
296
+ );
297
+ $this->saveLog($this->entityLastId,$this->orderEntity,null,$this->inprogress);
298
+ }
299
+
300
+ foreach ($collection as $order) {
301
+ $orderArray = $this->createOrderArray($order);
302
+ $this->call($orderArray, $this->orderEntity, true);
303
+ }
304
+ $this->selectGreyferretLog($this->orderEntity);
305
+ if(is_null($this->entityId)) {
306
+ $this->saveLog($this->entityLastId,$this->orderEntity,null,$this->complete);
307
+ }
308
+ }
309
+ /**
310
+ * Create order array.
311
+ * @param object $orderObj order object.
312
+ * @return array
313
+ */
314
+ public function createOrderArray($orderObj)
315
+ {
316
+ $returnArray = $productArray = array();
317
+ $orderid = $orderObj->getId();
318
+ $items = $orderObj->getAllVisibleItems();
319
+ $customerid = $orderObj->getCustomerId();
320
+ $date = $orderObj->getCreatedAt();
321
+ foreach ($items as $item) {
322
+ $returnArray['Order_id'] = trim($item->getOrderId());
323
+ $returnArray['customer_id'] = $customerid;
324
+ $returnArray['createdBy'] = 'Magento Ecommerce';
325
+ $returnArray['currency_code'] = $orderObj->getBaseCurrencyCode();
326
+ $returnArray['date_created'] = $date;
327
+ $product_id = $item->getProductId();
328
+ $product = $item->getProduct();
329
+ $cats = $product->getCategoryIds();
330
+ $category_id = $cats[0];
331
+ $category = $this->_categoryObj->load($category_id);
332
+ $productArray['categoryId'] = $category->getId();
333
+ $productArray['categoryName'] = $category->getName();
334
+ $productArray['discount'] = $item->getDiscountAmount();
335
+ $productArray['qty'] = $item->getQtyOrdered();
336
+ $productArray['sku'] = trim($item->getSku());
337
+ $productArray['skuName'] = $item->getName();
338
+ $productArray['totalAmount'] = $item->getPrice();
339
+ $returnArray['products'] = array($productArray);
340
+ $returnArray['purchaseDate'] = $date;
341
+ }
342
+ return $returnArray;
343
+ }
344
+ /**
345
+ * Run the greyferret service for complete list of customers.
346
+ */
347
+ public function getCustomerList()
348
+ {
349
+
350
+ $customerArray = array();
351
+ $collection = $this->_customerObj
352
+ ->addNameToSelect()
353
+ ->addAttributeToSelect('firstname')
354
+ ->addAttributeToSelect('lastname')
355
+ ->addAttributeToSelect('email')
356
+ ->addAttributeToSelect('created_at')
357
+ ->addAttributeToSelect('group_id')
358
+ ->addAttributeToSelect('email')
359
+ ->joinAttribute('shipping_street', 'customer_address/street', 'default_shipping', null, 'left')
360
+ ->joinAttribute('shipping_postcode', 'customer_address/postcode', 'default_shipping', null, 'left')
361
+ ->joinAttribute('shipping_city', 'customer_address/city', 'default_shipping', null, 'left')
362
+ ->joinAttribute('shipping_telephone', 'customer_address/telephone', 'default_shipping', null, 'left')
363
+ ->joinAttribute('shipping_fax', 'customer_address/fax', 'default_shipping', null, 'left')
364
+ ->joinAttribute('shipping_region', 'customer_address/region', 'default_shipping', null, 'left')
365
+ ->joinAttribute('shipping_country_code', 'customer_address/country_id', 'default_shipping', null, 'left');
366
+
367
+ $this->selectGreyferretLog($this->customerEntity);
368
+ $this->saveLog($this->entityLastId,$this->customerEntity,$this->entityId,$this->initiate);
369
+
370
+ if(!is_null($this->entityId) ) {
371
+ $collection->addAttributeToFilter(array(
372
+ array(
373
+ 'attribute' => 'entity_id',
374
+ 'gt' => is_null($this->entityLastId)?0:$this->entityLastId
375
+ ),
376
+ array(
377
+ 'attribute' => 'entity_id',
378
+ 'in' => is_null($this->entityId)?'':$this->entityId
379
+ )
380
+ ));
381
+
382
+ $this->saveLog($this->entityLastId,$this->customerEntity,null,$this->inprogress);
383
+ }
384
+
385
+ foreach ($collection as $item) {
386
+ $customerArray = $this->createCustomerArray($item);
387
+ $this->call($customerArray,$this->customerEntity);
388
+ }
389
+ $this->selectGreyferretLog($this->customerEntity);
390
+ if(is_null($this->entityId)) {
391
+ $this->saveLog($this->entityLastId,$this->customerEntity,null,$this->complete);
392
+ }
393
+ }
394
+ /**
395
+ * Create customer array.
396
+ * @param object $customerObj customer object.
397
+ * @return array
398
+ */
399
+ public function createCustomerArray($customerInfo)
400
+ {
401
+ if (is_object($customerInfo)) {
402
+ $returnArray['customerId'] = $customerInfo->getId();
403
+ $returnArray['firstName'] = $customerInfo->firstname;
404
+ $returnArray['lastName'] = $customerInfo->lastname;
405
+ $returnArray['createdBy'] = $customerInfo->created_at;
406
+ $returnArray['Address1'] = $customerInfo->shipping_street;
407
+ $returnArray['pinCode'] = $customerInfo->shipping_postcode;
408
+ $returnArray['email1'] = $customerInfo->email;
409
+ $returnArray['city'] = $customerInfo->shipping_city;
410
+ $returnArray['state'] = $customerInfo->shipping_region;
411
+ $countryCode = $customerInfo->shipping_country_code;
412
+ } else {
413
+ $returnArray = array();
414
+ $returnArray['customerId'] = empty($customerInfo['customer_id'])?$customerInfo['parent_id']:$customerInfo['customer_id'];
415
+ $returnArray['firstName'] = $customerInfo['firstname'];
416
+ $returnArray['lastName'] = $customerInfo['lastname'];
417
+ $returnArray['email1'] = empty($customerInfo['email'])?$this->findEmail($customerInfo['customer_id']):$customerInfo['email'];
418
+ $returnArray['createdBy'] = $customerInfo['updated_at'];
419
+ $returnArray['Address1'] = $customerInfo['street'];
420
+ $returnArray['pinCode'] = $customerInfo['postcode'];
421
+ $returnArray['city'] = $customerInfo['city'];
422
+ $returnArray['state'] = $customerInfo['region'];
423
+ $countryCode = $customerInfo['country_id'];
424
+ }
425
+
426
+ if (!empty($countryCode)) {
427
+ $country = $this->countryObj->loadByCode($countryCode);
428
+ $returnArray['country'] = $country->getName();
429
+ }
430
+ return $returnArray;
431
+ }
432
+
433
+ /**
434
+ * Runs the service call.
435
+ * @param string $request The files and directories to process. For
436
+ * @param string $entityType The set of code sniffs we are testing
437
+ * @param boolean $bulk If true, send bulk list.
438
+ * @return string.
439
+ */
440
+ protected function call($request,$entityType,$bulk=true)
441
+ {
442
+ try {
443
+ $this->_headers = array(
444
+ 'Content-Type: application/json',
445
+ 'Accept: application/json',
446
+ 'Authorization: Basic '. base64_encode($this->_userName.":".Mage::helper('core')->decrypt($this->_clientKey))
447
+ );
448
+
449
+ switch($entityType) {
450
+ case 'category':
451
+ $url = $this->_url.self::CATEGORY_URL;
452
+ $currentId = $request['categoryId'];
453
+ break;
454
+ case 'customer':
455
+ $url = $this->_url.self::CUSTOMER_URL;
456
+ $currentId = $request['customerId'];
457
+ break;
458
+ case 'order':
459
+ $url = $this->_url.self::ORDER_URL;
460
+ $currentId = $request['Order_id'];
461
+ break;
462
+ }
463
+
464
+ if(array_key_exists('0', $request)) {
465
+ $json =$request;
466
+ } else {
467
+ $json =array($request);
468
+ }
469
+ $post = Mage::helper('core')->jsonencode($json);
470
+ $this->_handler->write(
471
+ Zend_Http_Client::POST,
472
+ $url,
473
+ '1.1',
474
+ $this->_headers,
475
+ $post
476
+ );
477
+
478
+ $response = $this->_handler->read();
479
+
480
+ $status = intval($this->_handler->getInfo(CURLINFO_HTTP_CODE));
481
+ $error = array(
482
+ 'number' => $this->_handler->getErrno(),
483
+ 'message' => $this->_handler->getError()
484
+ );
485
+ $this->_handler->close();
486
+ if($this->apiLog) {
487
+ Mage::log(
488
+ "url: ".$url.
489
+ "\nentityType Type: ".$entityType." - ".$currentId.
490
+ "\nError Code: ".$error['number'].
491
+ "\nError Message: ".$error['message'].
492
+ "Response Data: ".trim($response)."\n",
493
+ null,
494
+ self::LOGFILE
495
+ );
496
+ }
497
+ $result = $this->responseCode($currentId,$status, $entityType, $bulk);
498
+ }
499
+ catch (Exception $e) {
500
+ if($this->apiLog) {
501
+ Mage::logException($e);
502
+ }
503
+ }
504
+ return $result;
505
+ }
506
+
507
+ /**
508
+ * Handle the response code from curl request.
509
+ * @param string $lastId last insert id
510
+ * @param string $status rest call status
511
+ * @param string $entityType entity type
512
+ * @param boolean $bulk If true, send bulk list.
513
+ * @return string.
514
+ */
515
+ protected function responseCode($lastId,$status,$entityType,$bulk)
516
+ {
517
+ try {
518
+ switch ($status) {
519
+ case 400:
520
+ if($bulk == true) {
521
+ $this->savePid($lastId,$entityType);
522
+ }
523
+ Mage::throwException('Not a valid inputs:');
524
+ break;
525
+ case 200:
526
+ $this->saveLog($lastId,$entityType,NULL,$this->pending);
527
+ break;
528
+ }
529
+ return true;
530
+ } catch (Exception $e) {
531
+ $this->_errorCode = $e->getCode();
532
+ $this->_errorMessage = $e->getMessage();
533
+ }
534
+ return false;
535
+ }
536
+
537
+ /**
538
+ * Get the configuration from the given URI.
539
+ * @param string $dir path
540
+ * @param boolean $field field.
541
+ * @return string.
542
+ */
543
+ protected function getConfig($dir,$field)
544
+ {
545
+ try {
546
+ return trim(Mage::getStoreConfig(sprintf($dir, $field))) ? trim(Mage::getStoreConfig(sprintf($dir, $field))) : false;
547
+ } catch (Exception $exc) {
548
+ return false;
549
+ }
550
+ }
551
+
552
+ /**
553
+ * Get the configuration from the given URI.
554
+ * @param string $lastId last insert id
555
+ * @param string $entityType entity type
556
+ * @param boolean $pId primary id.
557
+ * * @param string $status rest call status
558
+ * @return string.
559
+ */
560
+ protected function saveLog($lastId,$entityType,$pId,$status)
561
+ {
562
+ try {
563
+ $inputArray = array();
564
+ if(!is_null($lastId)) {
565
+ $inputArray['entityLastId'] = $lastId;
566
+ } else {
567
+ $inputArray['entityLastId'] = null;
568
+ }
569
+ if(!is_null($pId)) {
570
+ $inputArray['entityId'] = $pId;
571
+ } else {
572
+ $inputArray['entityId'] = null;
573
+ }
574
+ if(!is_null($entityType)) {
575
+ $inputArray['entityType'] = $entityType;
576
+ } else {
577
+ $inputArray['entityType'] = null;
578
+ }
579
+ if(!is_null($status)) {
580
+ $inputArray['entityStatus'] = $status;
581
+ } else {
582
+ $inputArray['entityStatus'] = null;
583
+ }
584
+
585
+ if(count($inputArray)>0) {
586
+ $model = Mage::getModel('greyferret/api');
587
+ $this->selectGreyferretLog($entityType);
588
+ if(is_null($this->greyId)) {
589
+ $model->setData($inputArray);
590
+ $insertId = $model->save()->getId();
591
+ } else {
592
+ $model->load($this->greyId)->addData($inputArray);
593
+ $model->setId($this->greyId)->save();
594
+ }
595
+ }
596
+ } catch (Exception $exc) {
597
+ return false;
598
+ }
599
+ }
600
+
601
+
602
+ /**
603
+ * Get the configuration from the given URI.
604
+ * @param string $entityType entity type
605
+ * @return string.
606
+ */
607
+ protected function selectGreyferretLog($entityType)
608
+ {
609
+ try {
610
+ $model = Mage::getModel('greyferret/api');
611
+ $collection = $model->getCollection($entityType);
612
+ $collection->addFieldToFilter('entityType', $entityType);
613
+ $inputLog = $collection->getData();
614
+ if(count($inputLog) > 0) {
615
+ $extractLog = call_user_func_array('array_merge', $inputLog);
616
+ $this->extractVar($extractLog);
617
+ } else {
618
+ $this->greyId=$this->entityType=$this->entityLastId=$this->entityStatus=null;
619
+ }
620
+ if(count($extractLog) > 0)
621
+ return true;
622
+ else
623
+ return false;
624
+ } catch (Exception $exc) {
625
+ return false;
626
+ }
627
+ }
628
+
629
+ /**
630
+ * Get the configuration from the given URI.
631
+ * @param string $entityType entity type
632
+ * @return string.
633
+ */
634
+ protected function readEntityId($entityType)
635
+ {
636
+ try {
637
+ $this->selectGreyferretLog($entityType);
638
+ return true;
639
+ } catch (Exception $exc) {
640
+ return false;
641
+ }
642
+ }
643
+
644
+ /**
645
+ * Get the configuration from the given URI.
646
+ * @param string $lastId last inserted id
647
+ * @param string $entityType entity type
648
+ * @return string.
649
+ */
650
+ protected function savePid($lastId,$entityType)
651
+ {
652
+ try {
653
+ $this->selectGreyferretLog($entityType);
654
+ $pid = is_null($this->entityId)?$lastId:$this->entityId.','.$lastId;
655
+ $this->saveLog($this->entityLastId,$this->entityType,$pid,$this->pending);
656
+ } catch (Exception $exc) {
657
+ return false;
658
+ }
659
+ }
660
+
661
+ /**
662
+ * Get the configuration from the given URI.
663
+ * @param array $paramArray
664
+ * @return string.
665
+ */
666
+ protected function extractVar($paramArray)
667
+ {
668
+ try {
669
+ foreach($paramArray as $key => $value) {
670
+ $this->$key = $value;
671
+ }
672
+ } catch (Exception $exc) {
673
+ return false;
674
+ }
675
+ }
676
+
677
+ /**
678
+ * Get the configuration from the given URI.
679
+ * @param string $customerId customer id
680
+ * @return string.
681
+ */
682
+ protected function findEmail($customerId)
683
+ {
684
+ try {
685
+ $customerData = $this->_userObj->load($customerId)->getData();
686
+ $email = $customerData['email'];
687
+ return $email;
688
+
689
+ } catch (Exception $exc) {
690
+ return false;
691
+ }
692
+ }
693
+ }
694
+
695
+
696
+
app/code/community/Lister/Greyferret/Model/Observer.php ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Repesents Lister_Greyferret Api.
4
+ *
5
+ * PHP version 5.5
6
+ *
7
+ * @category PHP
8
+ * @package Lister_Greyferret_Model_Observer
9
+ * @author info@listertechnologies.com
10
+ * @license General Public License
11
+ * @link https://greyferret.com/
12
+ */
13
+
14
+ class Lister_Greyferret_Model_Observer extends Lister_Greyferret_Model_Api
15
+ {
16
+
17
+ /**
18
+ * Get customer details.
19
+ * @param object $observer customer event observer.
20
+ * @return string
21
+ */
22
+ public function getCustomer(Varien_Event_Observer $observer)
23
+ {
24
+ $option = explode(',', $this->categoryList);
25
+ if (in_array("1", $option)) {
26
+ if(get_class($observer->getCustomerAddress()) == 'Mage_Customer_Model_Address') {
27
+ $address = $observer->getCustomerAddress()->getData();
28
+ if($address['is_default_billing'] == true) {
29
+ $customerArray[] = $this->createCustomerArray($address);
30
+ $response = $this->getCall($customerArray, $this->customerEntity);
31
+ return $response;
32
+ }
33
+ }
34
+ } else {
35
+ Mage::log('Customer endpoint not selected for greyferret', null, self::LOGFILE);
36
+ return false;
37
+ }
38
+ }
39
+
40
+ /**
41
+ * Get category details.
42
+ * @param object $observer category event observer.
43
+ * @return string
44
+ */
45
+ public function getCategory(Varien_Event_Observer $observer)
46
+ {
47
+ $option = explode(',', $this->categoryList);
48
+ if (in_array("2", $option)) {
49
+ $categoryArray = array();
50
+ $category = $observer->getEvent()->getDataObject();
51
+ $categoryArray = $this->createCategoryArray($category);
52
+ $response = $this->getCall($categoryArray, $this->catalogEntity);
53
+ return $response;
54
+ } else {
55
+ Mage::log('Category endpoint not selected for greyferret', null, self::LOGFILE);
56
+ return false;
57
+ }
58
+ }
59
+
60
+ /**
61
+ * Get Order details.
62
+ * @param object $observer order event observer.
63
+ * @return string
64
+ */
65
+ public function getOrder(Varien_Event_Observer $observer)
66
+ {
67
+ $option = explode(',', $this->categoryList);
68
+ if (in_array("3", $option)) {
69
+ $orderArray = array();
70
+ $order = $observer->getEvent()->getData('order');
71
+ if ($order->getState() == Mage_Sales_Model_Order::STATE_COMPLETE) {
72
+ $orderArray[] = $this->createOrderArray($order);
73
+ $response = $this->getCall($orderArray, $this->orderEntity);
74
+ return $response;
75
+ } else {
76
+ return false;
77
+ }
78
+ } else {
79
+ Mage::log('Order endpoint not selected for greyferret', null, self::LOGFILE);
80
+ return false;
81
+ }
82
+ }
83
+
84
+ /**
85
+ * Runs the api call.
86
+ * @param array $inputArray Input array send to greyferret.
87
+ * @param boolean $type If true, send bulk list.
88
+ * @return string.
89
+ */
90
+ public function getCall($inputArray,$type)
91
+ {
92
+ if ($this->apiState == 'Completed') {
93
+ $response = $this->call($inputArray, $type,false);
94
+ return $response;
95
+ } else {
96
+ return false;
97
+ }
98
+ }
99
+ }
app/code/community/Lister/Greyferret/Model/Resource/Api.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Repesents Lister_Greyferret Api.
4
+ *
5
+ * PHP version 5.5
6
+ *
7
+ * @category PHP
8
+ * @package Lister_Greyferret_Model_Resource_Api
9
+ * @author info@listertechnologies.com
10
+ * @license General Public License
11
+ * @link https://greyferret.com/
12
+ */
13
+
14
+ class Lister_Greyferret_Model_Resource_Api extends Mage_Core_Model_Resource_Db_Abstract
15
+ {
16
+ /**
17
+ * Initialize resource model
18
+ *
19
+ * @return void
20
+ */
21
+ public function _construct()
22
+ {
23
+ $this->_init('greyferret/api', 'greyId');
24
+
25
+ }
26
+ }
app/code/community/Lister/Greyferret/Model/Resource/Api/Collection.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Repesents Lister_Greyferret Api.
5
+ *
6
+ * PHP version 5.5
7
+ *
8
+ * @category PHP
9
+ * @package Lister_Greyferret_Model_Resource_Api_Collection
10
+ * @author info@listertechnologies.com
11
+ * @license General Public License
12
+ * @link https://greyferret.com/
13
+ */
14
+
15
+ class Lister_Greyferret_Model_Resource_Api_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
16
+ {
17
+ /**
18
+ * Initialize resource model
19
+ *
20
+ * @return void
21
+ */
22
+ public function _construct()
23
+ {
24
+ $this->_init('greyferret/api');
25
+ }
26
+ }
app/code/community/Lister/Greyferret/etc/config.xml ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <modules>
4
+ <Lister_Greyferret>
5
+ <version>0.0.1</version>
6
+ </Lister_Greyferret>
7
+ </modules>
8
+ <global>
9
+ <helpers>
10
+ <greyferret>
11
+ <class>Lister_Greyferret_Helper</class>
12
+ </greyferret>
13
+ </helpers>
14
+ <models>
15
+ <greyferret>
16
+ <class>Lister_Greyferret_Model</class>
17
+ <resourceModel>greyferret_resource</resourceModel>
18
+ </greyferret>
19
+ <greyferret_resource>
20
+ <class>Lister_Greyferret_Model_Resource</class>
21
+ <entities>
22
+ <api>
23
+ <table>greyferret_api</table>
24
+ </api>
25
+ </entities>
26
+ </greyferret_resource>
27
+ </models>
28
+ <resources>
29
+ <greyferret_setup>
30
+ <setup>
31
+ <module>Lister_Greyferret</module>
32
+ </setup>
33
+ <connection>
34
+ <use>core_setup</use>
35
+ </connection>
36
+ </greyferret_setup>
37
+ <greyferret_read>
38
+ <connection>
39
+ <use>core_read</use>
40
+ </connection>
41
+ </greyferret_read>
42
+ <greyferret_write>
43
+ <connection>
44
+ <use>core_write</use>
45
+ </connection>
46
+ </greyferret_write>
47
+ </resources>
48
+ <blocks>
49
+ <greyferret>
50
+ <class>Lister_Greyferret_Block</class>
51
+ </greyferret>
52
+ </blocks>
53
+ <events>
54
+ <catalog_category_save_commit_after>
55
+ <observers>
56
+ <greyferret_savecategory>
57
+ <type>singleton</type>
58
+ <class>Lister_Greyferret_Model_Observer</class>
59
+ <method>getCategory</method>
60
+ </greyferret_savecategory>
61
+ </observers>
62
+ </catalog_category_save_commit_after>
63
+ <sales_order_save_commit_after>
64
+ <observers>
65
+ <greyferret_saveorder>
66
+ <type>singleton</type>
67
+ <class>Lister_Greyferret_Model_Observer</class>
68
+ <method>getOrder</method>
69
+ </greyferret_saveorder>
70
+ </observers>
71
+ </sales_order_save_commit_after>
72
+ <customer_address_save_commit_after>
73
+ <observers>
74
+ <greyferret_customer_contact>
75
+ <type>singleton</type>
76
+ <class>Lister_Greyferret_Model_Observer</class>
77
+ <method>getCustomer</method>
78
+ </greyferret_customer_contact>
79
+ </observers>
80
+ </customer_address_save_commit_after>
81
+ <adminhtml_customer_save_after>
82
+ <observers>
83
+ <greyferret_save_account_admin>
84
+ <type>singleton</type>
85
+ <class>Lister_Greyferret_Model_Observer</class>
86
+ <method>getCustomer</method>
87
+ </greyferret_save_account_admin>
88
+ </observers>
89
+ </adminhtml_customer_save_after>
90
+ </events>
91
+ </global>
92
+ <frontend>
93
+ <routers>
94
+ <greyferret>
95
+ <use>standard</use>
96
+ <args>
97
+ <module>Lister_Greyferret</module>
98
+ <frontName>greyferret</frontName>
99
+ </args>
100
+ </greyferret>
101
+ </routers>
102
+ </frontend>
103
+ <adminhtml>
104
+ <acl>
105
+ <resources>
106
+ <admin>
107
+ <children>
108
+ <system>
109
+ <children>
110
+ <config>
111
+ <children>
112
+ <greyferret_options>
113
+ <title>Store Greyferret Configurations</title>
114
+ </greyferret_options>
115
+ </children>
116
+ </config>
117
+ </children>
118
+ </system>
119
+ </children>
120
+ </admin>
121
+ </resources>
122
+ </acl>
123
+ </adminhtml>
124
+ <crontab>
125
+ <jobs>
126
+ <greyferret_cron>
127
+ <schedule>
128
+ <cron_expr></cron_expr>
129
+ </schedule>
130
+ <run>
131
+ <model>greyferret/api::run</model>
132
+ </run>
133
+ </greyferret_cron>
134
+ </jobs>
135
+ </crontab>
136
+ <default>
137
+ <greyferret_options>
138
+ <configurable_cron>
139
+ <greyferret_timeout>30</greyferret_timeout>
140
+ <greyferret_state>Deactivate</greyferret_state>
141
+ </configurable_cron>
142
+ </greyferret_options>
143
+ </default>
144
+ </config>
app/code/community/Lister/Greyferret/etc/system.xml ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <tabs>
4
+ <greyferretconfig translate="label" module="greyferret">
5
+ <label>Lister API</label>
6
+ <sort_order>999999</sort_order>
7
+ </greyferretconfig>
8
+ </tabs>
9
+ <sections>
10
+ <greyferret_options translate="label" module="greyferret">
11
+ <label>Greyferret</label>
12
+ <tab>greyferretconfig</tab>
13
+ <frontend_type>text</frontend_type>
14
+ <sort_order>1000</sort_order>
15
+ <show_in_default>1</show_in_default>
16
+ <show_in_website>1</show_in_website>
17
+ <show_in_store>1</show_in_store>
18
+ <groups>
19
+ <configurable_cron translate="label">
20
+ <label>Greyferret Cron Schedule</label>
21
+ <frontend_type>text</frontend_type>
22
+ <sort_order>1</sort_order>
23
+ <show_in_default>1</show_in_default>
24
+ <show_in_website>1</show_in_website>
25
+ <show_in_store>1</show_in_store>
26
+ <fields>
27
+ <greyferret_api_url>
28
+ <label>Api URL</label>
29
+ <frontend_type>text</frontend_type>
30
+ <validate>required-entry validate-url </validate>
31
+ <sort_order>1</sort_order>
32
+ <show_in_default>1</show_in_default>
33
+ <show_in_website>1</show_in_website>
34
+ <show_in_store>1</show_in_store>
35
+ </greyferret_api_url>
36
+ <greyferret_use_name>
37
+ <label>User Name</label>
38
+ <frontend_type>text</frontend_type>
39
+ <validate>required-entry</validate>
40
+ <sort_order>2</sort_order>
41
+ <show_in_default>1</show_in_default>
42
+ <show_in_website>1</show_in_website>
43
+ <show_in_store>1</show_in_store>
44
+ </greyferret_use_name>
45
+ <greyferret_api_key>
46
+ <label>Password</label>
47
+ <frontend_type>password</frontend_type>
48
+ <validate>required-entry</validate>
49
+ <backend_model>adminhtml/system_config_backend_encrypted</backend_model>
50
+ <sort_order>3</sort_order>
51
+ <show_in_default>1</show_in_default>
52
+ <show_in_website>1</show_in_website>
53
+ <show_in_store>1</show_in_store>
54
+ </greyferret_api_key>
55
+ <greyferret_timeout>
56
+ <label>Timeout</label>
57
+ <frontend_type>text</frontend_type>
58
+ <validate>required-entry validate-number</validate>
59
+ <sort_order>4</sort_order>
60
+ <show_in_default>1</show_in_default>
61
+ <show_in_website>1</show_in_website>
62
+ <show_in_store>1</show_in_store>
63
+ </greyferret_timeout>
64
+ <greyferret_cron>
65
+ <label>Cron</label>
66
+ <frontend_type>select</frontend_type>
67
+ <source_model>adminhtml/system_config_source_yesno</source_model>
68
+ <sort_order>5</sort_order>
69
+ <show_in_default>1</show_in_default>
70
+ <show_in_website>1</show_in_website>
71
+ <show_in_store>1</show_in_store>
72
+ </greyferret_cron>
73
+ <greyferret_time>
74
+ <label>Cron time</label>
75
+ <frontend_type>time</frontend_type>
76
+ <sort_order>6</sort_order>
77
+ <show_in_default>1</show_in_default>
78
+ <show_in_website>1</show_in_website>
79
+ <show_in_store>1</show_in_store>
80
+ </greyferret_time>
81
+ <greyferret_date>
82
+ <label>Cron Date</label>
83
+ <frontend_type>text</frontend_type>
84
+ <validate>required-entry validate-date</validate>
85
+ <frontend_model>greyferret/adminhtml_system_config_date</frontend_model>
86
+ <backend_model>greyferret/adminhtml_system_config_cron_schedule</backend_model>
87
+ <sort_order>7</sort_order>
88
+ <show_in_default>1</show_in_default>
89
+ <show_in_website>1</show_in_website>
90
+ <show_in_store>1</show_in_store>
91
+ </greyferret_date>
92
+ <greyferret_list>
93
+ <label>Category</label>
94
+ <frontend_type>multiselect</frontend_type>
95
+ <validate>required-entry validate-select</validate>
96
+ <source_model>greyferret/adminhtml_system_config_category_list</source_model>
97
+ <comment><![CDATA[<script type="text/javascript">document.getElementById('greyferret_options_configurable_cron_greyferret_list').size =4;</script><script type="text/javascript">jQuery.noConflict();</script>]]></comment>
98
+ <sort_order>8</sort_order>
99
+ <show_in_default>1</show_in_default>
100
+ <show_in_website>1</show_in_website>
101
+ <show_in_store>1</show_in_store>
102
+ </greyferret_list>
103
+ <greyferret_debug>
104
+ <label>Debug Mode</label>
105
+ <frontend_type>select</frontend_type>
106
+ <source_model>adminhtml/system_config_source_yesno</source_model>
107
+ <sort_order>9</sort_order>
108
+ <show_in_default>1</show_in_default>
109
+ <show_in_website>1</show_in_website>
110
+ <show_in_store>1</show_in_store>
111
+ </greyferret_debug>
112
+ <greyferret_state>
113
+ <label>Status</label>
114
+ <frontend_type>label</frontend_type>
115
+ <sort_order>10</sort_order>
116
+ <show_in_default>1</show_in_default>
117
+ <show_in_website>1</show_in_website>
118
+ <show_in_store>1</show_in_store>
119
+ </greyferret_state>
120
+ </fields>
121
+ </configurable_cron>
122
+ </groups>
123
+ </greyferret_options>
124
+ </sections>
125
+ </config>
app/code/community/Lister/Greyferret/sql/greyferret_setup/install-0.0.1.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $installer=$this;
3
+ $installer->startSetup();
4
+ $installer->run("
5
+ -- DROP TABLE IF EXISTS {$this->getTable('greyferret_api')};
6
+ CREATE TABLE {$this->getTable('greyferret_api')} (
7
+ `greyId` INT NOT NULL AUTO_INCREMENT,
8
+ `entityLastId` VARCHAR(45) NULL ,
9
+ `entityType` VARCHAR(10) NULL ,
10
+ `entityId` VARCHAR(10872) NULL ,
11
+ `entityStatus` VARCHAR(45) NULL ,
12
+ PRIMARY KEY (`greyId`)
13
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
14
+ ");
15
+ $installer->endSetup();
16
+ ?>
app/etc/modules/Lister_Greyferret.xml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Lister_Greyferret>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </Lister_Greyferret>
8
+ </modules>
9
+ </config>
10
+
package.xml ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Lister_Greyferret</name>
4
+ <version>0.0.1</version>
5
+ <stability>stable</stability>
6
+ <license>General Public License (GPL)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Greyferret is designed to offer e-tailers an edge by helping marketers achieve their critical marketing goals i.e Customer Retention, Acquisition &amp; Sales Uplift</summary>
10
+ <description> &#x2022; Segmentation Intelligence using Customer behavioural data&#xD;
11
+ o Use Behavioral data from your Magento Store to understand your customers using real time data. Drive your marketing campaigns by understanding your customer based on how they have purchased and how they have engaged with you&#xD;
12
+ &#x2022; Actionable insights using Customer Profiling, RFM Clustering &amp; Advanced Analytics&#xD;
13
+ o Greyferret helps you profile your customers based key criteria such as gender, location, purchase history, frequency of purchases, SKUs purchased and engagement on email just to name a few.&#xD;
14
+ o Based on this segmentation criteria, you can identify the right cohorts and apply the right marketing strategy that helps in retention programs, loyalty marketing and cross/upsell programs.&#xD;
15
+ o As an example, imagine Cathy, who lives in Cleveland Ohio has been a regular customer and she has made several medium value purchases regularly over the last 18 months. Using Greyferret helps you identify this behavior and reward her with free shipping options that will delight her and increase her loyalty towards your store. &#xD;
16
+ &#x2022; Bi-directional integration with Marketing platforms&#xD;
17
+ o Once you know your segment, you are just one step away from sending the right personalized campaign through the email service provider of your choice. Currently Greyferret integrates with MailChimp and integrations with other major email tools are coming soon</description>
18
+ <notes>Initial Stable release</notes>
19
+ <authors><author><name>Lister Technologies (P) Ltd</name><user>Lister</user><email>info@listertechnologies.com</email></author></authors>
20
+ <date>2015-07-02</date>
21
+ <time>12:25:57</time>
22
+ <contents><target name="magecommunity"><dir name="Lister"><dir name="Greyferret"><dir name="Block"><dir name="Adminhtml"><dir name="System"><dir name="Config"><file name="Date.php" hash="9833c2f5876d82e424644605a817fde7"/></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="281a133d262533ecf4d5e01359fcf4fc"/></dir><dir name="Model"><dir name="Adminhtml"><dir name="System"><dir name="Config"><dir name="Category"><file name="List.php" hash="7004f22b892e2c30553d19abcf495639"/></dir><dir name="Cron"><file name="Schedule.php" hash="364bc51d39c4b8db3bb5fd8fa07b7a52"/></dir></dir></dir></dir><file name="Api.php" hash="34d96bafbe153725975cc05d22a6108f"/><file name="Observer.php" hash="575325822f389b779fe4235fd49b537f"/><dir name="Resource"><dir name="Api"><file name="Collection.php" hash="981e11f094a2c984b41a8af53c9f7f69"/></dir><file name="Api.php" hash="af980d553f39c98549224a3cb6a95e56"/></dir></dir><dir name="etc"><file name="config.xml" hash="870656cf0530ae55420a77ba1f51070d"/><file name="system.xml" hash="2fcaa06eaf617e67fde643fec4d818d1"/></dir><dir name="sql"><dir name="greyferret_setup"><file name="install-0.0.1.php" hash="92821c43bfe5e69846f661d8ad828d4c"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Lister_Greyferret.xml" hash="828e4ee56d06860ac2f415a9814b6ca9"/></dir></target></contents>
23
+ <compatible/>
24
+ <dependencies><required><php><min>5.1.0</min><max>5.6.9</max></php></required></dependencies>
25
+ </package>