Shopferret_Shopferretxmlimport - Version 0.1.0

Version Notes

This is first version of the package

Download this release

Release Info

Developer Shop
Extension Shopferret_Shopferretxmlimport
Version 0.1.0
Comparing to
See all releases


Version 0.1.0

app/code/local/Shopferret/Shopferretxmlimport/Block/Index.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Shopferret_Shopferretxmlimport_Block_Index extends Mage_Core_Block_Template{
3
+
4
+
5
+
6
+
7
+
8
+ }
app/code/local/Shopferret/Shopferretxmlimport/Helper/Data.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+ class Shopferret_Shopferretxmlimport_Helper_Data extends Mage_Core_Helper_Abstract
3
+ {
4
+ }
5
+
app/code/local/Shopferret/Shopferretxmlimport/Model/Cron.php ADDED
@@ -0,0 +1,340 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Shopferret_Shopferretxmlimport_Model_Cron{
3
+
4
+ // this function is used to make entry of the products into the tbl_shopferret_product . On each run it will import the 1000 products at a time.
5
+ public function index(){
6
+ ini_set("memory_limit", '1064M');
7
+ ini_set("max_execution_time", '0');
8
+ $tableNameStatus = Mage::getSingleton("core/resource")->getTableName("tbl_shopferret_status");
9
+ $tableNameProducts = Mage::getSingleton("core/resource")->getTableName("tbl_shopferret_product");
10
+
11
+ $connection = Mage::getSingleton('core/resource')->getConnection('core_write');
12
+
13
+ $selectStatus = $connection->select()->from($tableNameStatus, array('*'));
14
+ $rowArrayStatus = $connection->fetchRow($selectStatus); //return row
15
+
16
+
17
+ $resource = Mage::getSingleton('core/resource');
18
+ $readConnection = $resource->getConnection('core_read');
19
+ $table = $resource->getTableName('core_config_data');
20
+ $query = 'SELECT value FROM ' . $table . ' WHERE path = "web/secure/base_url" LIMIT 1';
21
+ $url = $readConnection->fetchOne($query);
22
+ $LoSXMLData = base64_encode($url);
23
+
24
+
25
+ $LoILastProductId = 0;
26
+ if(isset($rowArrayStatus['last_inserted_id']) && $rowArrayStatus['last_inserted_id'] != ""){
27
+ $LoILastProductId = $rowArrayStatus['last_inserted_id'];
28
+ }else{
29
+ $connection->beginTransaction();
30
+ $__fields = array();
31
+ $__fields['last_inserted_id'] = '0';
32
+ $connection->insert($tableNameStatus, $__fields);
33
+ $connection->commit();
34
+ }
35
+ // it is fetching the 1000 product from the last entry made into tbl_shopferret_status table
36
+ $products = Mage::getModel('catalog/product')
37
+ ->getCollection()
38
+ ->setPageSize(100)
39
+ ->addAttributeToSelect('entity_id')
40
+ ->addAttributeToSelect('sku')
41
+ ->addAttributeToSelect('name')
42
+ ->addAttributeToSelect('image')
43
+ ->addAttributeToSelect('small_image')
44
+ ->addAttributeToSelect('thumbnail')
45
+ ->addAttributeToSelect('url_key')
46
+ ->addAttributeToSelect('shipping_delivery')
47
+ ->addAttributeToSelect('shipping_weight')
48
+ ->addAttributeToSelect('alu')
49
+ ->addAttributeToSelect('upsize')
50
+ ->addAttributeToSelect('price')
51
+ ->addAttributeToSelect('special_price')
52
+ ->addAttributeToSelect('color')
53
+ ->addAttributeToSelect('status')
54
+ ->addAttributeToSelect('gender')
55
+ ->addAttributeToSelect('size')
56
+ ->addAttributeToSelect('brand')
57
+ ->addAttributeToSelect('description')
58
+ ->addAttributeToSelect('qty')
59
+ ->addAttributeToSelect('is_in_stock')
60
+ ->addAttributeToFilter('status', array('eq' => '1'))
61
+ ->addAttributeToFilter('type_id', array('eq' => 'simple'))
62
+ ->addAttributeToFilter('entity_id', array('gt' => $LoILastProductId));
63
+
64
+ $LoIStatusRecord = 0;
65
+ foreach($products as $_product){
66
+ $LoIStatusRecord = 1;
67
+ // collecting all the required details used at shopfeert site
68
+ $__fields = array();
69
+
70
+ $__fields['entity_id'] = $_product->getentity_id();
71
+ $__fields['sku'] = $_product->getSku();
72
+ $__fields['name'] = $_product->getName();
73
+ $__fields['image'] = trim(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'catalog/product' . $_product->getData('image'));
74
+ $__fields['small_image'] = trim(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'catalog/product' . $_product->getData('small_image'));
75
+ $__fields['thumbnail'] = trim(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'catalog/product' . $_product->getData('thumbnail'));
76
+ $__fields['url_key'] = trim($this->getCustomProductUrl($_product));
77
+ $__fields['shipping_delivery'] = trim($_product->getShippingDelivery());
78
+ $__fields['shipping_weight'] = trim($_product->getShippingWeight());
79
+ $__fields['alu'] = trim($_product->getAlu());
80
+ $__fields['upsize'] = trim($_product->getUpsize());
81
+ $__fields['price'] = (($_product->getSpecialPrice()== "")?trim($_product->getPrice()):$_product->getSpecialPrice());
82
+ $__fields['special_price'] = (($_product->getSpecialPrice()== "")?trim($_product->getPrice()):$_product->getSpecialPrice());
83
+ $__fields['color'] = trim($_product->getResource()->getAttribute('color')->getFrontend()->getValue($_product));
84
+ $__fields['status'] = trim($_product->getResource()->getAttribute('status')->getFrontend()->getValue($_product));
85
+ if($_product->getResource()->getAttribute('gender'))
86
+ $__fields['gender'] = trim($_product->getResource()->getAttribute('gender')->getFrontend()->getValue($_product));
87
+ else
88
+ $__fields['gender'] = "";
89
+
90
+ if($_product->getResource()->getAttribute('size'))
91
+ $__fields['size'] = trim($_product->getResource()->getAttribute('size')->getFrontend()->getValue($_product));
92
+ else
93
+ $__fields['size'] = "";
94
+
95
+ if($_product->getResource()->getAttribute('brand'))
96
+ $__fields['brand'] = trim($_product->getAttributeText('brand'));
97
+ else
98
+ $__fields['brand'] = "";
99
+ $__fields['description'] = trim($_product->getDescription());
100
+ $__fields['qty'] = trim(Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty());
101
+ $__fields['is_in_stock'] = trim(Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getIsInStock());
102
+
103
+ $cats = $_product->getCategoryIds();
104
+ $LoSCategory = "";
105
+ foreach ($cats as $category_id) {
106
+ $_cat = Mage::getModel('catalog/category')->load($category_id) ;
107
+ $LoSCategory .= ($LoSCategory != "")? "###":"";
108
+ $LoSCategory .= $_cat->getName();
109
+ }
110
+ if($LoSCategory == ""){
111
+ $LoSCategory = "Default";
112
+ }
113
+ $__fields['category'] = trim($LoSCategory);
114
+ // insert the data at the tbl_shopferret_product table
115
+ $connection->beginTransaction();
116
+ $selectIsExists = $connection->select()->from($tableNameProducts, array('*'))->where('entity_id=?',$__fields['entity_id']);
117
+ $rowArrayExists = $connection->fetchRow($selectIsExists); //return row
118
+ $LoILastId = $__fields['entity_id'];
119
+ if(isset($rowArrayExists['shopferret_product_id']) && $rowArrayExists['shopferret_product_id'] != ""){
120
+ $__where = $connection->quoteInto('shopferret_product_id =?', $rowArrayExists['shopferret_product_id']);
121
+ $connection->update($tableNameProducts, $__fields, $__where);
122
+ }else{
123
+ $connection->insert($tableNameProducts, $__fields);
124
+ }
125
+ $connection->commit();
126
+
127
+ $connection->beginTransaction();
128
+ $__fieldsInsertion = array();
129
+ $__fieldsInsertion['last_inserted_id'] = $LoILastId;
130
+ $connection->update($tableNameStatus, $__fieldsInsertion);
131
+ $connection->commit();
132
+
133
+ file_get_contents( "http://www.shopferret.com.au/notifier.php?url=" . $LoSXMLData . "&action=addupdateproduct&productid=" . $__fields['entity_id']);
134
+ }
135
+ }
136
+
137
+ /*
138
+ This function is getting the product url baased upon its store. If there are multiple store at site then it will get the url based on the product associated with store.
139
+ */
140
+
141
+ public function getCustomProductUrl($product, $additional = array()) {
142
+
143
+ if ($product->getProductUrl()) {
144
+ $pstore_id = array_shift(array_values($product->getStoreIds()));
145
+ if(Mage::app()->getStore()->getStoreId() == $pstore_id){
146
+ $purl = $product->getUrlModel()->getUrl($product, $additional);
147
+ }else{
148
+ $productnew= Mage::getModel('catalog/product')->setStoreId($pstore_id)->load($product->getentity_id());
149
+ $purl = $productnew->getProductUrl();
150
+ }
151
+ if (!isset($additional['_escape'])) {
152
+ $additional['_escape'] = true;
153
+ }
154
+ return $purl;
155
+ }
156
+ return '#';
157
+
158
+ }
159
+
160
+ /*
161
+ cron run once a day at 5th minute of the night (00:05 PM) And it will get all the product whose special price start date is today or whose special price end date is yesterday and it will update the product prices at shopferret site.
162
+ */
163
+
164
+ public function discountindex(){
165
+
166
+ $product = Mage::getModel('catalog/product');
167
+ // getting all the product whose special price data is of today
168
+ $todayDate = date("Y-m-d", time());
169
+ $yesterdayDate = date("Y-m-d", mktime(0, 0, 0, date('m'), date('d')-1, date('y')));
170
+ $products = $product->getCollection()
171
+ ->addAttributeToSelect('entity_id')
172
+ ->addAttributeToSelect('sku')
173
+ ->addAttributeToSelect('name')
174
+ ->addAttributeToSelect('image')
175
+ ->addAttributeToSelect('small_image')
176
+ ->addAttributeToSelect('thumbnail')
177
+ ->addAttributeToSelect('url_key')
178
+ ->addAttributeToSelect('shipping_delivery')
179
+ ->addAttributeToSelect('shipping_weight')
180
+ ->addAttributeToSelect('alu')
181
+ ->addAttributeToSelect('upsize')
182
+ ->addAttributeToSelect('price')
183
+ ->addAttributeToSelect('special_price')
184
+ ->addAttributeToSelect('color')
185
+ ->addAttributeToSelect('status')
186
+ ->addAttributeToSelect('gender')
187
+ ->addAttributeToSelect('size')
188
+ ->addAttributeToSelect('brand')
189
+ ->addAttributeToSelect('description')
190
+ ->addAttributeToSelect('qty')
191
+ ->addAttributeToSelect('is_in_stock')
192
+ ->addAttributeToFilter('special_from_date', array('date'=>true, 'from'=> $todayDate))
193
+ ->addAttributeToFilter('status', array('eq' => '1'))
194
+ ->addAttributeToFilter('type_id', array('eq' => 'simple'));
195
+
196
+ foreach($products as $_product){
197
+ // it will update the product at this module table and as well as into the shopferret site
198
+ $this->productActionsUpdateCron($_product);
199
+ }
200
+
201
+ // getting all the product whose special price end data is of yesterday
202
+
203
+ $products = $product->getCollection()
204
+ ->addAttributeToSelect('entity_id')
205
+ ->addAttributeToSelect('sku')
206
+ ->addAttributeToSelect('name')
207
+ ->addAttributeToSelect('image')
208
+ ->addAttributeToSelect('small_image')
209
+ ->addAttributeToSelect('thumbnail')
210
+ ->addAttributeToSelect('url_key')
211
+ ->addAttributeToSelect('shipping_delivery')
212
+ ->addAttributeToSelect('shipping_weight')
213
+ ->addAttributeToSelect('alu')
214
+ ->addAttributeToSelect('upsize')
215
+ ->addAttributeToSelect('price')
216
+ ->addAttributeToSelect('special_price')
217
+ ->addAttributeToSelect('color')
218
+ ->addAttributeToSelect('status')
219
+ ->addAttributeToSelect('gender')
220
+ ->addAttributeToSelect('size')
221
+ ->addAttributeToSelect('brand')
222
+ ->addAttributeToSelect('description')
223
+ ->addAttributeToSelect('qty')
224
+ ->addAttributeToSelect('is_in_stock')
225
+ ->addAttributeToFilter('special_to_date', array('date'=>true, 'from'=> $yesterdayDate))
226
+ ->addAttributeToFilter('status', array('eq' => '1'))
227
+ ->addAttributeToFilter('type_id', array('eq' => 'simple'));
228
+
229
+ foreach($products as $_product){
230
+ // it will update the product at this module table and as well as into the shopferret site
231
+ $this->productActionsUpdateCron($_product);
232
+ }
233
+
234
+ }
235
+
236
+ // it will update the product at this module table and as well as into the shopferret site
237
+ public function productActionsUpdateCron( $_product){
238
+ if ($_product instanceof Mage_Catalog_Model_Product) {
239
+ $tableNameStatus = Mage::getSingleton("core/resource")->getTableName("tbl_shopferret_status");
240
+ $tableNameProducts = Mage::getSingleton("core/resource")->getTableName("tbl_shopferret_product");
241
+ $connection = Mage::getSingleton('core/resource')->getConnection('core_write');
242
+
243
+ $selectStatus = $connection->select()->from($tableNameStatus, array('*'));
244
+ $rowArrayStatus = $connection->fetchRow($selectStatus); //return row
245
+
246
+ if(isset($rowArrayStatus['last_inserted_id']) && $rowArrayStatus['last_inserted_id'] != ""){
247
+
248
+ }else{
249
+ $connection->beginTransaction();
250
+ $__fields = array();
251
+ $__fields['last_inserted_id'] = '0';
252
+ $connection->insert($tableNameStatus, $__fields);
253
+ $connection->commit();
254
+ }
255
+ // creating an arry of data regarding the product
256
+ $__fields = array();
257
+ $__fields['entity_id'] = $_product->getentity_id();
258
+ $__fields['sku'] = $_product->getSku();
259
+ $__fields['name'] = $_product->getName();
260
+ $__fields['image'] = trim(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'catalog/product' . $_product->getData('image'));
261
+ $__fields['small_image'] = trim(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'catalog/product' . $_product->getData('small_image'));
262
+ $__fields['thumbnail'] = trim(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'catalog/product' . $_product->getData('thumbnail'));
263
+ $__fields['url_key'] = trim($this->getCustomProductUrl($_product));
264
+ $__fields['shipping_delivery'] = trim($_product->getShippingDelivery());
265
+ $__fields['shipping_weight'] = trim($_product->getShippingWeight());
266
+ $__fields['alu'] = trim($_product->getAlu());
267
+ $__fields['upsize'] = trim($_product->getUpsize());
268
+ $__fields['price'] = (($_product->getSpecialPrice()== "")?trim($_product->getPrice()):$_product->getSpecialPrice());
269
+ $__fields['special_price'] = (($_product->getSpecialPrice()== "")?trim($_product->getPrice()):$_product->getSpecialPrice());
270
+ $__fields['color'] = trim($_product->getResource()->getAttribute('color')->getFrontend()->getValue($_product));
271
+ $__fields['status'] = trim($_product->getResource()->getAttribute('status')->getFrontend()->getValue($_product));
272
+ if($_product->getResource()->getAttribute('gender'))
273
+ $__fields['gender'] = trim($_product->getResource()->getAttribute('gender')->getFrontend()->getValue($_product));
274
+ else
275
+ $__fields['gender'] = "";
276
+
277
+ if($_product->getResource()->getAttribute('size'))
278
+ $__fields['size'] = trim($_product->getResource()->getAttribute('size')->getFrontend()->getValue($_product));
279
+ else
280
+ $__fields['size'] = "";
281
+
282
+ $__fields['brand'] = trim($_product->getAttributeText('brand'));
283
+ $__fields['description'] = trim($_product->getDescription());
284
+ $__fields['qty'] = trim(Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty());
285
+ $__fields['is_in_stock'] = trim(Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getIsInStock());
286
+
287
+ $cats = $_product->getCategoryIds();
288
+ $LoSCategory = "";
289
+ foreach ($cats as $category_id) {
290
+ $_cat = Mage::getModel('catalog/category')->load($category_id) ;
291
+ $LoSCategory .= ($LoSCategory != "")? "###":"";
292
+ $LoSCategory .= $_cat->getName();
293
+ }
294
+ if($LoSCategory == ""){
295
+ $LoSCategory = "Default";
296
+ }
297
+ $__fields['category'] = trim($LoSCategory);
298
+
299
+ $connection->beginTransaction();
300
+ $selectIsExists = $connection->select()->from($tableNameProducts, array('*'))->where('entity_id=?',$__fields['entity_id']);
301
+ $rowArrayExists = $connection->fetchRow($selectIsExists); //return row
302
+ $LoILastId = $__fields['entity_id'];
303
+ $LoIIsinserted = 0;
304
+ // updating the product into our existing table
305
+ if(isset($rowArrayExists['shopferret_product_id']) && $rowArrayExists['shopferret_product_id'] != ""){
306
+ $__where = $connection->quoteInto('shopferret_product_id =?', $rowArrayExists['shopferret_product_id']);
307
+ $connection->update($tableNameProducts, $__fields, $__where);
308
+ }else{
309
+ $connection->insert($tableNameProducts, $__fields);
310
+ $LoIIsinserted = 1;
311
+ }
312
+ $connection->commit();
313
+
314
+ if($LoIIsinserted == 1){
315
+ $connection->beginTransaction();
316
+ $__fieldsInsertion = array();
317
+ $__fieldsInsertion['last_inserted_id'] = $LoILastId;
318
+ $connection->update($tableNameStatus, $__fieldsInsertion);
319
+ $connection->commit();
320
+ }
321
+ $resource = Mage::getSingleton('core/resource');
322
+ $readConnection = $resource->getConnection('core_read');
323
+ $table = $resource->getTableName('core_config_data');
324
+ $query = 'SELECT value FROM ' . $table . ' WHERE path = "web/secure/base_url" LIMIT 1';
325
+ $url = $readConnection->fetchOne($query);
326
+ $LoSXMLData = base64_encode($url);
327
+ // updating the product at shopferret site.
328
+
329
+ $resource = Mage::getSingleton('core/resource');
330
+ $readConnection = $resource->getConnection('core_read');
331
+ $table = $resource->getTableName('core_config_data');
332
+ $query = 'SELECT value FROM ' . $table . ' WHERE path = "web/secure/base_url" LIMIT 1';
333
+ $url = $readConnection->fetchOne($query);
334
+ $LoSXMLData = base64_encode($url);
335
+ // making changes at the shopferret site.
336
+
337
+ file_get_contents( "http://www.shopferret.com.au/notifier.php?url=" . $LoSXMLData . "&action=addupdateproduct&productid=" . $__fields['entity_id']);
338
+ }
339
+ }
340
+ }
app/code/local/Shopferret/Shopferretxmlimport/Model/Observer.php ADDED
@@ -0,0 +1,177 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Shopferret_Shopferretxmlimport_Model_Observer{
3
+
4
+ public function addJavascriptBlock(Varien_Event_Observer $observer){
5
+ $controller = $observer->getAction();
6
+ $layout = $controller->getLayout();
7
+ $block = $layout->createBlock('core/text');
8
+ $block->setText(
9
+ '<script src="http://www.shopferret.com.au/flat-visual-chat/flat-visual-chat.js"></script>'
10
+ );
11
+ $layout->getBlock('head')->append($block);
12
+ }
13
+
14
+ //Whenever there is generate of sale order this observer is called
15
+
16
+ public function orderActionsUpdate(Varien_Event_Observer $observer){
17
+ // fetching the generated order details
18
+ $order = $observer->getEvent()->getOrder();
19
+ $resource = Mage::getSingleton('core/resource');
20
+ $readConnection = $resource->getConnection('core_read');
21
+ $table = $resource->getTableName('core_config_data');
22
+ $query = 'SELECT value FROM ' . $table . ' WHERE path = "web/secure/base_url" LIMIT 1';
23
+ $url = $readConnection->fetchOne($query);
24
+ $LoSXMLData = base64_encode($url);
25
+ // sending the details at shopferret site.
26
+ //$LoSData = file_get_contents( "http://shop.shopferret.com.au/wp-content/plugins/compare-plus-sales/compareplussalecron.php?url=" . $LoSXMLData);
27
+ }
28
+
29
+ //This observer is used whenever there is any change in the product and any change in product status
30
+
31
+ public function productActionsUpdate(Varien_Event_Observer $observer){
32
+ $_product = $observer->getEvent()->getProduct();
33
+ if ($_product instanceof Mage_Catalog_Model_Product) {
34
+ // feteching the updated order details
35
+ $tableNameStatus = Mage::getSingleton("core/resource")->getTableName("tbl_shopferret_status");
36
+ $tableNameProducts = Mage::getSingleton("core/resource")->getTableName("tbl_shopferret_product");
37
+ $connection = Mage::getSingleton('core/resource')->getConnection('core_write');
38
+
39
+ $selectStatus = $connection->select()->from($tableNameStatus, array('*'));
40
+ $rowArrayStatus = $connection->fetchRow($selectStatus); //return row
41
+
42
+ if(isset($rowArrayStatus['last_inserted_id']) && $rowArrayStatus['last_inserted_id'] != ""){
43
+
44
+ }else{
45
+ $connection->beginTransaction();
46
+ $__fields = array();
47
+ $__fields['last_inserted_id'] = '0';
48
+ $connection->insert($tableNameStatus, $__fields);
49
+ $connection->commit();
50
+ }
51
+
52
+ $__fields = array();
53
+ $__fields['entity_id'] = $_product->getentity_id();
54
+ $__fields['sku'] = $_product->getSku();
55
+ $__fields['name'] = $_product->getName();
56
+ $__fields['image'] = trim(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'catalog/product' . $_product->getData('image'));
57
+ $__fields['small_image'] = trim(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'catalog/product' . $_product->getData('small_image'));
58
+ $__fields['thumbnail'] = trim(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'catalog/product' . $_product->getData('thumbnail'));
59
+ $__fields['url_key'] = trim($this->getCustomProductUrl($_product));
60
+ $__fields['shipping_delivery'] = trim($_product->getShippingDelivery());
61
+ $__fields['shipping_weight'] = trim($_product->getShippingWeight());
62
+ $__fields['alu'] = trim($_product->getAlu());
63
+ $__fields['upsize'] = trim($_product->getUpsize());
64
+ $__fields['price'] = (($_product->getSpecialPrice()== "")?trim($_product->getPrice()):$_product->getSpecialPrice());
65
+ $__fields['special_price'] = (($_product->getSpecialPrice()== "")?trim($_product->getPrice()):$_product->getSpecialPrice());
66
+ $__fields['color'] = trim($_product->getResource()->getAttribute('color')->getFrontend()->getValue($_product));
67
+ $__fields['status'] = trim($_product->getResource()->getAttribute('status')->getFrontend()->getValue($_product));
68
+ if($_product->getResource()->getAttribute('gender'))
69
+ $__fields['gender'] = trim($_product->getResource()->getAttribute('gender')->getFrontend()->getValue($_product));
70
+ else
71
+ $__fields['gender'] = "";
72
+
73
+ if($_product->getResource()->getAttribute('size'))
74
+ $__fields['size'] = trim($_product->getResource()->getAttribute('size')->getFrontend()->getValue($_product));
75
+ else
76
+ $__fields['size'] = "";
77
+
78
+ if($_product->getResource()->getAttribute('brand'))
79
+ $__fields['brand'] = trim($_product->getAttributeText('brand'));
80
+ else
81
+ $__fields['brand'] = "";
82
+ $__fields['description'] = trim($_product->getDescription());
83
+ $__fields['qty'] = trim(Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty());
84
+ $__fields['is_in_stock'] = trim(Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getIsInStock());
85
+
86
+ $cats = $_product->getCategoryIds();
87
+ $LoSCategory = "";
88
+ foreach ($cats as $category_id) {
89
+ $_cat = Mage::getModel('catalog/category')->load($category_id) ;
90
+ $LoSCategory .= ($LoSCategory != "")? "###":"";
91
+ $LoSCategory .= $_cat->getName();
92
+ }
93
+ if($LoSCategory == ""){
94
+ $LoSCategory = "Default";
95
+ }
96
+ $__fields['category'] = trim($LoSCategory);
97
+
98
+ $connection->beginTransaction();
99
+ $selectIsExists = $connection->select()->from($tableNameProducts, array('*'))->where('entity_id=?',$__fields['entity_id']);
100
+ $rowArrayExists = $connection->fetchRow($selectIsExists); //return row
101
+ $LoILastId = $__fields['entity_id'];
102
+ $LoIIsinserted = 0;
103
+ // doing changes into this module file.
104
+ if(isset($rowArrayExists['shopferret_product_id']) && $rowArrayExists['shopferret_product_id'] != ""){
105
+ $__where = $connection->quoteInto('shopferret_product_id =?', $rowArrayExists['shopferret_product_id']);
106
+ $connection->update($tableNameProducts, $__fields, $__where);
107
+ }else{
108
+ $connection->insert($tableNameProducts, $__fields);
109
+ $LoIIsinserted = 1;
110
+ }
111
+ $connection->commit();
112
+
113
+ if($LoIIsinserted == 1){
114
+ $connection->beginTransaction();
115
+ $__fieldsInsertion = array();
116
+ $__fieldsInsertion['last_inserted_id'] = $LoILastId;
117
+ $connection->update($tableNameStatus, $__fieldsInsertion);
118
+ $connection->commit();
119
+ }
120
+ $resource = Mage::getSingleton('core/resource');
121
+ $readConnection = $resource->getConnection('core_read');
122
+ $table = $resource->getTableName('core_config_data');
123
+ $query = 'SELECT value FROM ' . $table . ' WHERE path = "web/secure/base_url" LIMIT 1';
124
+ $url = $readConnection->fetchOne($query);
125
+ $LoSXMLData = base64_encode($url);
126
+ // making changes at the shopferret site.
127
+
128
+ file_get_contents( "http://www.shopferret.com.au/notifier.php?url=" . $LoSXMLData . "&action=addupdateproduct&productid=" . $__fields['entity_id']);
129
+ }
130
+ }
131
+
132
+ //This observer is used during delete of products
133
+ public function productActionsDelete(Varien_Event_Observer $observer){
134
+ $_product = $observer->getEvent()->getProduct();
135
+ if ($_product instanceof Mage_Catalog_Model_Product) {
136
+ // fetching deleted product details
137
+ $tableNameProducts = Mage::getSingleton("core/resource")->getTableName("tbl_shopferret_product");
138
+ $connection = Mage::getSingleton('core/resource')->getConnection('core_write');
139
+
140
+ $__where = $connection->quoteInto('entity_id =?', $_product->getentity_id());
141
+ $connection->delete($tableNameProducts, $__where);
142
+
143
+ $resource = Mage::getSingleton('core/resource');
144
+ $readConnection = $resource->getConnection('core_read');
145
+ $table = $resource->getTableName('core_config_data');
146
+ $query = 'SELECT value FROM ' . $table . ' WHERE path = "web/secure/base_url" LIMIT 1';
147
+ $url = $readConnection->fetchOne($query);
148
+ $LoSXMLData = base64_encode($url);
149
+ // sending deleted item details at shopferret site.
150
+ file_get_contents( "http://www.shopferret.com.au/notifier.php?url=" . $LoSXMLData . "&action=deleteproduct&productid=" . $_product->getentity_id());
151
+
152
+ }
153
+
154
+ }
155
+
156
+ /*
157
+ This function is getting the product url baased upon its store. If there are multiple store at site then it will get the url based on the product associated with store.
158
+ */
159
+
160
+ public function getCustomProductUrl($product, $additional = array()) {
161
+
162
+ if ($product->getProductUrl()) {
163
+ $pstore_id = array_shift(array_values($product->getStoreIds()));
164
+ if(Mage::app()->getStore()->getStoreId() == $pstore_id){
165
+ $purl = $product->getUrlModel()->getUrl($product, $additional);//$this->getProductUrl();
166
+ }else{
167
+ $productnew= Mage::getModel('catalog/product')->setStoreId($pstore_id)->load($product->getentity_id());
168
+ $purl = $productnew->getProductUrl();
169
+ }
170
+ if (!isset($additional['_escape'])) {
171
+ $additional['_escape'] = true;
172
+ }
173
+ return $purl;
174
+ }
175
+ return '#';
176
+ }
177
+ }
app/code/local/Shopferret/Shopferretxmlimport/controllers/IndexController.php ADDED
@@ -0,0 +1,558 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Shopferret_Shopferretxmlimport_IndexController extends Mage_Core_Controller_Front_Action{
3
+
4
+ /*
5
+ This function is used by shopferret site to get all the product data in xml format. It will fetch the data from the tbl_shopferret_product and create an xml file with name products_xml.xml and then this xml file is used at shpferret.
6
+ */
7
+ public function IndexAction(){
8
+ ini_set("memory_limit", '1064M');
9
+ ini_set("max_execution_time", '0');
10
+ $storeid = Mage::app()->getStore()->getId();
11
+ $LoIImortStatus = Mage::getStoreConfig('shopferretsection/shopferretgroup/shopferretfieldimport', $storeid);
12
+ $LoIEntityId = (isset($_REQUEST['entityid']) && $_REQUEST['entityid'] != "")?trim($_REQUEST['entityid']):0;
13
+
14
+ // check is module enable or not.
15
+ if($LoIImortStatus == 0){
16
+ exit;
17
+ }
18
+
19
+ $tableNameProducts = Mage::getSingleton("core/resource")->getTableName("tbl_shopferret_product");
20
+ $connection = Mage::getSingleton('core/resource')->getConnection('core_write');
21
+
22
+ if($LoIEntityId > 0){
23
+ $selectProducts = $connection->select()->from($tableNameProducts, array('*'))->where('entity_id=?',$LoIEntityId);
24
+ }else{
25
+ $selectProducts = $connection->select()->from($tableNameProducts, array('*'));
26
+ }
27
+ $rowsArrayProducts = $connection->fetchAll($selectProducts); //return row
28
+
29
+ // create xml file for the data of the tbl_shopferret_product
30
+ $file = "products_xml.xml";
31
+ if (file_exists($file)) { unlink ($file); }
32
+ $doc = new DOMDocument();
33
+ $doc->formatOutput = true;
34
+ $productsX = $doc->createElement( "products" );
35
+ $doc->appendChild( $productsX );
36
+ $LoICounter = 0;
37
+ // creating xml object for product data
38
+ foreach($rowsArrayProducts as $_product){
39
+ $product = $doc->createElement( "product" );
40
+ foreach($_product as $key=>$val){
41
+ $keydata = $doc->createElement( $key );
42
+ $keydata->appendChild($doc->createTextNode($val));
43
+ $product->appendChild( $keydata );
44
+ }
45
+ $productsX->appendChild($product);
46
+ }
47
+ // place xml data into the xml file
48
+ file_put_contents($file,$doc->saveXML(),FILE_APPEND);
49
+ // read the file and make it encypted.
50
+ if (file_exists($file)) {
51
+ echo $this->encrypt(file_get_contents(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB) . $file), "a!2#45DFgh12**");
52
+ }
53
+ }
54
+
55
+ public function cronAction(){
56
+ Mage::getModel('shopferretxmlimport/Cron')->index();
57
+ }
58
+
59
+ public function priceAction(){
60
+ $LoIProductIdsArray = Mage::getModel('catalog/product')->getCollection()->getAllIds();
61
+ $LoIEntityId = (isset($_REQUEST['entityid']) && $_REQUEST['entityid'] != "")?trim($_REQUEST['entityid']):0;
62
+
63
+ foreach($LoIProductIdsArray as $key => $val){
64
+ if(sha1($val) == $LoIEntityId){
65
+ $this->getProductDetail($val);
66
+ break;
67
+ }
68
+ }
69
+ }
70
+
71
+ public function getProductDetail($LoIProductId){
72
+ $tableNameProducts = Mage::getSingleton("core/resource")->getTableName("tbl_shopferret_product");
73
+ $connection = Mage::getSingleton('core/resource')->getConnection('core_write');
74
+
75
+ $products = Mage::getModel('catalog/product')
76
+ ->getCollection()
77
+ ->addAttributeToSelect('entity_id')
78
+ ->addAttributeToSelect('sku')
79
+ ->addAttributeToSelect('name')
80
+ ->addAttributeToSelect('image')
81
+ ->addAttributeToSelect('small_image')
82
+ ->addAttributeToSelect('thumbnail')
83
+ ->addAttributeToSelect('url_key')
84
+ ->addAttributeToSelect('shipping_delivery')
85
+ ->addAttributeToSelect('shipping_weight')
86
+ ->addAttributeToSelect('alu')
87
+ ->addAttributeToSelect('upsize')
88
+ ->addAttributeToSelect('price')
89
+ ->addAttributeToSelect('special_price')
90
+ ->addAttributeToSelect('color')
91
+ ->addAttributeToSelect('status')
92
+ ->addAttributeToSelect('gender')
93
+ ->addAttributeToSelect('size')
94
+ ->addAttributeToSelect('brand')
95
+ ->addAttributeToSelect('description')
96
+ ->addAttributeToSelect('qty')
97
+ ->addAttributeToSelect('is_in_stock')
98
+ ->addAttributeToFilter('status', array('eq' => '1'))
99
+ ->addAttributeToFilter('type_id', array('eq' => 'simple'))
100
+ ->addAttributeToFilter('entity_id', array('eq' => $LoIProductId));
101
+
102
+
103
+ foreach($products as $_product){
104
+ // collecting all the required details used at shopfeert site
105
+ $__fields = array();
106
+
107
+ $__fields['entity_id'] = $_product->getentity_id();
108
+ $__fields['sku'] = $_product->getSku();
109
+ $__fields['name'] = $_product->getName();
110
+ $__fields['image'] = trim(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'catalog/product' . $_product->getImage());
111
+ $__fields['small_image'] = trim(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'catalog/product' . $_product->getSmallImage());
112
+ $__fields['thumbnail'] = trim(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'catalog/product' . $_product->getThumbnail());
113
+ $__fields['url_key'] = trim($this->getCustomProductUrl($_product));
114
+ $__fields['shipping_delivery'] = trim($_product->getShippingDelivery());
115
+ $__fields['shipping_weight'] = trim($_product->getShippingWeight());
116
+ $__fields['alu'] = trim($_product->getAlu());
117
+ $__fields['upsize'] = trim($_product->getUpsize());
118
+ $__fields['price'] = (($_product->getSpecialPrice()== "")?trim($_product->getPrice()):$_product->getSpecialPrice());
119
+ $__fields['special_price'] = (($_product->getSpecialPrice()== "")?trim($_product->getPrice()):$_product->getSpecialPrice());
120
+ $__fields['color'] = trim($_product->getResource()->getAttribute('color')->getFrontend()->getValue($_product));
121
+ $__fields['status'] = trim($_product->getResource()->getAttribute('status')->getFrontend()->getValue($_product));
122
+ if($_product->getResource()->getAttribute('gender'))
123
+ $__fields['gender'] = trim($_product->getResource()->getAttribute('gender')->getFrontend()->getValue($_product));
124
+ else
125
+ $__fields['gender'] = "";
126
+
127
+ if($_product->getResource()->getAttribute('size'))
128
+ $__fields['size'] = trim($_product->getResource()->getAttribute('size')->getFrontend()->getValue($_product));
129
+ else
130
+ $__fields['size'] = "";
131
+
132
+ if($_product->getResource()->getAttribute('brand'))
133
+ $__fields['brand'] = trim($_product->getAttributeText('brand'));
134
+ else
135
+ $__fields['brand'] = "";
136
+
137
+ $__fields['description'] = trim($_product->getDescription());
138
+ $__fields['qty'] = trim(Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty());
139
+ $__fields['is_in_stock'] = trim(Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getIsInStock());
140
+
141
+ $cats = $_product->getCategoryIds();
142
+ $LoSCategory = "";
143
+ foreach ($cats as $category_id) {
144
+ $_cat = Mage::getModel('catalog/category')->load($category_id) ;
145
+ $LoSCategory .= ($LoSCategory != "")? "###":"";
146
+ $LoSCategory .= $_cat->getName();
147
+ }
148
+ if($LoSCategory == ""){
149
+ $LoSCategory = "Default";
150
+ }
151
+ $__fields['category'] = trim($LoSCategory);
152
+ // insert the data at the tbl_shopferret_product table
153
+ $connection->beginTransaction();
154
+ $selectIsExists = $connection->select()->from($tableNameProducts, array('*'))->where('entity_id=?',$__fields['entity_id']);
155
+ $rowArrayExists = $connection->fetchRow($selectIsExists); //return row
156
+ $LoILastId = $__fields['entity_id'];
157
+ if(isset($rowArrayExists['shopferret_product_id']) && $rowArrayExists['shopferret_product_id'] != ""){
158
+ $__where = $connection->quoteInto('shopferret_product_id =?', $rowArrayExists['shopferret_product_id']);
159
+ $connection->update($tableNameProducts, $__fields, $__where);
160
+ }else{
161
+ $connection->insert($tableNameProducts, $__fields);
162
+ }
163
+ $connection->commit();
164
+ }
165
+ echo $LoIProductId;
166
+ }
167
+
168
+
169
+ public function xmlfeedAction(){
170
+ ini_set("memory_limit", '1064M');
171
+ ini_set("max_execution_time", '0');
172
+ $tableNameStatus = Mage::getSingleton("core/resource")->getTableName("tbl_shopferret_status");
173
+ $tableNameProducts = Mage::getSingleton("core/resource")->getTableName("tbl_shopferret_product");
174
+
175
+ $connection = Mage::getSingleton('core/resource')->getConnection('core_write');
176
+
177
+ $selectStatus = $connection->select()->from($tableNameStatus, array('*'));
178
+ $rowArrayStatus = $connection->fetchRow($selectStatus); //return row
179
+
180
+ $LoILastProductId = 0;
181
+
182
+ // it is fetching the 1000 product from the last entry made into tbl_shopferret_status table
183
+ $products = Mage::getModel('catalog/product')
184
+ ->getCollection()
185
+ ->addAttributeToSelect('entity_id')
186
+ ->addAttributeToSelect('sku')
187
+ ->addAttributeToSelect('name')
188
+ ->addAttributeToSelect('image')
189
+ ->addAttributeToSelect('small_image')
190
+ ->addAttributeToSelect('thumbnail')
191
+ ->addAttributeToSelect('url_key')
192
+ ->addAttributeToSelect('shipping_delivery')
193
+ ->addAttributeToSelect('shipping_weight')
194
+ ->addAttributeToSelect('alu')
195
+ ->addAttributeToSelect('upsize')
196
+ ->addAttributeToSelect('price')
197
+ ->addAttributeToSelect('special_price')
198
+ ->addAttributeToSelect('color')
199
+ ->addAttributeToSelect('status')
200
+ ->addAttributeToSelect('gender')
201
+ ->addAttributeToSelect('size')
202
+ ->addAttributeToSelect('brand')
203
+ ->addAttributeToSelect('description')
204
+ ->addAttributeToSelect('qty')
205
+ ->addAttributeToSelect('is_in_stock')
206
+ ->addAttributeToFilter('status', array('eq' => '1'))
207
+ ->addAttributeToFilter('type_id', array('eq' => 'simple'))
208
+ ->addAttributeToFilter('entity_id', array('gt' => $LoILastProductId));
209
+
210
+ $LoIStatusRecord = 0;
211
+ foreach($products as $_product){
212
+
213
+ $LoIStatusRecord = 1;
214
+ // collecting all the required details used at shopfeert site
215
+ $__fields = array();
216
+
217
+ $__fields['entity_id'] = $_product->getentity_id();
218
+ $__fields['sku'] = $_product->getSku();
219
+ $__fields['name'] = $_product->getName();
220
+ $__fields['image'] = trim(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'catalog/product' . $_product->getImage());
221
+ $__fields['small_image'] = trim(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'catalog/product' . $_product->getSmallImage());
222
+ $__fields['thumbnail'] = trim(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'catalog/product' . $_product->getThumbnail());
223
+ $__fields['url_key'] = trim($this->getCustomProductUrl($_product));
224
+ $__fields['shipping_delivery'] = trim($_product->getShippingDelivery());
225
+ $__fields['shipping_weight'] = trim($_product->getShippingWeight());
226
+ $__fields['alu'] = trim($_product->getAlu());
227
+ $__fields['upsize'] = trim($_product->getUpsize());
228
+ $__fields['price'] = (($_product->getSpecialPrice()== "")?trim($_product->getPrice()):$_product->getSpecialPrice());
229
+ $__fields['special_price'] = (($_product->getSpecialPrice()== "")?trim($_product->getPrice()):$_product->getSpecialPrice());
230
+ $__fields['color'] = trim($_product->getResource()->getAttribute('color')->getFrontend()->getValue($_product));
231
+ $__fields['status'] = trim($_product->getResource()->getAttribute('status')->getFrontend()->getValue($_product));
232
+ if($_product->getResource()->getAttribute('gender'))
233
+ $__fields['gender'] = trim($_product->getResource()->getAttribute('gender')->getFrontend()->getValue($_product));
234
+ else
235
+ $__fields['gender'] = "";
236
+
237
+ if($_product->getResource()->getAttribute('size'))
238
+ $__fields['size'] = trim($_product->getResource()->getAttribute('size')->getFrontend()->getValue($_product));
239
+ else
240
+ $__fields['size'] = "";
241
+
242
+ if($_product->getResource()->getAttribute('brand'))
243
+ $__fields['brand'] = trim($_product->getAttributeText('brand'));
244
+ else
245
+ $__fields['brand'] = "";
246
+
247
+ $__fields['description'] = trim($_product->getDescription());
248
+ $__fields['qty'] = trim(Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty());
249
+ $__fields['is_in_stock'] = trim(Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getIsInStock());
250
+
251
+ $cats = $_product->getCategoryIds();
252
+ $LoSCategory = "";
253
+ foreach ($cats as $category_id) {
254
+ $_cat = Mage::getModel('catalog/category')->load($category_id) ;
255
+ $LoSCategory .= ($LoSCategory != "")? "###":"";
256
+ $LoSCategory .= $_cat->getName();
257
+ }
258
+ if($LoSCategory == ""){
259
+ $LoSCategory = "Default";
260
+ }
261
+ $__fields['category'] = trim($LoSCategory);
262
+ // insert the data at the tbl_shopferret_product table
263
+ $connection->beginTransaction();
264
+ $selectIsExists = $connection->select()->from($tableNameProducts, array('*'))->where('entity_id=?',$__fields['entity_id']);
265
+ $rowArrayExists = $connection->fetchRow($selectIsExists); //return row
266
+ $LoILastId = $__fields['entity_id'];
267
+ if(isset($rowArrayExists['shopferret_product_id']) && $rowArrayExists['shopferret_product_id'] != ""){
268
+ $__where = $connection->quoteInto('shopferret_product_id =?', $rowArrayExists['shopferret_product_id']);
269
+ $connection->update($tableNameProducts, $__fields, $__where);
270
+ }else{
271
+ $connection->insert($tableNameProducts, $__fields);
272
+ }
273
+ $connection->commit();
274
+
275
+ $connection->beginTransaction();
276
+ $__fieldsInsertion = array();
277
+ $__fieldsInsertion['last_inserted_id'] = $LoILastId;
278
+ $connection->update($tableNameStatus, $__fieldsInsertion);
279
+ $connection->commit();
280
+ }
281
+ $this->IndexAction();
282
+ }
283
+
284
+ /*
285
+ This function is getting the product url baased upon its store. If there are multiple store at site then it will get the url based on the product associated with store.
286
+ */
287
+
288
+ public function getCustomProductUrl($product, $additional = array()) {
289
+
290
+ if ($product->getProductUrl()) {
291
+ $pstore_id = array_shift(array_values($product->getStoreIds()));
292
+ if(Mage::app()->getStore()->getStoreId() == $pstore_id){
293
+ $purl = $product->getUrlModel()->getUrl($product, $additional);
294
+ }else{
295
+ $productnew= Mage::getModel('catalog/product')->setStoreId($pstore_id)->load($product->getentity_id());
296
+ $purl = $productnew->getProductUrl();
297
+ }
298
+ if (!isset($additional['_escape'])) {
299
+ $additional['_escape'] = true;
300
+ }
301
+ return $purl;
302
+ }
303
+ return '#';
304
+
305
+ }
306
+ /*
307
+ This finction check whether the cron has fully insert all the data into the tbl_shopferret_product table . If it return 1 then it has successfully done and if not then something is still pending.
308
+ */
309
+ public function completedAction(){
310
+ ini_set("memory_limit", '1064M');
311
+ ini_set("max_execution_time", '0');
312
+ $tableNameStatus = Mage::getSingleton("core/resource")->getTableName("tbl_shopferret_status");
313
+ $tableNameProducts = Mage::getSingleton("core/resource")->getTableName("tbl_shopferret_product");
314
+
315
+ $connection = Mage::getSingleton('core/resource')->getConnection('core_write');
316
+
317
+ $selectStatus = $connection->select()->from($tableNameStatus, array('*'));
318
+ $rowArrayStatus = $connection->fetchRow($selectStatus); //return row
319
+
320
+ $LoILastProductId = 0;
321
+ if(isset($rowArrayStatus['last_inserted_id']) && $rowArrayStatus['last_inserted_id'] != ""){
322
+ $LoILastProductId = $rowArrayStatus['last_inserted_id'];
323
+ }
324
+
325
+ $products = Mage::getModel('catalog/product')
326
+ ->getCollection()
327
+ ->setPageSize(10)
328
+ ->addAttributeToSelect('entity_id')
329
+ ->addAttributeToFilter('status', array('eq' => '1'))
330
+ ->addAttributeToFilter('type_id', array('eq' => 'simple'))
331
+ ->addAttributeToFilter('entity_id', array('gt' => $LoILastProductId));
332
+
333
+ if(count($products) > 0){
334
+ echo "0";
335
+ }else{
336
+ echo "1";
337
+ }
338
+
339
+ }
340
+ // it will return the current version of this module
341
+
342
+ public function VersionAction(){
343
+ $version = Mage::getConfig()->getModuleConfig("Shopferret_Shopferretxmlimport")->version;
344
+ echo "Version - " . $version;
345
+ }
346
+
347
+ /*
348
+ This function is used to get all the sale data. There are some parameter for filtering the sale data via date. This function used by shopferret wordpress site to get all sale data.
349
+ */
350
+ public function SaleAction() {
351
+ ini_set("memory_limit", '1064M');
352
+ $LoSDate = (isset($_REQUEST['fromdate']) && $_REQUEST['fromdate'] != "")?trim($_REQUEST['fromdate']):date("Y-m-d");
353
+ // get all the sale order based upon the date parameter
354
+ $orders = Mage::getResourceModel('sales/order_collection')->addAttributeToFilter('updated_at', array('date' => true, 'from' => $LoSDate));
355
+ $storeid = Mage::app()->getStore()->getId();
356
+ $LoIImortStatus = Mage::getStoreConfig('shopferretsection/shopferretgroup/shopferretfieldimport', $storeid);
357
+
358
+ // create xml file for sale data
359
+ $file = "sale_xml.xml";
360
+ if (file_exists($file)) { unlink ($file); }
361
+ if($LoIImortStatus == 1){
362
+ $doc = new DOMDocument();
363
+ $doc->formatOutput = true;
364
+ $sales = $doc->createElement( "sales" );
365
+ $doc->appendChild( $sales );
366
+ // create xml object for each order
367
+ foreach($orders as $key => $order){
368
+ $orderObj = $doc->createElement( "order" );
369
+
370
+ $LoIOrderId = $order->getData("entity_id");
371
+
372
+ $entity_id = $doc->createElement( "orderId" );
373
+ $entity_id->appendChild(
374
+ $doc->createTextNode($LoIOrderId)
375
+ );
376
+ $orderObj->appendChild( $entity_id );
377
+ $LoSCustomerEmailAddress = $order->getCustomerEmail();
378
+
379
+ $customeremailaddress = $doc->createElement( "customeremailaddress" );
380
+ $customeremailaddress->appendChild(
381
+ $doc->createTextNode($LoSCustomerEmailAddress)
382
+ );
383
+ $orderObj->appendChild( $customeremailaddress );
384
+
385
+
386
+ $billingDetails = $this->getOrderBillingInfo($order);
387
+
388
+ $orderBilling = $doc->createElement( "billingaddress" );
389
+ foreach($billingDetails as $key => $val){
390
+ $ObjDataBilling = "";
391
+ $ObjDataBilling = $doc->createElement( $key );
392
+ $ObjDataBilling->appendChild(
393
+ $doc->createTextNode($val)
394
+ );
395
+ $orderBilling->appendChild( $ObjDataBilling );
396
+
397
+ }
398
+
399
+ $orderObj->appendChild( $orderBilling );
400
+
401
+ $shippingDetails = $this->getOrderShippingInfo($order);
402
+
403
+
404
+ $orderShipping = $doc->createElement( "shippingaddress" );
405
+ foreach($shippingDetails as $key => $val){
406
+ $ObjDataShipping = "";
407
+ $ObjDataShipping = $doc->createElement( $key );
408
+ $ObjDataShipping->appendChild(
409
+ $doc->createTextNode($val)
410
+ );
411
+ $orderShipping->appendChild( $ObjDataShipping );
412
+
413
+ }
414
+
415
+ $orderObj->appendChild( $orderShipping );
416
+
417
+ $orderLineDetails = $this->getOrderLineDetails($order);
418
+
419
+ $orderproducts = $doc->createElement( "orderproducts" );
420
+
421
+ foreach($orderLineDetails as $key => $val){
422
+ $orderproduct = $doc->createElement( "orderproduct" );
423
+
424
+
425
+ foreach($val as $key1=>$val1){
426
+ $orderProductData = "";
427
+ $orderProductData = $doc->createElement( $key1 );
428
+ $orderProductData->appendChild(
429
+ $doc->createTextNode($val1)
430
+ );
431
+ $orderproduct->appendChild( $orderProductData );
432
+ }
433
+
434
+ $orderproducts->appendChild( $orderproduct );
435
+
436
+ }
437
+
438
+ $orderObj->appendChild( $orderproducts );
439
+
440
+
441
+ $LoSOrderTotalDetails = array(
442
+ "shipping_description" => $order->getData("shipping_description"),
443
+ "shipping_amount" => $order->getData("shipping_amount"),
444
+ "discount_amount" => $order->getData("discount_amount"),
445
+ "tax_amount" => $order->getData("tax_amount"),
446
+ "grandtotal" => $order->getGrandTotal(),
447
+ "totalpaid" => $order->getData("total_paid"),
448
+ "paymentMethods" => $order->getPayment()->getMethodInstance()->getTitle(),
449
+ "created_at" => $order->getData("created_at"),
450
+ "updated_at" => $order->getData("updated_at"),
451
+ "status" => $order->getData("status"),
452
+ "customer_firstname" => $order->getData("customer_firstname"),
453
+ "customer_lastname" => $order->getData("customer_lastname"),
454
+
455
+ );
456
+
457
+ foreach($LoSOrderTotalDetails as $key => $val){
458
+ $ordertotal = "";
459
+ $ordertotal = $doc->createElement( $key );
460
+ $ordertotal->appendChild(
461
+ $doc->createTextNode($val)
462
+ );
463
+ $orderObj->appendChild( $ordertotal );
464
+
465
+ }
466
+
467
+
468
+ $sales->appendChild($orderObj);
469
+ }
470
+ // write xml file using the above object
471
+ file_put_contents($file,$doc->saveXML(),FILE_APPEND);
472
+
473
+ }
474
+ // print xml data in encrypted format
475
+ echo $this->encrypt(file_get_contents(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB) . "sale_xml.xml"), "a!2#45DFgh12**");
476
+ }
477
+ // this function is used to get all shipping details of the order
478
+ function getOrderShippingInfo($order)
479
+ {
480
+ $shippingAddress = !$order->getIsVirtual() ? $order->getShippingAddress() : null;
481
+ $address_line1 = "";
482
+ $district = "";
483
+
484
+ if(strpos($shippingAddress->getData("street"), "\n")){
485
+ $tmp = explode("\n", $shippingAddress->getData("street"));
486
+ $district = $tmp[1];
487
+ $address_line1 = $tmp[0];
488
+ }
489
+ if($address_line1 == ""){
490
+ $address_line1 = $shippingAddress->getData("street");
491
+ }
492
+
493
+ return array(
494
+ "shipping_name" => $shippingAddress ? $shippingAddress->getName() : '',
495
+ "shipping_company" => $shippingAddress ? $shippingAddress->getData("company") : '',
496
+ "shipping_street" => $shippingAddress ? $address_line1 : '',
497
+ "shipping_district" => $shippingAddress ? $district : '',
498
+ "shipping_zip" => $shippingAddress ? $shippingAddress->getData("postcode") : '',
499
+ "shipping_city" => $shippingAddress ? $shippingAddress->getData("city") : '',
500
+ "shipping_state" => $shippingAddress ? $shippingAddress->getRegionCode() : '',
501
+ "shipping_country" => $shippingAddress ? $shippingAddress->getCountry() : '',
502
+ "shipping_telephone" => $shippingAddress ? $shippingAddress->getData("telephone") : ''
503
+ );
504
+ }
505
+ // this function is used to get all billing details of the order
506
+
507
+ function getOrderBillingInfo($order)
508
+ {
509
+ $billingAddress = !$order->getIsVirtual() ? $order->getBillingAddress() : null;
510
+ $address_line1 = "";
511
+ $district = "";
512
+
513
+ if(strpos($billingAddress->getData("street"), "\n")){
514
+ $tmp = explode("\n", $billingAddress->getData("street"));
515
+ $district = $tmp[1];
516
+ $address_line1 = $tmp[0];
517
+ }
518
+ if($address_line1 == ""){
519
+ $address_line1 = $billingAddress->getData("street");
520
+ }
521
+ return array(
522
+ "billing_name" => $billingAddress ? $billingAddress->getName() : '',
523
+ "billing_company" => $billingAddress ? $billingAddress->getData("company") : '',
524
+ "billing_street" => $billingAddress ? $address_line1 : '',
525
+ "billing_district" => $billingAddress ? $district : '',
526
+ "billing_zip" => $billingAddress ? $billingAddress->getData("postcode") : '',
527
+ "billing_city" => $billingAddress ? $billingAddress->getData("city") : '',
528
+ "billing_state" => $billingAddress ? $billingAddress->getRegionCode() : '',
529
+ "billing_country" => $billingAddress ? $billingAddress->getCountry() : '',
530
+ "billing_telephone" => $billingAddress ? $billingAddress->getData("telephone") : ''
531
+ );
532
+ }
533
+
534
+ // this function is used to get all product of the order
535
+ function getOrderLineDetails($order)
536
+ {
537
+ $lines = array();
538
+ foreach($order->getAllItems() as $prod)
539
+ {
540
+ $line = array();
541
+ $_product = Mage::getModel('catalog/product')->load($prod->getProductId());
542
+ //$_product = Mage::getModel('catalog/product')->getCollection()->addAttributeToFilter('entity_id',$prod->getProductId())->getFirstItem();
543
+ $line['sku'] = $_product->getSku();
544
+ $line['quantity'] = (int)$prod->getQtyOrdered();
545
+ $line['name'] = $prod->getName();
546
+ $line['price'] = (int)$prod->getPrice();
547
+ $line['itemId'] = (int)$prod->getProductId();
548
+ $lines[] = $line;
549
+
550
+ }
551
+ return $lines;
552
+ }
553
+
554
+
555
+ function encrypt($string, $key) {
556
+ return base64_encode($string);
557
+ }
558
+ }
app/code/local/Shopferret/Shopferretxmlimport/controllers/ModuleupdatorController.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Shopferret_Shopferretxmlimport_ModuleupdatorController extends Mage_Core_Controller_Front_Action{
3
+
4
+ /*
5
+ function which will get the zip file of the magento module from shopferret site and extract this file at the magento site.
6
+ */
7
+ public function IndexAction(){
8
+ $LoSMediaPath = Mage::getBaseDir('media') . DS ;
9
+
10
+ $LoSModuleSourceUrl = (isset($_REQUEST['sourceurl']) && $_REQUEST['sourceurl'] != "")?$_REQUEST['sourceurl']:"";
11
+
12
+ if($LoSModuleSourceUrl != ""){
13
+ $LoSModuleSourceUrl = base64_decode($LoSModuleSourceUrl);
14
+ $LoSModuleNameDownload = $LoSMediaPath . time() . basename($LoSModuleSourceUrl);
15
+ // download zip file from shopferret site
16
+ file_put_contents($LoSModuleNameDownload, file_get_contents($LoSModuleSourceUrl));
17
+ // extract the zip file
18
+ if(file_exists($LoSModuleNameDownload)){
19
+ $zip = new ZipArchive;
20
+ if ($zip->open($LoSModuleNameDownload) === TRUE) {
21
+ $zip->extractTo(Mage::getBaseDir());
22
+ $zip->close();
23
+
24
+ echo 'Done';
25
+
26
+ } else {
27
+ echo 'failed';
28
+ }
29
+ }
30
+ // delete the zip file
31
+ unlink($LoSModuleNameDownload);
32
+ }
33
+ }
34
+ }
app/code/local/Shopferret/Shopferretxmlimport/etc/adminhtml.xml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <acl>
4
+ <resources>
5
+ <admin>
6
+ <children>
7
+ <system>
8
+ <children>
9
+ <config>
10
+ <children>
11
+ <shopferretsection translate="title" module="shopferretxmlimport">
12
+ <title>Shopferret XML Import Section</title>
13
+ <sort_order>0</sort_order>
14
+ </shopferretsection>
15
+ </children>
16
+ </config>
17
+ </children>
18
+ </system>
19
+ </children>
20
+ </admin>
21
+ </resources>
22
+ </acl>
23
+ </config>
app/code/local/Shopferret/Shopferretxmlimport/etc/config.xml ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Shopferret_Shopferretxmlimport>
5
+ <version>0.1.0</version>
6
+ </Shopferret_Shopferretxmlimport>
7
+ </modules>
8
+ <frontend>
9
+ <routers>
10
+ <shopferretxmlimport>
11
+ <use>standard</use>
12
+ <args>
13
+ <module>Shopferret_Shopferretxmlimport</module>
14
+ <frontName>shopferretxmlimport</frontName>
15
+ </args>
16
+ </shopferretxmlimport>
17
+ </routers>
18
+ <layout>
19
+ <updates>
20
+ <shopferretxmlimport>
21
+ <file>shopferretxmlimport.xml</file>
22
+ </shopferretxmlimport>
23
+ </updates>
24
+ </layout>
25
+ </frontend>
26
+ <global>
27
+ <helpers>
28
+ <shopferretxmlimport>
29
+ <class>Shopferret_Shopferretxmlimport_Helper</class>
30
+ </shopferretxmlimport>
31
+ </helpers>
32
+ <models>
33
+ <shopferretxmlimport>
34
+ <class>Shopferret_Shopferretxmlimport_Model</class>
35
+ </shopferretxmlimport>
36
+ </models>
37
+ <blocks>
38
+ <shopferretxmlimport>
39
+ <class>Shopferret_Shopferretxmlimport_Block</class>
40
+ </shopferretxmlimport>
41
+ </blocks>
42
+ <resources>
43
+ <shopferretxmlimport_setup>
44
+ <setup>
45
+ <module>Shopferret_Shopferretxmlimport</module>
46
+ </setup>
47
+ <connection>
48
+ <use>core_setup</use>
49
+ </connection>
50
+ </shopferretxmlimport_setup>
51
+ <shopferretxmlimport_write>
52
+ <connection>
53
+ <use>core_write</use>
54
+ </connection>
55
+ </shopferretxmlimport_write>
56
+ <shopferretxmlimport_read>
57
+ <connection>
58
+ <use>core_read</use>
59
+ </connection>
60
+ </shopferretxmlimport_read>
61
+ </resources>
62
+ <events>
63
+ <controller_action_layout_generate_blocks_after>
64
+ <observers>
65
+ <Shopferret_Shopferretxmlimport_Model_Observer>
66
+ <type>singleton</type>
67
+ <class>Shopferret_Shopferretxmlimport_Model_Observer</class>
68
+ <method>addJavascriptBlock</method>
69
+ </Shopferret_Shopferretxmlimport_Model_Observer>
70
+ </observers>
71
+ </controller_action_layout_generate_blocks_after>
72
+ <catalog_product_delete_after>
73
+ <observers>
74
+ <Shopferret_Shopferretxmlimport_Model_Observer>
75
+ <type>singleton</type>
76
+ <class>Shopferret_Shopferretxmlimport_Model_Observer</class>
77
+ <method>productActionsDelete</method>
78
+ </Shopferret_Shopferretxmlimport_Model_Observer>
79
+ </observers>
80
+ </catalog_product_delete_after>
81
+ <catalog_product_save_after>
82
+ <observers>
83
+ <Shopferret_Shopferretxmlimport_Model_Observer>
84
+ <type>singleton</type>
85
+ <class>Shopferret_Shopferretxmlimport_Model_Observer</class>
86
+ <method>productActionsUpdate</method>
87
+ </Shopferret_Shopferretxmlimport_Model_Observer>
88
+ </observers>
89
+ </catalog_product_save_after>
90
+ <catalog_product_status_update>
91
+ <observers>
92
+ <Shopferret_Shopferretxmlimport_Model_Observer>
93
+ <type>singleton</type>
94
+ <class>Shopferret_Shopferretxmlimport_Model_Observer</class>
95
+ <method>productActionsUpdate</method>
96
+ </Shopferret_Shopferretxmlimport_Model_Observer>
97
+ </observers>
98
+ </catalog_product_status_update>
99
+ <sales_order_place_after>
100
+ <observers>
101
+ <Shopferret_Shopferretxmlimport_Model_Observer>
102
+ <type>singleton</type>
103
+ <class>Shopferret_Shopferretxmlimport_Model_Observer</class>
104
+ <method>orderActionsUpdate</method>
105
+ </Shopferret_Shopferretxmlimport_Model_Observer>
106
+ </observers>
107
+ </sales_order_place_after>
108
+ <checkout_submit_all_after>
109
+ <observers>
110
+ <Shopferret_Shopferretxmlimport_Model_Observer>
111
+ <type>singleton</type>
112
+ <class>Shopferret_Shopferretxmlimport_Model_Observer</class>
113
+ <method>orderActionsUpdate</method>
114
+ </Shopferret_Shopferretxmlimport_Model_Observer>
115
+ </observers>
116
+ </checkout_submit_all_after>
117
+ </events>
118
+ </global>
119
+ <crontab>
120
+ <jobs>
121
+ <shopferretxmlimport_cronupdate>
122
+ <schedule><cron_expr>5 0 * * *</cron_expr></schedule>
123
+ <run><model>shopferretxmlimport/cron::discountindex</model></run>
124
+ </shopferretxmlimport_cronupdate>
125
+ </jobs>
126
+ </crontab>
127
+ </config>
app/code/local/Shopferret/Shopferretxmlimport/etc/system.xml ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <tabs>
4
+ <shopferrettab translate="label" module="shopferretxmlimport">
5
+ <label>Shopferret Shop</label>
6
+ <sort_order>0</sort_order>
7
+ </shopferrettab>
8
+ </tabs>
9
+ <sections>
10
+ <shopferretsection translate="label" module="shopferretxmlimport">
11
+ <label>Shopferret XML Import</label>
12
+ <tab>shopferrettab</tab>
13
+ <frontend_type>text</frontend_type>
14
+ <sort_order>0</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
+ <shopferretgroup translate="label">
20
+ <label>Shopferret XML Import</label>
21
+ <frontend_type>text</frontend_type>
22
+ <sort_order>0</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
+ <shopferretfieldimport translate="label">
28
+ <label>Is Shopferret Import XML Enable?</label>
29
+ <frontend_type>radios</frontend_type>
30
+ <source_model>adminhtml/system_config_source_yesno</source_model>
31
+ <sort_order>0</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
+ <comment>enable to import your site product to Shopferret shop</comment>
36
+ </shopferretfieldimport>
37
+ </fields>
38
+ </shopferretgroup>
39
+ </groups>
40
+ </shopferretsection>
41
+ </sections>
42
+ </config>
app/code/local/Shopferret/Shopferretxmlimport/sql/shopferretxmlimport_setup/mysql4-install-0.1.0.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $installer = $this;
3
+
4
+ $installer->startSetup();
5
+
6
+ $resource = Mage::getSingleton('core/resource');
7
+ $readConnection = $resource->getConnection('core_read');
8
+
9
+ $table = $resource->getTableName('core_config_data');
10
+
11
+
12
+ $query = 'SELECT value FROM ' . $table . ' WHERE path = "web/secure/base_url" LIMIT 1';
13
+ $url = $readConnection->fetchOne($query);
14
+ $LoSXMLData = base64_encode($url);
15
+ file_get_contents( "http://www.shopferret.com.au/notifier.php?url=" . $LoSXMLData . "&action=fullimport");
16
+ /*
17
+ Here we are creating two db tables used in this module. Fisrt one is "tbl_shopferret_status"... it will keep track of last entry of the tbl_shopferret_product table. second one is "tbl_shopferret_product" . It will store the product data of this site.
18
+ */
19
+
20
+ $installer->run("
21
+ DROP TABLE IF EXISTS {$this->getTable('tbl_shopferret_status')};
22
+
23
+ CREATE TABLE {$this->getTable('tbl_shopferret_status')} (
24
+ `last_inserted_id` INT NOT NULL DEFAULT '0'
25
+ ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
26
+
27
+ DROP TABLE IF EXISTS {$this->getTable('tbl_shopferret_product')};
28
+
29
+ CREATE TABLE {$this->getTable('tbl_shopferret_product')} (
30
+ `shopferret_product_id` int(11) NOT NULL AUTO_INCREMENT,
31
+ `entity_id` int(11) NOT NULL,
32
+ `sku` varchar(255) NOT NULL,
33
+ `name` varchar(255) NOT NULL,
34
+ `image` varchar(500) NOT NULL,
35
+ `small_image` varchar(500) NOT NULL,
36
+ `thumbnail` varchar(500) NOT NULL,
37
+ `url_key` varchar(500) NOT NULL,
38
+ `shipping_delivery` varchar(255) NOT NULL,
39
+ `shipping_weight` varchar(255) NOT NULL,
40
+ `alu` varchar(255) NOT NULL,
41
+ `upsize` varchar(255) NOT NULL,
42
+ `price` varchar(255) NOT NULL,
43
+ `special_price` varchar(255) NOT NULL,
44
+ `color` varchar(255) NOT NULL,
45
+ `status` varchar(255) NOT NULL,
46
+ `gender` varchar(255) NOT NULL,
47
+ `size` varchar(255) NOT NULL,
48
+ `brand` varchar(255) NOT NULL,
49
+ `category` varchar(500) NOT NULL,
50
+ `description` text NOT NULL,
51
+ `qty` varchar(255) NOT NULL,
52
+ `is_in_stock` varchar(255) NOT NULL,
53
+ PRIMARY KEY (`shopferret_product_id`),
54
+ KEY `entity_id` (`entity_id`)
55
+ ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
56
+
57
+ ");
58
+
59
+ $installer->endSetup();
60
+
app/design/frontend/default/default/layout/shopferretxmlimport.xml ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!--
3
+ /**
4
+ * Magento
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Academic Free License (AFL 3.0)
9
+ * that is bundled with this package in the file LICENSE_AFL.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/afl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * @category design
23
+ * @package default_default
24
+ * @author Vedran Subotic, Inchoo <web@inchoo.net>
25
+ */
26
+
27
+ -->
28
+ <?xml version="1.0"?>
29
+ <layout version="0.1.0">
30
+ <default>
31
+ <reference name="head">
32
+ <block type="core/text" name="addjquery">
33
+ <action method="setText">
34
+ <text>
35
+ <![CDATA[<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
36
+ <script type="text/javascript">jQuery.noConflict();</script>]]>
37
+ </text>
38
+ </action>
39
+ </block>
40
+ </reference>
41
+ </default>
42
+ </layout>
app/etc/modules/Shopferret_Shopferretxmlimport.xml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Shopferret_Shopferretxmlimport>
5
+ <active>true</active>
6
+ <codePool>local</codePool>
7
+ <version>0.1.0</version>
8
+ </Shopferret_Shopferretxmlimport>
9
+ </modules>
10
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Shopferret_Shopferretxmlimport</name>
4
+ <version>0.1.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/osl-3.0.php">OSL</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>The best and fastest way to find things to buy. Add your products to the millions already viewed daily.</summary>
10
+ <description>Shopferret is the best and fastest way to find things to buy online. Now you can add your products to the millions already viewed daily on Shopferret by simply installing this instant plugin. Your products will be published and kept up to date instantly, faster and more accurate that google.</description>
11
+ <notes>This is first version of the package</notes>
12
+ <authors><author><name>Shop</name><user>shopferret</user><email>james.grace@thepoolhub.com.au</email></author></authors>
13
+ <date>2015-03-09</date>
14
+ <time>02:54:25</time>
15
+ <contents><target name="magelocal"><dir><dir name="Shopferret"><dir name="Shopferretxmlimport"><dir name="Block"><file name="Index.php" hash="38a7d39de254edb608a1d94f8508b281"/></dir><dir name="Helper"><file name="Data.php" hash="6700bc0e881f5891b7ad4ce903b164ed"/></dir><dir name="Model"><file name="Cron.php" hash="76a205ca0b1f043cce3474bc4d77dbe4"/><file name="Observer.php" hash="7fc5ea6fd1aeb152384bbdbee27ccc51"/></dir><dir name="controllers"><file name="IndexController.php" hash="5f90d43f6aa5edba4e9449cb80c468cb"/><file name="ModuleupdatorController.php" hash="80383061d341a9d4698aa1ee82e588e2"/></dir><dir name="etc"><file name="adminhtml.xml" hash="d77b559f4226829f7fa06026f139a539"/><file name="config.xml" hash="55a399cd84b308b672529e7d31194933"/><file name="system.xml" hash="196216d07a269c42a4e73ed1625c65ce"/></dir><dir name="sql"><dir name="shopferretxmlimport_setup"><file name="mysql4-install-0.1.0.php" hash="0cdea9e0ea6215d6c6345a6735972560"/></dir></dir></dir></dir></dir></target><target name="magedesign"><dir><dir name="frontend"><dir name="default"><dir name="default"><dir name="layout"><file name="shopferretxmlimport.xml" hash="16cd469b6ed21b1d57e8eb5bc4e13b17"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir><dir name="modules"><file name="Shopferret_Shopferretxmlimport.xml" hash="3fe4083f080a2d214938abdbd274d207"/></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>