unbxd_recommendation - Version 1.0.6

Version Notes

supports all the unbxd recommendor widgets

Download this release

Release Info

Developer ananthesh
Extension unbxd_recommendation
Version 1.0.6
Comparing to
See all releases


Version 1.0.6

Files changed (39) hide show
  1. app/code/local/Unbxd/Datafeeder/.DS_Store +0 -0
  2. app/code/local/Unbxd/Datafeeder/Block/Edit.php +12 -0
  3. app/code/local/Unbxd/Datafeeder/Block/Index.php +76 -0
  4. app/code/local/Unbxd/Datafeeder/Helper/.DS_Store +0 -0
  5. app/code/local/Unbxd/Datafeeder/Helper/Analyticshelper.php +105 -0
  6. app/code/local/Unbxd/Datafeeder/Helper/Data.php +12 -0
  7. app/code/local/Unbxd/Datafeeder/Helper/UnbxdIndexingHelper.php +682 -0
  8. app/code/local/Unbxd/Datafeeder/Helper/UnbxdTaxonomyHelper.php +318 -0
  9. app/code/local/Unbxd/Datafeeder/Model/Attribute.php +22 -0
  10. app/code/local/Unbxd/Datafeeder/Model/Conf.php +12 -0
  11. app/code/local/Unbxd/Datafeeder/Model/Facet.php +14 -0
  12. app/code/local/Unbxd/Datafeeder/Model/Feed/Feedcreator.php +321 -0
  13. app/code/local/Unbxd/Datafeeder/Model/Feed/Feedmanager.php +159 -0
  14. app/code/local/Unbxd/Datafeeder/Model/Feed/Filemanager.php +74 -0
  15. app/code/local/Unbxd/Datafeeder/Model/Feed/Jsonbuilder/Jsonbuilder.php +9 -0
  16. app/code/local/Unbxd/Datafeeder/Model/Feed/Jsonbuilder/Productbuilder.php +316 -0
  17. app/code/local/Unbxd/Datafeeder/Model/Feed/Jsonbuilder/Schemabuilder.php +51 -0
  18. app/code/local/Unbxd/Datafeeder/Model/Feed/Jsonbuilder/Taxonomybuilder.php +209 -0
  19. app/code/local/Unbxd/Datafeeder/Model/Field.php +11 -0
  20. app/code/local/Unbxd/Datafeeder/Model/Mysql4/Attribute.php +22 -0
  21. app/code/local/Unbxd/Datafeeder/Model/Mysql4/Conf.php +47 -0
  22. app/code/local/Unbxd/Datafeeder/Model/Mysql4/Conf/Collection.php +16 -0
  23. app/code/local/Unbxd/Datafeeder/Model/Mysql4/Field.php +192 -0
  24. app/code/local/Unbxd/Datafeeder/Model/Mysql4/Field/Collection.php +16 -0
  25. app/code/local/Unbxd/Datafeeder/Model/Mysql4/Resource/Attribute.php +22 -0
  26. app/code/local/Unbxd/Datafeeder/Model/Mysql4/Upgrade.php +37 -0
  27. app/code/local/Unbxd/Datafeeder/controllers/ConfigController.php +80 -0
  28. app/code/local/Unbxd/Datafeeder/controllers/FieldController.php +52 -0
  29. app/code/local/Unbxd/Datafeeder/controllers/IndexController.php +61 -0
  30. app/code/local/Unbxd/Datafeeder/etc/adminhtml.xml +16 -0
  31. app/code/local/Unbxd/Datafeeder/etc/config.xml +119 -0
  32. app/code/local/Unbxd/Datafeeder/scripts/Cron.php +25 -0
  33. app/code/local/Unbxd/Datafeeder/scripts/abstract.php +218 -0
  34. app/code/local/Unbxd/Datafeeder/sql/datafeeder_setup/mysql4-install-1.0.5.php +39 -0
  35. app/code/local/Unbxd/Datafeeder/sql/datafeeder_setup/mysql4-upgrade-0.1.0-1.0.5.php +39 -0
  36. app/design/adminhtml/base/default/template/datafeeder/conf.phtml +439 -0
  37. app/etc/modules/Unbxd_Datafeeder.xml +8 -0
  38. package.xml +18 -0
  39. shell/UnbxdFeed.php +25 -0
app/code/local/Unbxd/Datafeeder/.DS_Store ADDED
Binary file
app/code/local/Unbxd/Datafeeder/Block/Edit.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class Unbxd_Datafeeder_Block_Edit extends Mage_Core_Block_Template
5
+ {
6
+
7
+ public function getCollection()
8
+ {
9
+ return Mage::getModel('datafeeder/field')->getCollection();
10
+ }
11
+ }
12
+ ?>
app/code/local/Unbxd/Datafeeder/Block/Index.php ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class Unbxd_Datafeeder_Block_Index extends Mage_Adminhtml_Block_Template
5
+ {
6
+ public function getFullindexFormAction()
7
+ {
8
+
9
+ return Mage::getUrl('*/*/fullindex', array('_secure' => Mage::app()->getFrontController()->getRequest()->isSecure()));
10
+ }
11
+
12
+ public function getTaxonomyUploadFormAction(){
13
+ return Mage::getUrl('*/*/taxonomyindex', array('_secure' => Mage::app()->getFrontController()->getRequest()->isSecure()));
14
+ }
15
+
16
+ public function getSaveApiUrl(){
17
+ return Mage::getUrl('*/*/saveapi', array('_secure' => Mage::app()->getFrontController()->getRequest()->isSecure()));
18
+ }
19
+
20
+ public function getSaveFieldUrl()
21
+ {
22
+ return Mage::getUrl('*/field/save', array('_secure' => Mage::app()->getFrontController()->getRequest()->isSecure()));
23
+ }
24
+
25
+ public function saveFeedConf(){
26
+ return Mage::getUrl('*/*/savefeedconf', array('_secure' => Mage::app()->getFrontController()->getRequest()->isSecure()));
27
+ }
28
+
29
+ public function checkApiKeyExists()
30
+ {
31
+ if(Mage::getResourceSingleton("datafeeder/conf")->getValue("apiKey")=="empty"){
32
+ return false;
33
+ }
34
+ else{
35
+ return true;
36
+ }
37
+ }
38
+
39
+ public function getApiKey(){
40
+ return Mage::getResourceSingleton("datafeeder/conf")->getValue("apiKey");
41
+ }
42
+
43
+ public function getFields($site)
44
+ {
45
+
46
+ return Mage::getResourceSingleton('datafeeder/field')->getFields($site);
47
+ }
48
+
49
+ public function getIncrementalIndexFormAction()
50
+ {
51
+ return Mage::getUrl('*/*/incrementalindex', array('_secure' => Mage::app()->getFrontController()->getRequest()->isSecure()));
52
+ }
53
+
54
+ public function getProgressUrl()
55
+ {
56
+
57
+ return Mage::getUrl('datafeeder/config/progress', array('_secure' =>Mage::app()->getFrontController()->getRequest()->isSecure()));
58
+ }
59
+
60
+ public function getFeedConf()
61
+ {
62
+
63
+ return Mage::getUrl('datafeeder/config/getfeedconf', array('_secure' =>Mage::app()->getFrontController()->getRequest()->isSecure()));
64
+ }
65
+
66
+ public function getResetAction(){
67
+ return Mage::getUrl('datafeeder/config/reset', array('_secure' => Mage::app()->getFrontController()->getRequest()->isSecure()));
68
+ }
69
+
70
+ public function getEditUrl()
71
+ {
72
+ return Mage::getUrl('*/field/config', array('_secure' => Mage::app()->getFrontController()->getRequest()->isSecure()));
73
+ }
74
+ }
75
+
76
+ ?>
app/code/local/Unbxd/Datafeeder/Helper/.DS_Store ADDED
Binary file
app/code/local/Unbxd/Datafeeder/Helper/Analyticshelper.php ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Unbxd_Datafeeder_Helper_Analyticshelper extends Mage_Core_Helper_Abstract{
3
+
4
+ /**
5
+ * Returns unbxd script tag
6
+ *;
7
+ * @return String
8
+ **/
9
+ public function getAnalyticsScriptTag() {
10
+ $siteName = Mage::getResourceSingleton("datafeeder/conf")->getValue(Mage::app()->getWebsite()->getName() . "/siteName");
11
+ if(is_null($siteName) || $siteName == "" ) {
12
+ Mage::throwException("Unbxd site key is not set");
13
+ }
14
+ $scriptDiv = '<script type="text/javascript">';
15
+ $scriptDiv = $scriptDiv.'var UnbxdSiteName="'.$siteName.'";';
16
+ $scriptDiv = $scriptDiv.'var s=document.createElement("script");';
17
+ $scriptDiv = $scriptDiv.'s.src="//unbxd.s3.amazonaws.com/unbxdAnalytics.js";';
18
+ $scriptDiv = $scriptDiv.'s.type="text/javascript";';
19
+ $scriptDiv = $scriptDiv.'s.async=true;';
20
+ $scriptDiv = $scriptDiv.'document.getElementsByTagName("head").item(0).appendChild(s);';
21
+ $scriptDiv = $scriptDiv.'var s=document.createElement("script");';
22
+ $scriptDiv = $scriptDiv."</script>";
23
+ return $scriptDiv;
24
+ }
25
+
26
+ /**
27
+ * Returns unbxd search box attributes
28
+ *
29
+ * @return String
30
+ **/
31
+ public function getSearchBoxAttribute() {
32
+ return 'unbxdattr="sq"';
33
+ }
34
+
35
+ /**
36
+ * Returns unbxd search box button attributes
37
+ *
38
+ * @return String
39
+ **/
40
+ public function getSearchBoxButtonAttribute() {
41
+ return 'unbxdattr="sq_bt"';
42
+ }
43
+
44
+ /**
45
+ * Returns unbxd navigation meta tag
46
+ *
47
+ * @return String
48
+ **/
49
+ public function getNavigationTag() {
50
+ return '<meta name="unbxd:type" content="category">';
51
+ }
52
+
53
+ /**
54
+ * Returns unbxd product click attributes
55
+ *
56
+ * @return String
57
+ **/
58
+ public function getProductClickAttributes($product, $rank) {
59
+ if (!$product instanceof Mage_Catalog_Model_Product ) {
60
+ Mage::throwException("$product parameter to getProductClickAttributes method should be of type Mage_Catalog_Model_Product");
61
+ }
62
+ if (!$rank || $rank < 1 ) {
63
+ Mage::throwException("$rank parameter to getProductClickAttributes method should be greater than 0");
64
+ }
65
+ return 'unbxdattr="product" unbxdparam_sku="'.$product->getData('entity_id').'" unbxdparam_prank="'.$rank.'"';
66
+ }
67
+
68
+ /**
69
+ * Returns unbxd add to cart attributes
70
+ *
71
+ * @return String
72
+ **/
73
+ public function getAddToCartAttributes($product) {
74
+ if (!$product instanceof Mage_Catalog_Model_Product ) {
75
+ Mage::throwException("$product parameter to getProductClickAttributes method should be of type Mage_Catalog_Model_Product");
76
+ }
77
+ return 'unbxdattr="AddToCart" unbxdparam_sku="'.$product->getData('entity_id').'"';
78
+ }
79
+
80
+ /**
81
+ * Returns unbxd order attributes
82
+ *
83
+ * @return String
84
+ **/
85
+ public function getOrderAttributes($product) {
86
+ if (!$product instanceof Mage_Catalog_Model_Product ) {
87
+ Mage::throwException("$product parameter to getProductClickAttributes method should be of type Mage_Catalog_Model_Product");
88
+ }
89
+ return 'unbxdattr="order" unbxdparam_sku="'.$product->getData('entity_id').'"';
90
+ }
91
+
92
+ /**
93
+ * Checks whether request is a navigation
94
+ *
95
+ * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute
96
+ * @return bool
97
+ */
98
+ public function isNavigation() {
99
+ if(Mage::app()->getRequest()->getControllerName() == "category") {
100
+ return true;
101
+ }
102
+ return false;
103
+ }
104
+ }
105
+ ?>
app/code/local/Unbxd/Datafeeder/Helper/Data.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Unbxd_Datafeeder_Helper_Data extends Mage_Core_Helper_Abstract
4
+ {
5
+
6
+ public function getsetaddressparams()
7
+ {
8
+ $params=$this->_getRequest()->getParams();
9
+ return $params;
10
+ }
11
+
12
+ }
app/code/local/Unbxd/Datafeeder/Helper/UnbxdIndexingHelper.php ADDED
@@ -0,0 +1,682 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * Created on 14-May-2013
4
+ *
5
+ * @author antz(ananthesh@unbxd.com)
6
+ */
7
+
8
+ class Unbxd_Datafeeder_Helper_UnbxdIndexingHelper {
9
+ // This is like to act as a temporary cache, which holds the fieldName to fieldType information
10
+ // so that just to avoid multiple database reads, and make it faster
11
+ var $fieldType = array();
12
+ // This is the name of the logFile which it is writing in to//
13
+ var $logFile;
14
+ // This is also act like a temporary cache, which holds the category id to category information,
15
+ // so that just to avoid multiple database reads, and make it faster
16
+ var $categoryMap = array();
17
+ // size to fetch how much products should it pick in batches
18
+ var $PAGE_SIZE = 500;
19
+ // the file to write to..
20
+ var $file;
21
+ // fields to be selected to push to unbxd
22
+ var $fields;
23
+ // Feed unlock interval
24
+ //LOCK_TIMEOUT = 60 * 30;
25
+
26
+ public function __construct(){
27
+ $this->logFile = Mage::getBaseDir('log').DS.'generic.log';
28
+ $this->file = Mage::getBaseDir('tmp').DS.'unbxdFeed.xml';
29
+ $this-log("calling setfeilds method");
30
+ $this->fields = array();
31
+ $this-> setFieldType();
32
+ }
33
+
34
+ public function setFields($site) {
35
+ $this->fields = Mage::getResourceSingleton('datafeeder/field')->getEnabledFields($site);
36
+ $this-log("inside setfeilds method");
37
+ $this->fields[] = 'entity_id';
38
+ $this->log("fields are " .json_encode($this->fields));
39
+ }
40
+
41
+ /**
42
+ * Function to create a file
43
+ */
44
+ private function createXmlFile(){
45
+ try{
46
+ $f=fopen($this->file,'w');
47
+
48
+ fclose($f);
49
+ if(!file_exists($this->file)) {
50
+ $this->log("UNBXD_MODULE:Couldn't create the file");
51
+ return false;
52
+ }
53
+ $this->log("UNBXD_MODULE: created the file");
54
+ return true;
55
+ } catch (Exception $ex) {
56
+ $this->log("UNBXD_MODULE:Error while creating the file");
57
+ $this->log($ex->getMessage());
58
+ return false;
59
+ }
60
+ }
61
+
62
+ /**
63
+ * Function to append the contents to the file
64
+ */
65
+ private function appendTofile($content){
66
+ try{
67
+
68
+ if(file_put_contents($this->file, $content, FILE_APPEND)) {
69
+ return true;
70
+ } else {
71
+ return false;
72
+ }
73
+ } catch(Exception $ex) {
74
+ $this->log("UNBXD_MODULE:Error while appending the contents to feed file");
75
+ $this->log($ex->getMessage());
76
+ return false;
77
+ }
78
+ }
79
+
80
+
81
+ /**
82
+ * Function to create a file
83
+ */
84
+ private function createLogFile(){
85
+ try {
86
+ $f=fopen($this->logFile,'w');
87
+ fclose($f);
88
+ return true;
89
+ } catch (Exception $ex) {
90
+ error_log("UNBXD_MODULE:Error while creating the file");
91
+ error_log($ex->getMessage());
92
+ return false;
93
+ }
94
+ }
95
+
96
+ /**
97
+ * Function to appened the contents to the file
98
+ */
99
+ public function log($content){
100
+ try{
101
+ $resp = file_put_contents($this->logFile, date('Y-m-d H:i:s').$content."\n", FILE_APPEND);
102
+ if($resp){
103
+ return true;
104
+ } else {
105
+ error_log("UNBXD_MODULE:Error while appending the contents to log file");
106
+ return false;
107
+ }
108
+ return true;
109
+ }catch(Exception $ex) {
110
+ error_log("UNBXD_MODULE:Error while appending the contents to log file");
111
+ Mage::throwException($ex->getMessage());
112
+ return false;
113
+ }
114
+ }
115
+
116
+ /**
117
+ * Function to delete the file
118
+ */
119
+ private function deleteFile(){
120
+ unlink($this->file);
121
+ }
122
+
123
+ /**
124
+ * function to get the file name
125
+ */
126
+ private function getFile(){
127
+ return $this->file;
128
+ }
129
+
130
+ /**
131
+ * Write Header contents to the file
132
+ *
133
+ */
134
+ private function writeXmlHeaderContents($operation){
135
+ $headerContent="<feed>"."<taxonomyname>".$this->tax.
136
+ "</taxonomyname><username>unbxd</username>".
137
+ "<feedname>feed</feedname>".
138
+ "<entry>"."<data>" .
139
+ "<unbxdActionType>".$operation.
140
+ "</unbxdActionType>"."<products>";
141
+
142
+ return $this->appendTofile($headerContent);
143
+
144
+ }
145
+
146
+ /**
147
+ * function to append the xml footer contents to the file
148
+ *
149
+ */
150
+ private function writeXmlFooterContents(){
151
+ $footerContent="</products></data></entry></feed>";
152
+ return $this->appendTofile($footerContent);
153
+ }
154
+
155
+ /**
156
+ * function to append the product contents to the file
157
+ */
158
+ private function writeXmlProductContents($fromdate,$todate,$site,$operation,$ids){
159
+
160
+
161
+ $collection=$this->getCatalogCollection($fromdate,$todate,$site,$operation,$ids);
162
+ // get total size
163
+ //set the time limit to infinite
164
+ set_time_limit(0);
165
+ $pageNum = 0;
166
+ $this->log('started writing products');
167
+
168
+ while(true){
169
+ $collection->clear();
170
+ $collection->getSelect()->limit($this->PAGE_SIZE, ($pageNum++) * $this->PAGE_SIZE);
171
+ $collection->load();
172
+ echo "<pre>";print_r($collection);echo "</pre>";
173
+ if(count($collection) == 0){
174
+ if($pageNum == 1){
175
+ $this->log("No products found");
176
+ return false;
177
+ }
178
+ break;
179
+ }
180
+ $content=$this->getCollectionInXML($collection, $operation);
181
+ $status=$this->appendTofile($content);
182
+ if(!$status){
183
+ return false;
184
+ }
185
+ $this->log('Added '.($pageNum) * $pageSize.' products');
186
+ }
187
+
188
+ $this->log('Added all products');
189
+ return true;
190
+ }
191
+
192
+ /**
193
+ ** This method iterates over the collection and builds the xml for product object
194
+ **
195
+ **/
196
+ private function getCollectionInXML($collection, $operation){
197
+
198
+ $content='';
199
+ $count=0;
200
+ foreach($collection as $product){
201
+ $count++;
202
+ $content=$content.'<product>';
203
+ $content=$content.$this->getProductInXML($product, $operation);
204
+ $content=$content.'</product>';
205
+ }
206
+
207
+ return $content;
208
+ }
209
+
210
+ /**
211
+ ** This method builds xml string, given the product object
212
+ **
213
+ **/
214
+ private function getProductInXML($product, $operation){
215
+ $content='';
216
+ if($operation != "add"){
217
+ return $this->getAttributesInXML('uniqueId',$product->getData('entity_id'));
218
+ }
219
+
220
+ foreach($product->getData('') as $columnHeader=>$columndata){
221
+
222
+ if(!in_array($columnHeader, $this->fields)) {
223
+ continue;
224
+ }
225
+ if(is_null($columndata)|| !isset($columndata) || $columndata==""){
226
+ continue;
227
+ }
228
+ if($columnHeader=="entity_id"){
229
+ $content=$content. $this->getAttributesInXML('uniqueId',$columndata);
230
+ }
231
+ if($columnHeader=="name"){
232
+ $content=$content. $this->getAttributesInXML('productname',$columndata);
233
+ }
234
+ if($columnHeader=="small_image"){
235
+ $content=$content. $this->getAttributesInXML('image_url',$columndata);
236
+ }
237
+
238
+ if($columnHeader=="entity_id"){
239
+ $content=$content. $this->getAttributesInXML('uniqueId',$columndata);
240
+ }
241
+ if($columnHeader == "visibility") {
242
+ $content = $content.$this->getAttributesInXML('unbxdVisibility', $columndata);
243
+ }
244
+ if($columnHeader=="url_path"){
245
+ $content=$content. $this->getAttributesInXML('url', Mage::getUrl('').$columndata);
246
+ $content=$content. $this->getAttributesInXML('url_path', Mage::getUrl('').$columndata);
247
+ } else if( $this->isMultiSelect($columnHeader) && $columnHeader != "status"){
248
+ $data = explode(",", $columndata);
249
+ $attributeModel = Mage::getResourceSingleton("datafeeder/attribute");
250
+ foreach( $data as $eachdata){
251
+ $attributeValue = $attributeModel ->getAttributeValue($columnHeader, trim($eachdata), $product);
252
+ $value = $value .$this->getAttributesInXML($columnHeader,$attributeModel ->getAttributeValue($columnHeader, trim($eachdata), $product));
253
+ if(isset($this->filterable[$columnHeader]) && ($this->filterable[$columnHeader] == 1) && isset($attributeValue) && $attributeValue != ""){
254
+ $value = $value.$this->getAttributesInXML($columnHeader."_id", trim($eachdata));
255
+ }
256
+ }
257
+ } else if($columnHeader == "created_at" ||$columnHeader == "updated_at") {
258
+ $tokens = explode(" ",$columndata);
259
+ $columndata =$tokens[0].'T'.$tokens[1].'Z';
260
+ $value =$this->getAttributesInXML($columnHeader,$columndata);
261
+ } else if($columnHeader == "category_id"){
262
+ if(!isset($columndata)){
263
+ continue;
264
+ }
265
+ $categoryIds = explode(",",$columndata);
266
+ foreach($categoryIds as $categoryId){
267
+ $value = $value.$this->getAttributesInXML($columnHeader, trim($categoryId));
268
+ $value = $value.$this->getAttributesInXML("unbxdTaxonomyId",trim($categoryId));
269
+ $value = $value.$this->getAttributesInXML("category",$this->getCategoryName(trim($categoryId)));
270
+ }
271
+
272
+ } else if (is_array($columndata)){
273
+ $value = $this->getArrayAttributesInXML($columnHeader,$columndata);
274
+ } else if ($columndata instanceof Varien_Object){
275
+ $value = $this->getArrayAttributesInXML($columnHeader,$columndata->getData());
276
+ } else if ( !isset($value) || $value == ""){
277
+ $value =$this->getAttributesInXML($columnHeader, $columndata);
278
+ }
279
+ $content = $content.$value;
280
+ $value = "";
281
+ }
282
+
283
+ $content=$content.$this->getCategoryAttribute($product);
284
+ $content=$content.$this->getAttributesInXML('store','default');
285
+ return $content;
286
+ }
287
+
288
+ /*
289
+ * function to check whether the field is a multiSelect/select or not,
290
+ * This is optimized method, where it doesn't make a database call to get fieldType
291
+ * where it fetches from the local variable, which holds the information of field to fieldType mapping
292
+ */
293
+ public function isMultiSelect($attributeName = ""){
294
+ if($this->getFieldType($attributeName) == "select" || $this->getFieldType($attributeName) == "multiselect" || $attributeName == "categoryIds"){
295
+ return true;
296
+ }
297
+ return false;
298
+ }
299
+
300
+
301
+ public function isImage($attributeName = "") {
302
+ if($this->getFieldType($attributeName) == "media_image") {
303
+ return true;
304
+ }
305
+ return false;
306
+ }
307
+
308
+ /**
309
+ * function to get Category from the category id,
310
+ * This checks it present in the global array 'categoryMap', if it is not there fetches from db
311
+ * So that once it gets one category, it doesn't make db call again for the same category
312
+ */
313
+ public function getCategory($category_id = ""){
314
+ if(!isset($this->categoryMap[$category_id])){
315
+ $category = Mage::getModel('catalog/category')->load($category_id);
316
+ $this->categoryMap[$category_id] = $category;
317
+ return $this->categoryMap[$category_id];
318
+ }
319
+ return $this->categoryMap[$category_id];
320
+ }
321
+
322
+ /**
323
+ * Method to get stock attribute in xml given the product
324
+ */
325
+ private function getStockAttribute($product){
326
+ $model = Mage::getModel('catalog/product');
327
+ $_product = $model->load($product->getId());
328
+ $stocklevel = Mage::getModel('cataloginventory/stock_item')
329
+ ->loadByProduct($product)->getQty();
330
+
331
+ $content=$this->getAttributesInXML("stock",$stocklevel);
332
+
333
+ if($stocklevel > 0){
334
+ $content=$content.$this->getAttributesInXML("Instock","1");
335
+ }
336
+ else{
337
+ $content=$content.$this->getAttributesInXML("Instock","0");
338
+ }
339
+ return $content;
340
+ }
341
+
342
+ /**
343
+ * method to get category content in xml given the product object
344
+ */
345
+ private function getCategoryAttribute($product){
346
+ $cats = $product->getCategoryIds();
347
+ $categoryId=array();
348
+ $category=array();
349
+ $content = "";
350
+ foreach ($cats as $category_id) {
351
+
352
+ $_cat = $this->getCategory($category_id);
353
+ $categoryId[]=$category_id;
354
+ $category[]=$_cat->getName();
355
+ }
356
+
357
+ $content=$content.$this->getArrayAttributesInXML("categoryIds",$categoryId);
358
+ $content=$content.$this->getArrayAttributesInXML("unbxdTaxonomyId",$categoryId);
359
+ $content=$content.$this->getArrayAttributesInXML("category",$category);
360
+ return $content;
361
+ }
362
+
363
+ /**
364
+ * method to get the xml content given the fieldname and array
365
+ */
366
+ private function getArrayAttributesInXML($columnHeader,$columndata){
367
+ $content='';
368
+
369
+ foreach($columndata as $element){
370
+ $content=$content.$this->getAttributesInXML($columnHeader,$element);
371
+ }
372
+
373
+ return $content;
374
+ }
375
+
376
+ /**
377
+ * method to get the xml content given the fieldname and value
378
+ */
379
+ private function getAttributesInXML($columnHeader,$columndata){
380
+
381
+ $columnHeader=$this->_escapeXMLHeader($columnHeader);
382
+ $content = $this->_escapeXMLValue($columndata);
383
+ $content = iconv("ISO-8859-1", "UTF-8", $content);
384
+ if($content != '' && $columnHeader != ''){
385
+ return '<'.$columnHeader.'>'.$content.'</'.$columnHeader.'>';
386
+ }else{
387
+ return '';
388
+ }
389
+ }
390
+
391
+ /**
392
+ * method to escape the xml header contents
393
+ */
394
+ private function _escapeXMLHeader($columnHeader){
395
+ if(is_numeric(substr($columnHeader,0,1))){
396
+ $columnHeader ='_'.$columnHeader;
397
+ }
398
+ return str_replace(' ','_',$columnHeader);
399
+ }
400
+
401
+ /**
402
+ * method to escape the xml contents
403
+ */
404
+ private function _escapeXMLValue($str){
405
+ $encryptedString = "";
406
+ $strlen = strlen( $str );
407
+ for( $i = 0; $i <= $strlen; $i++ ) {
408
+ $char = substr( $str, $i, 1 );
409
+ if(ord($char) == 11){
410
+ continue;
411
+ }
412
+ if((ord($char) < 32) && (ord($char) > 0) && (ord($char) != 9) && (ord($char) != 10) && (ord($char) != 13)){
413
+ $controlCharacter = true;
414
+ } else {
415
+ $controlCharacter = false;
416
+ }
417
+ $unicodeButNotAscii = (ord($char) > 126) ? true: false;
418
+ if ( ($char == "<") || ($char == "&") || ($char == ">") || ($char == '"') || ($char == "'")) {
419
+ $characterWithSpecialMeaningInXML =true;
420
+ } else {
421
+ $characterWithSpecialMeaningInXML =false;
422
+ }
423
+ if ($controlCharacter || $characterWithSpecialMeaningInXML || $unicodeButNotAscii) {
424
+ $encryptedString = $encryptedString . "&#" . (ord($char)) . ";" ;
425
+ } else {
426
+ $encryptedString = $encryptedString.$char;
427
+ }
428
+ }
429
+ return $encryptedString;
430
+ }
431
+
432
+ /**
433
+ * method to get the catalog collection
434
+ *
435
+ */
436
+ private function getCatalogCollection($fromdate,$todate,$site,$operation,$ids) {
437
+ try{
438
+ if ($operation == "add") {
439
+ // select all the attributes
440
+ $website =Mage::getModel("core/website")->setName($site);
441
+ $visiblityCondition = array('in' => array(4));
442
+
443
+ $collection = Mage::getResourceModel('catalog/product_collection')
444
+ ->addWebsiteFilter($this->validateSite($site))
445
+ ->addAttributeToFilter('status',1)
446
+ ->joinField("qty", "cataloginventory_stock_item", 'qty', 'product_id=entity_id', null, 'left')
447
+ ->addAttributeToSelect('*')
448
+ ->addAttributeToFilter('visibility',$visiblityCondition);
449
+
450
+ if(sizeof($ids) > 0){
451
+ $condition = array('in' => $ids);
452
+ $collection=$collection->addAttributeToFilter('entity_id',$condition);
453
+ }
454
+ } else {
455
+ $collection = Mage::getResourceModel('catalog/product_collection');
456
+ if(sizeof($ids) > 0) {
457
+ $condition = array('in' => $ids);
458
+ $collection = $collection->addAttributeToFilter('entity_id',$condition)->addAttributeToSelect('entity_id');
459
+ }
460
+ }
461
+
462
+ $this->log($collection->getSelect());
463
+ return $collection;
464
+ } catch(Exception $e) {
465
+ $this->log($e->getMessage());
466
+ }
467
+ }
468
+
469
+ /**
470
+ * method to get all the attributes
471
+ **/
472
+ public function getAttributes(){
473
+ return Mage::getSingleton('eav/config')
474
+ ->getEntityType(Mage_Catalog_Model_Product::ENTITY)->getAttributeCollection();
475
+ }
476
+
477
+ /**
478
+ * method to get field type of the field
479
+ **/
480
+ private function getFieldType($attributeName){
481
+ if(array_key_exists( $attributeName, $this->fieldType)){
482
+ return $this->fieldType[$attributeName];
483
+ } else {
484
+ return "text";
485
+ }
486
+ }
487
+
488
+ /**
489
+ * method to set field type to the global object
490
+ **/
491
+ private function setFieldType(){
492
+ $attributes = $this->getAttributes();
493
+ foreach($attributes as $attribute){
494
+ $this->filterable[$attribute->getAttributeCode()] = $attribute->getData('is_filterable');
495
+ $this->fieldType[$attribute->getAttributeCode()] = $attribute-> getFrontendInput();
496
+ }
497
+ }
498
+
499
+ /**
500
+ * method to get the zend date condition
501
+ */
502
+ private function getDateCondition($fromdate,$todate){
503
+ return array('from'=>$fromdate,'to'=>$todate,'date'=>true,);
504
+ }
505
+
506
+ /**
507
+ * method to create the feed
508
+ **/
509
+ public function createFeed($fromdate,$todate,$site,$operation,$ids){
510
+ if($this->createXmlFile()){
511
+ $this->log("started writing header");
512
+ if(!$this->writeXmlHeaderContents($operation)){
513
+ return false;
514
+ }
515
+ $this->log('Added header contents');
516
+ try{
517
+ if(!$this->writeXmlProductContents($fromdate,$todate,$site,$operation,$ids)){
518
+ return false;
519
+ }
520
+ }catch(Exception $e){
521
+ $this->log($e->getMessage());
522
+ $this->log($e->getTraceAsString());
523
+ return false;
524
+ }
525
+ $this->log('Added products');
526
+
527
+ if(!$this->writeXmlFooterContents()){
528
+ return false;
529
+ }
530
+ } else {
531
+ return false;
532
+ }
533
+ return true;
534
+ }
535
+
536
+ /**
537
+ * method to initiate task after index
538
+ **/
539
+ private function _afterIndex(){
540
+ $this->deleteFile();
541
+ }
542
+
543
+ /**
544
+ * method to validate whether the site exists or not
545
+ **/
546
+ public function validateSite($site){
547
+ $sites=Mage::app()->getWebsites();
548
+ if( !isset($site) || $site == "") {
549
+ return false;
550
+ }
551
+ foreach( $sites as $eachSite){
552
+ if(strcasecmp ( $eachSite->getName(), $site ) == 0 ){
553
+ return $eachSite->getWebsiteId();
554
+ }
555
+ }
556
+ return -1;
557
+ }
558
+
559
+ /**
560
+ * method to set the feedName, log, apikey based on site Name
561
+ **/
562
+ public function setUnbxdConf($site)
563
+ {
564
+ $this->key = Mage::getResourceSingleton("datafeeder/conf")->getValue("apiKey");
565
+ $this->feedName = Mage::getResourceSingleton("datafeeder/conf")->getValue($site."/feed");
566
+ $this->tax = Mage::getResourceSingleton("datafeeder/conf")->getValue($site."/tax");
567
+ $this->logFile = Mage::getBaseDir('log').DS.substr($site,0,strrpos($site, ".")-1).'unbxdDataFeeder.log';
568
+ $this->file = Mage::getBaseDir('tmp').DS.substr($site,0,strrpos($site, ".")-1).'unbxdFeed.xml';
569
+ if (!$this->log("Feed uploading started")) {
570
+ error_log("No permission to write to " + Mage::getBaseDir('log'));
571
+ return false;
572
+ }
573
+ if(!isset($this->key) || $this->key == "" || $this->key == "empty"){
574
+ $this->log("api key not set");
575
+ return false;
576
+ }
577
+ if(!isset($this->feedName) || $this->feedName == "" || $this->feedName == "empty"){
578
+ $this->log("Feed Name not set");
579
+ return false;
580
+ }
581
+ $this->setFields($site);
582
+ return true;
583
+ }
584
+
585
+ /**
586
+ * method to initiate feed uploading to the unbxd servers
587
+ **/
588
+ public function indexUnbxdFeed($fromdate,$site,$operation = "add", $ids=array()){
589
+
590
+ $this->log('unbxd Datafeeder initiated');
591
+ // validatest the site
592
+ if($this->validateSite($site) == -1){
593
+ $this->log("Invalid site Name".$site);
594
+ return;
595
+ }
596
+ // set the basic
597
+ if(! $this->setUnbxdConf($site)){
598
+ return;
599
+ }
600
+ $todate =date('Y-m-d H:i:s');
601
+
602
+ // check the lock, that if already indexing is happening
603
+ if($this->checkSiteLock($site)){
604
+ $this->log('site '. $site.' has been locked');
605
+ $action=$site.'/status';
606
+ // lock the feed
607
+ Mage::getResourceSingleton("datafeeder/conf")->updateAction($action,'1');
608
+ // create the feed
609
+
610
+ $status=$this->createFeed($fromdate,$todate,$site,$operation,$ids);
611
+ $this->log('unbxd Datafeeder finished creating file');
612
+
613
+ if($status){
614
+ try{
615
+ // if successful push it to unbxd servers
616
+ $status=$this->pushFeed($site);
617
+ }catch(Exception $e){
618
+ $this->log($e->getMessage());
619
+
620
+ }
621
+ if($status){
622
+ Mage::getResourceSingleton("datafeeder/conf")->updateAction('Lastindex',$todate);
623
+ }
624
+ }
625
+ // unlock the feed once everything is completed
626
+ Mage::getResourceSingleton("datafeeder/conf")->updateAction($action,'0');
627
+ $this->log('site '. $site.' has been unlocked');
628
+ } else {
629
+ $this->log('Feed Uploading failed because site has been locked');
630
+ }
631
+ }
632
+
633
+
634
+ /**
635
+ * method to push the feed to the Unbxd server
636
+ **/
637
+ public function pushFeed($site){
638
+ $fields=array('file'=>'@'.$this->file.';filename=unbxdFeedRenamed.xml');
639
+ $header = array('Content-Type: multipart/form-data');
640
+
641
+ $url="feed.unbxdapi.com/upload/".$this->key."/".$this->feedName;
642
+ //clear the feed
643
+ $clearFeedUrl = "http://feed.unbxdapi.com/clearfeed.do?key=".$this->key."&feedName=".$this->feedName;
644
+ file_get_contents($clearFeedUrl);
645
+ $this->log('cleared the feed');
646
+
647
+
648
+ $ch = curl_init();
649
+ curl_setopt($ch, CURLOPT_URL,$url);
650
+ curl_setopt($ch, CURLOPT_POST,true);
651
+ curl_setopt($ch, CURLOPT_POSTFIELDS,$fields);
652
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
653
+ try{
654
+ $this->log('pushing the feed');
655
+ // push the feed to the server
656
+ $response = curl_exec ($ch);
657
+ }catch(Exception $Ex){
658
+ $this->log($Ex->getMessage());
659
+ return false;
660
+ }
661
+ $this->log($response);
662
+ curl_close($ch);
663
+ return true;
664
+ }
665
+
666
+ /**
667
+ * method to check the status of the uploading
668
+ **/
669
+ public function checkSiteLock($site)
670
+ {
671
+ $value = Mage::getResourceSingleton("datafeeder/conf")->getValue($site."/status");
672
+ if($value == '0' || $value == 'empty'){
673
+ $this->log("true");
674
+ return true;
675
+ }else{
676
+ $this->log("false". $value);
677
+ return false;
678
+ }
679
+ }
680
+ }
681
+ ?>
682
+
app/code/local/Unbxd/Datafeeder/Helper/UnbxdTaxonomyHelper.php ADDED
@@ -0,0 +1,318 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Unbxd_Datafeeder_Helper_UnbxdTaxonomyHelper{
3
+
4
+ var $file='unbxdTaxonomy.xml';
5
+
6
+
7
+ public function __construct(){
8
+ $this->file = Mage::getBaseDir('tmp').DS.'unbxdTaxonomy.xml';
9
+ }
10
+ /**
11
+ * Function to create a file
12
+ */
13
+ private function createXmlFile(){
14
+ try{
15
+ $f=fopen($this->file,'w');
16
+ fclose($f);
17
+ return true;
18
+ } catch (Exception $Ex)
19
+ {
20
+ error_log("UNBXD_MODULE:Error while creating the file");
21
+ error_log($Ex->getMessage());
22
+ return false;
23
+ }
24
+ }
25
+
26
+ /**
27
+ * Function to appened the contents to the file
28
+ */
29
+ private function appendTofile($content){
30
+ try{
31
+
32
+ file_put_contents($this->file, $content, FILE_APPEND);
33
+ return true;
34
+ }catch(Exception $Ex){
35
+ error_log("UNBXD_MODULE:Error while appending the contents to file");
36
+ error_log($Ex->getMessage());
37
+ return false;
38
+ }
39
+ }
40
+
41
+ private function log($content){
42
+ try{
43
+ file_put_contents($this->logFile, date('Y-m-d H:i:s').$content."\n", FILE_APPEND);
44
+ return true;
45
+ }catch(Exception $Ex){
46
+ error_log("UNBXD_MODULE:Error while appending the contents to file");
47
+ Mage::throwException($Ex->getMessage());
48
+ return false;
49
+ }
50
+ }
51
+
52
+ /**
53
+ * Function to delete the file
54
+ */
55
+ private function deleteFile(){
56
+ unlink($this->file);
57
+ }
58
+
59
+ private function writeXMLHeaderContents(){
60
+ $content="<feed>
61
+ <username>unbxd</username>
62
+ <taxonomyname>tax</taxonomyname>";
63
+ return $this->appendTofile($content);
64
+ }
65
+
66
+
67
+ private function writeXMLFooterContents(){
68
+ $content="</feed>";
69
+ return $this->appendTofile($content);
70
+ }
71
+
72
+
73
+
74
+ private function writeXMLProductsContents($site){
75
+ $stores= $this->getStores($site);
76
+ foreach( $stores as $store){
77
+ $categories=$this->getStoreCategories($store);
78
+ $content='';
79
+ $count=0;
80
+ $content=$content.'<category>';
81
+ $content=$content.$this->getAttributesInXML("name",$site);
82
+ $content=$content.$this->getAttributesInXML("parents","-1");
83
+ $content=$content.$this->getAttributesInXML("id",1);
84
+ $content=$content.$this->getAttributesInXML("url","unbxd");
85
+ $content=$content.'</category>';
86
+ foreach($categories as $category){
87
+ if( $category->getName()== "" ){
88
+ continue;
89
+ }
90
+ $content =$content.$this->getCategoryContent($category);
91
+ $category_obj = Mage::getModel('catalog/category')->load($category->getId());
92
+ $childrens = $category_obj->getAllChildren(true);
93
+ $childrenCategories = Mage::getModel('catalog/category')->getCollection()->addIdFilter($childrens)->addAttributeToSelect('*')->load();
94
+
95
+ foreach($childrenCategories as $childCategory){
96
+ $content=$content.$this->getCategoryContent($childCategory);
97
+ }
98
+ }
99
+ }
100
+ return $this->appendTofile($content);
101
+ }
102
+
103
+ private function getCategoryContent($category){
104
+ $content='';
105
+ $content=$content.'<category>';
106
+ $content=$content.$this->getAttributesInXML("name",$category->getName());
107
+ $content=$content.$this->getAttributesInXML("parents",$category->getParentId());
108
+ $content=$content.$this->getAttributesInXML("id",$category->getId());
109
+ $content=$content.$this->getAttributesInXML("url","unbxd");
110
+ $content=$content.'</category>';
111
+ $content=$content."\n";
112
+ return $content;
113
+ }
114
+
115
+
116
+
117
+ private function getAllCategories($site){
118
+ $collection = Mage::getModel('catalog/category')->getCollection()
119
+ ->setStoreId($this->getStores($site))
120
+ ->addAttributeToSelect('name')
121
+ ->addAttributeToSelect('id');
122
+
123
+ return $collection->load();
124
+
125
+ }
126
+
127
+ private function getStores($site){
128
+ $sites=Mage::app()->getWebsites();
129
+ foreach( $sites as $eachSite){
130
+ if(strcasecmp ( $eachSite->getName(), $site ) == 0 ){
131
+ return $eachSite->getStores();
132
+ }
133
+ }
134
+ }
135
+
136
+
137
+
138
+ private function getAttributesInXML($columnHeader,$columndata){
139
+
140
+ $columnHeader=$this->_escapeXMLHeader($columnHeader);
141
+ $content=$this->_escapeXMLValue($columndata);
142
+ return '<'.$columnHeader.'>'.$content.'</'.$columnHeader.'>';
143
+ }
144
+
145
+ private function _escapeXMLHeader($columnHeader){
146
+
147
+ return str_replace(' ','_',$columnHeader);
148
+ }
149
+
150
+ private function _escapeXMLValue($columndata){
151
+
152
+ return strtr($columndata,array(
153
+ "<" => "&lt;",
154
+ ">" => "&gt;",
155
+ '"' => "&quot;",
156
+ "'" => "&apos;",
157
+ "&" => "&amp;",
158
+ ));
159
+ }
160
+
161
+
162
+ public function createFeed($site){
163
+ $this->log('creating xml file');
164
+ if($this->createXmlFile()){
165
+ if(!$this->writeXmlHeaderContents()){
166
+ return false;
167
+ }
168
+ $this->log('writing header');
169
+ if(!$this->writeXMLProductsContents($site)){
170
+ return false;
171
+ }
172
+ $this->log('writing content');
173
+ if(!$this->writeXmlFooterContents()){
174
+ return false;
175
+ }
176
+ $this->log('writing footer');
177
+ } else {
178
+ return false;
179
+ }
180
+ return true;
181
+ }
182
+
183
+ public function validateSite($site){
184
+ $sites=Mage::app()->getWebsites();
185
+ if( !isset($site) || $site == "") {
186
+ return false;
187
+ }
188
+ foreach( $sites as $eachSite){
189
+ if(strcasecmp ( $eachSite->getName(), $site ) == 0 ){
190
+ return $eachSite->getWebsiteId();
191
+ }
192
+ }
193
+ return -1;
194
+ }
195
+
196
+ public function getStoreCategories($store, $sorted=false, $asCollection=false, $toLoad=true)
197
+ {
198
+ $parent = $store->getRootCategoryId();
199
+
200
+ /**
201
+ * Check if parent node of the store still exists
202
+ */
203
+ $category = Mage::getModel('catalog/category');
204
+ /* @var $category Mage_Catalog_Model_Category */
205
+ if (!$category->checkId($parent)) {
206
+ if ($asCollection) {
207
+ return new Varien_Data_Collection();
208
+ }
209
+ return array();
210
+ }
211
+
212
+ $recursionLevel = max(0, (int) Mage::app()->getStore()->getConfig('catalog/navigation/max_depth'));
213
+ $tree = Mage::getResourceModel('catalog/category_tree');
214
+ /* @var $tree Mage_Catalog_Model_Resource_Category_Tree */
215
+ $nodes = $tree->loadNode($parent)
216
+ ->loadChildren($recursionLevel)
217
+ ->getChildren();
218
+
219
+ $tree->addCollectionData(null, $sorted, $parent, $toLoad, false);
220
+ if ($asCollection) {
221
+ return $tree->getCollection();
222
+ }
223
+ return $nodes;
224
+ }
225
+
226
+ public function setUnbxdConf($site){
227
+
228
+ $this->key = Mage::getResourceSingleton("datafeeder/conf")->getValue("apiKey");
229
+ $this->feedName = Mage::getResourceSingleton("datafeeder/conf")->getValue($site."/feed");
230
+ $this->tax = Mage::getResourceSingleton("datafeeder/conf")->getValue($site."/tax");
231
+ $this->logFile = Mage::getBaseDir('log').DS.substr($site,0,strrpos($site, ".")-1).'unbxdDataFeeder.log';
232
+ $this->file = Mage::getBaseDir('tmp').DS.substr($site,0,strrpos($site, ".")-1).'unbxdTaxonomyFeed.xml';
233
+ if(!isset($this->key) || $this->key == "" || $this->key == "empty"){
234
+ $this->log("api key not set");
235
+ return false;
236
+ }
237
+ if(!isset($this->feedName) || $this->feedName == "" || $this->feedName == "empty"){
238
+ $this->log("Feed Name not set");
239
+ return false;
240
+ }
241
+ return true;
242
+ }
243
+
244
+ public function indexUnbxdFeed($site){
245
+
246
+ $this->log('unbxd Datafeeder initiated');
247
+ if($this->validateSite($site) == -1){
248
+ $this->log("Invalid site Name".$site);
249
+ return;
250
+ }
251
+ if(! $this->setUnbxdConf($site)){
252
+ return;
253
+ }
254
+ if(true){
255
+ $action='taxonomyStatus';
256
+ $this->updateAction($action,'1');
257
+ $status=$this->createFeed($site);
258
+
259
+ if($status){
260
+ $status=$this->pushFeed();
261
+ }
262
+ $action='taxonomyStatus';
263
+ $this->updateAction($action,'0');
264
+
265
+ }
266
+ }
267
+
268
+
269
+ public function pushFeed(){
270
+
271
+ $fields=array('file'=>'@'.$this->file.";filename=unbxdFeedRenamed.xml");
272
+ $url="http://feed.unbxdapi.com/taxonomy/upload/".$this->key."/".$this->tax;
273
+
274
+
275
+ $ch = curl_init();
276
+ curl_setopt($ch, CURLOPT_URL,$url);
277
+ curl_setopt($ch,CURLOPT_POST,true);
278
+ curl_setopt($ch,CURLOPT_POSTFIELDS,$fields);
279
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
280
+ try{
281
+ $response = curl_exec($ch);
282
+ }catch(Exception $Ex){
283
+ error_log($Ex->getMessage());
284
+ return false;
285
+ }
286
+ $this->log($response);
287
+ return true;
288
+
289
+ }
290
+
291
+ public function checkStatus()
292
+ {
293
+ $action='taxonomyStatus';
294
+ $collection=Mage::getModel('datafeeder/conf')->getCollection()
295
+ ->addFieldToFilter('action',$action);
296
+
297
+ $count=0;
298
+ foreach($collection as $coll){
299
+ $count++;
300
+ $value=$coll->getvalue();
301
+ }
302
+ if($count==0){
303
+ $collection=Mage::getModel('datafeeder/conf')
304
+ ->setAction($action)->setValue("0")->save();
305
+ $value="0";
306
+ }
307
+ if($value=='0'){
308
+ return true;
309
+ } else {
310
+ return false;
311
+ }
312
+ }
313
+
314
+ public function updateAction($action,$value){
315
+ Mage::getResourceSingleton("datafeeder/conf")->updateAction($action, $value);
316
+ }
317
+ }
318
+ ?>
app/code/local/Unbxd/Datafeeder/Model/Attribute.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Unbxd_Datafeeder_Model_Attribute{
4
+
5
+ $attributeMap = array();
6
+ public function getAttributeValue($attributeCode, $label, $product){
7
+ if(!isset($this->attributeMap[$label])){
8
+ if(!($product instanceof Mage_Catalog_Model_Product)){
9
+ return null;
10
+ }
11
+ $options = $product->getAttribute($attributeCode)
12
+ ->getSource()->getAllOptions();
13
+ foreach($options as $option){
14
+ $this->attributeMap[$option["label"]] = $option["value"];
15
+ }
16
+ }
17
+ return array_key_exists($value, $this->attributeMap)?$this->attributeMap[$value]:NULL;
18
+ }
19
+
20
+ }
21
+
22
+ ?>
app/code/local/Unbxd/Datafeeder/Model/Conf.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Unbxd_Datafeeder_Model_Conf extends Mage_Core_Model_Abstract {
4
+
5
+
6
+ protected function _construct()
7
+ {
8
+ $this->_init('datafeeder/conf');
9
+ }
10
+ }
11
+
12
+ ?>
app/code/local/Unbxd/Datafeeder/Model/Facet.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Unbxd_Datafeeder_Model_Facet extends Mage_Core_Model_Abstract {
4
+
5
+
6
+ protected function _construct()
7
+ {
8
+ $this->_init('datafeeder/facet');
9
+ }
10
+
11
+
12
+ }
13
+
14
+ ?>
app/code/local/Unbxd/Datafeeder/Model/Feed/Feedcreator.php ADDED
@@ -0,0 +1,321 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Unbxd_Datafeeder_Model_Feed_Feedcreator {
4
+
5
+ var $fileName;
6
+
7
+ var $fields;
8
+
9
+ const STATUS = 'status';
10
+ const DATA_TYPE = 'data_type';
11
+ const AUTOSUGGEST = 'autosuggest';
12
+
13
+
14
+ const PAGE_SIZE = 500;
15
+ public function __construct(){
16
+ }
17
+
18
+ public function init($site, $fileName) {
19
+ Mage::getSingleton('unbxd_datafeeder/feed_filemanager')->setLog(str_replace(' ', '_',$site)."_Datafeeder.log");
20
+ $this->setFields($site);
21
+ $this->fileName = $fileName;
22
+ }
23
+
24
+
25
+ /**
26
+ * method to create the feed
27
+ **/
28
+ public function createFeed($fileName, $fromdate,$todate,$site,$operation,$ids){
29
+ $this->init($site, $fileName);
30
+ if($this->createFile()){
31
+ $this->log("started writing header");
32
+
33
+ if(!$this->writeFeedContent($fromdate,$todate,$site,$operation,$ids)){
34
+ return false;
35
+ }
36
+
37
+ } else {
38
+ return false;
39
+ }
40
+ return true;
41
+ }
42
+
43
+ private function writeFeedContent($fromdate,$todate,$site,$operation,$ids) {
44
+ if(!$this->appendTofile('{"feed":')) {
45
+ $this->log("Error writing feed tag");
46
+ return false;
47
+ }
48
+
49
+ if(!$this->writeCatalogContent($fromdate,$todate,$site,$operation,$ids)) {
50
+ $this->log("Error writing catalog tag");
51
+ return false;
52
+ }
53
+
54
+ if(!$this->appendTofile("}")) {
55
+ $this->log("Error writing closing feed tag");
56
+ return false;
57
+ }
58
+
59
+ return true;
60
+ }
61
+
62
+ private function writeCatalogContent($fromdate,$todate,$site,$operation,$ids) {
63
+ if(!$this->appendTofile('{"catalog":{')) {
64
+ $this->log("Error writing closing catalog tag");
65
+ return false;
66
+ }
67
+ if(!$this->writeSchemaContent()) {
68
+ return false;
69
+ }
70
+
71
+ if(!$this->appendTofile(",")) {
72
+ $this->log("Error while adding comma in catalog");
73
+ return false;
74
+ }
75
+
76
+ if(!$this->writeProductsContent($fromdate,$todate,$site,$operation,$ids)) {
77
+ return false;
78
+ }
79
+
80
+
81
+ if(!$this->appendTofile("}")) {
82
+ $this->log("Error writing closing catalog tag");
83
+ return false;
84
+ }
85
+
86
+ if(!$this->writeTaxonomyContents($site)) {
87
+ return false;
88
+ }
89
+
90
+ if(!$this->appendTofile("}")) {
91
+ $this->log("Error writing closing feed tag");
92
+ return false;
93
+ }
94
+
95
+
96
+ return true;
97
+ }
98
+
99
+ private function writeSchemaContent() {
100
+ return $this->appendTofile('"schema":'.Mage::getSingleton('unbxd_datafeeder/feed_jsonbuilder_schemabuilder')->getSchema($this->fields));
101
+ }
102
+
103
+ private function writeProductsContent($fromdate,$todate,$site,$operation,$ids) {
104
+
105
+ $collection=$this->getCatalogCollection($fromdate,$todate,$site,$operation,$ids);
106
+ // get total size
107
+ //set the time limit to infinite
108
+ ignore_user_abort(true);
109
+ set_time_limit(0);
110
+ $pageNum = 0;
111
+ $this->log('started writing products');
112
+
113
+ if(!$this->appendTofile('"'. $operation . '":{ "items":[')) {
114
+ $this->log("Error while adding items tag");
115
+ return false;
116
+ }
117
+
118
+ $firstLoop = true;
119
+
120
+ while(true){
121
+ $collection->clear();
122
+ $collection->getSelect()->limit(self::PAGE_SIZE, ($pageNum++) * self::PAGE_SIZE);
123
+ $collection->load();
124
+ if(count($collection) == 0){
125
+ if($pageNum == 1){
126
+ $this->log("No products found");
127
+ return false;
128
+ }
129
+ break;
130
+ }
131
+
132
+ if(!$firstLoop) {
133
+ if(!$this->appendTofile( ',')) {
134
+ $this->log("Error while addings items separator");
135
+ return false;
136
+ }
137
+ }
138
+ $content=Mage::getSingleton('unbxd_datafeeder/feed_jsonbuilder_productbuilder')->getProducts($collection, $this->fields);
139
+ $status=$this->appendTofile($content);
140
+ if(!$status){
141
+ $this->log("Error while addings items");
142
+ return false;
143
+ }
144
+ $this->log('Added '.($pageNum) * self::PAGE_SIZE.' products');
145
+ $firstLoop = false;
146
+ }
147
+
148
+ if(!$this->appendTofile("]}")) {
149
+ $this->log("Error writing closing items tag");
150
+ return false;
151
+ }
152
+
153
+
154
+ $this->log('Added all products');
155
+ return true;
156
+ }
157
+
158
+ private function writeTaxonomyContents($site){
159
+
160
+ $collection=$this->getTaxonomyMappingCollection();
161
+ // get total size
162
+ //set the time limit to infinite
163
+ ignore_user_abort(true);
164
+ set_time_limit(0);
165
+ $pageNum = 0;
166
+ $this->log('started writing taxonomy tree');
167
+
168
+ if(!$this->appendTofile(',"'. 'taxonomy' . '":{ "tree":[')) {
169
+ $this->log("Error while adding tree tag");
170
+ return false;
171
+ }
172
+
173
+ $content=Mage::getSingleton('unbxd_datafeeder/feed_jsonbuilder_taxonomybuilder')->createTaxonomyFeed($site);
174
+ $status=$this->appendTofile($content);
175
+
176
+ if(!$status){
177
+ $this->log("Error while addings taxonomy");
178
+ return false;
179
+ }
180
+
181
+ if(!$this->appendTofile("]")) {
182
+ $this->log("Error writing closing tree tag");
183
+ return false;
184
+ }
185
+
186
+ if(!$this->appendTofile(',"mapping":[')) {
187
+ $this->log("Error writing opening mapping tag");
188
+ return false;
189
+ }
190
+
191
+ $content=Mage::getSingleton('unbxd_datafeeder/feed_jsonbuilder_taxonomybuilder')->createMappingFeed($collection);
192
+ $status=$this->appendTofile($content);
193
+
194
+ if(!$status){
195
+ $this->log("Error while addings taxonomy");
196
+ return false;
197
+ }
198
+
199
+ if(!$this->appendTofile(']}')) {
200
+ $this->log("Error writing closing mapping tag");
201
+ return false;
202
+ }
203
+
204
+
205
+
206
+
207
+
208
+
209
+ $this->log('Added all categories');
210
+ return true;
211
+ }
212
+
213
+
214
+
215
+
216
+ private function setFields($site) {
217
+ $this->fields = Mage::getResourceSingleton('datafeeder/field')->getFieldMapping($site, true);
218
+ $this->log("fields are set" );
219
+ $this->fields["type_id"] = array(self::STATUS => 1,
220
+ self::DATA_TYPE => "longText",
221
+ self::AUTOSUGGEST => 0 );
222
+ $this->fields["entity_id"] = array(self::STATUS => 1,
223
+ self::DATA_TYPE => "text",
224
+ self::AUTOSUGGEST => 0 );
225
+ $this->fields["categoryIds"] = array(self::STATUS => 1,
226
+ self::DATA_TYPE => "text",
227
+ self::AUTOSUGGEST => 0 );
228
+ $this->fields["qty"] = array(self::STATUS => 1,
229
+ self::DATA_TYPE => "number",
230
+ self::AUTOSUGGEST => 0 );
231
+
232
+ $this->fields = array_merge($this->fields, Mage::getResourceSingleton("datafeeder/field")->getFeaturedFields());
233
+ }
234
+
235
+ /**
236
+ * method to get the catalog collection
237
+ *
238
+ */
239
+ public function getCatalogCollection($fromdate,$todate,$site,$operation,$ids) {
240
+ try{
241
+ if ($operation == "add") {
242
+ // select all the attributes
243
+ $website =Mage::getModel("core/website")->setName($site);
244
+ $visiblityCondition = array('in' => array(4));
245
+
246
+ $collection = Mage::getResourceModel('catalog/product_collection')
247
+ ->addWebsiteFilter($this->validateSite($site))
248
+ ->addAttributeToFilter('status',1)
249
+ ->joinField("qty", "cataloginventory_stock_item", 'qty', 'product_id=entity_id', null, 'left')
250
+ ->addAttributeToSelect('*')
251
+ ->addAttributeToFilter('visibility',$visiblityCondition);
252
+
253
+ if(sizeof($ids) > 0){
254
+ $condition = array('in' => $ids);
255
+ $collection=$collection->addAttributeToFilter('entity_id',$condition);
256
+ }
257
+ } else {
258
+ $collection = Mage::getResourceModel('catalog/product_collection');
259
+ if(sizeof($ids) > 0) {
260
+ $condition = array('in' => $ids);
261
+ $collection= $collection->addAttributeToFilter('entity_id',$condition)->addAttributeToSelect('entity_id');
262
+ }
263
+ }
264
+
265
+ $this->log($collection->getSelect());
266
+ return $collection;
267
+ } catch(Exception $e) {
268
+ $this->log($e->getMessage());
269
+ }
270
+ }
271
+
272
+ /**
273
+ * Function to initialize to feed creation process
274
+ */
275
+ private function createFile(){
276
+ return Mage::getSingleton('unbxd_datafeeder/feed_filemanager')->createFile($this->fileName);
277
+ }
278
+
279
+ private function appendTofile($data){
280
+ return Mage::getSingleton('unbxd_datafeeder/feed_filemanager')->appendTofile($this->fileName, $data);
281
+ }
282
+
283
+ public function log($message) {
284
+ Mage::getSingleton('unbxd_datafeeder/feed_filemanager')->log($message);
285
+ }
286
+
287
+ /**
288
+ * method to validate whether the site exists or not
289
+ **/
290
+ public function validateSite($site){
291
+ $sites=Mage::app()->getWebsites();
292
+ if( !isset($site) || $site == "") {
293
+ return false;
294
+ }
295
+ foreach( $sites as $eachSite){
296
+ if(strcasecmp ( $eachSite->getName(), $site ) == 0 ){
297
+ return $eachSite->getWebsiteId();
298
+ }
299
+ }
300
+ return -1;
301
+ }
302
+
303
+ public function getTaxonomyMappingCollection() {
304
+ try{
305
+ $adapter = Mage::getSingleton('core/resource')->getConnection('core_read');
306
+ $_productCategoryTable = method_exists($_reader, 'getTableName')?$adapter->getTable('catalog_category_product'):'catalog_category_product';
307
+ $_productTable = method_exists($_reader, 'getTableName')?$this->getTable('catalog_product_entity'):'catalog_category_product';
308
+
309
+ return $adapter->query("select catalog_category_product_index.product_id as entity_id,GROUP_CONCAT(catalog_category_product_index.category_id SEPARATOR ',') as category_id FROM catalog_category_product_index
310
+ join catalog_product_entity where catalog_category_product_index.product_id = catalog_product_entity.entity_id
311
+ group by catalog_category_product_index.product_id");
312
+ }
313
+ catch(Exception $e) {
314
+ $this->log($e->getMessage());
315
+ }
316
+
317
+
318
+ }
319
+
320
+ }
321
+ ?>
app/code/local/Unbxd/Datafeeder/Model/Feed/Feedmanager.php ADDED
@@ -0,0 +1,159 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Unbxd_Datafeeder_Model_Feed_Feedmanager {
4
+
5
+
6
+ /**
7
+ * method to push the feed to the Unbxd server
8
+ **/
9
+ public function pushFeed($site){
10
+ $fields=array('file'=>'@'.$this->fileName.';filename=unbxdFeedRenamed.json');
11
+ $header = array('Content-Type: multipart/form-data');
12
+
13
+ $url="http://feed.unbxdapi.com/upload/v2/".$this->key."/".$this->siteName."?fullimport=true";
14
+
15
+ $ch = curl_init();
16
+ curl_setopt($ch, CURLOPT_URL,$url);
17
+ curl_setopt($ch, CURLOPT_POST,true);
18
+ curl_setopt($ch, CURLOPT_POSTFIELDS,$fields);
19
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
20
+ try{
21
+ $this->log('pushing the feed to '.$url);
22
+ // push the feed to the server
23
+ $response = $this->exec($ch);
24
+ }catch(Exception $Ex){
25
+ $this->log($Ex->getMessage());
26
+ return false;
27
+ }
28
+ $this->log(json_encode($response));
29
+ curl_close($ch);
30
+ return true;
31
+ }
32
+
33
+ public function exec($ch)
34
+ {
35
+ $response = curl_exec($ch);
36
+ $error = curl_error($ch);
37
+ $result = array( 'header' => '',
38
+ 'body' => '',
39
+ 'curl_error' => '',
40
+ 'http_code' => '',
41
+ 'last_url' => '');
42
+ if ( $error != "" )
43
+ {
44
+ $result['curl_error'] = $error;
45
+ return $result;
46
+ }
47
+
48
+ $header_size = curl_getinfo($ch,CURLINFO_HEADER_SIZE);
49
+ $result['header'] = substr($response, 0, $header_size);
50
+ $result['body'] = substr( $response, $header_size );
51
+ $result['http_code'] = curl_getinfo($ch,CURLINFO_HTTP_CODE);
52
+ $result['last_url'] = curl_getinfo($ch,CURLINFO_EFFECTIVE_URL);
53
+ return $result;
54
+ }
55
+
56
+ /**
57
+ * method to set the feedName, log, apikey based on site Name
58
+ **/
59
+ public function init($site)
60
+ {
61
+ $this->fileName = Mage::getBaseDir('tmp').DS.str_replace(' ', '_',$site). "_Feed.json";
62
+ $this->key = Mage::getResourceSingleton("datafeeder/conf")->getValue("apiKey");
63
+ $this->siteName = Mage::getResourceSingleton("datafeeder/conf")->getValue($site."/siteName");
64
+ if(!isset($this->key) || $this->key == "" || $this->key == "empty"){
65
+ $this->log("api key not set");
66
+ return false;
67
+ }
68
+ if(!isset($this->siteName) || $this->siteName == "" || $this->siteName == "empty"){
69
+ $this->log("site Name not set");
70
+ return false;
71
+ }
72
+ return true;
73
+ }
74
+
75
+ /**
76
+ * method to validate whether the site exists or not
77
+ **/
78
+ public function validateSite($site){
79
+ $sites=Mage::app()->getWebsites();
80
+ if( !isset($site) || $site == "") {
81
+ return false;
82
+ }
83
+ foreach( $sites as $eachSite){
84
+ if(strcasecmp ( $eachSite->getName(), $site ) == 0 ){
85
+ return $eachSite->getWebsiteId();
86
+ }
87
+ }
88
+ return -1;
89
+ }
90
+
91
+ /**
92
+ * method to initiate feed uploading to the unbxd servers
93
+ **/
94
+ public function process($fromdate,$site,$operation = "add", $ids=array()){
95
+
96
+ $this->log('unbxd Datafeeder initiated');
97
+ // validatest the site
98
+ if($this->validateSite($site) == -1){
99
+ $this->log("Invalid site Name".$site);
100
+ return;
101
+ }
102
+ // set the basic
103
+ if(! $this->init($site)){
104
+ return;
105
+ }
106
+ $todate =date('Y-m-d H:i:s');
107
+
108
+ // check the lock, that if already indexing is happening
109
+ if($this->checkSiteLock($site)){
110
+ $this->log('site '. $site.' has been locked');
111
+ $action=$site.'/status';
112
+ // lock the feed
113
+ Mage::getResourceSingleton("datafeeder/conf")->updateAction($action,'1');
114
+ // create the feed
115
+
116
+ $status=Mage::getSingleton('unbxd_datafeeder/feed_feedcreator')
117
+ ->createFeed($this->fileName, $fromdate,$todate,$site,$operation,$ids);
118
+ $this->log('unbxd Datafeeder finished creating file');
119
+
120
+ if($status){
121
+ try{
122
+ // if successful push it to unbxd servers
123
+ $status=$this->pushFeed($site);
124
+ }catch(Exception $e){
125
+ $this->log($e->getMessage());
126
+
127
+ }
128
+ if($status){
129
+ Mage::getResourceSingleton("datafeeder/conf")->updateAction('Lastindex',$todate);
130
+ }
131
+ }
132
+ // unlock the feed once everything is completed
133
+ Mage::getResourceSingleton("datafeeder/conf")->updateAction($action,'0');
134
+ $this->log('site '. $site.' has been unlocked');
135
+ } else {
136
+ $this->log('Feed Uploading failed because site has been locked');
137
+ }
138
+ }
139
+
140
+ /**
141
+ * method to check the status of the uploading
142
+ **/
143
+ public function checkSiteLock($site)
144
+ {
145
+ $value = Mage::getResourceSingleton("datafeeder/conf")->getValue($site."/status");
146
+ if($value == '0' || $value == 'empty'){
147
+ $this->log("true");
148
+ return true;
149
+ }else{
150
+ $this->log("false". $value);
151
+ return false;
152
+ }
153
+ }
154
+
155
+ public function log($message) {
156
+ Mage::getSingleton('unbxd_datafeeder/feed_filemanager')->log($message);
157
+ }
158
+ }
159
+ ?>
app/code/local/Unbxd/Datafeeder/Model/Feed/Filemanager.php ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Unbxd_Datafeeder_Model_Feed_Filemanager {
4
+
5
+
6
+ var $logFileName;
7
+
8
+ public function __construct(){
9
+ $this->logFileName = Mage::getBaseDir('log').DS.'generic.log';
10
+ }
11
+
12
+ public function setLog($logFileName) {
13
+ $this->logFileName = Mage::getBaseDir('log').DS.$logFileName;
14
+ }
15
+
16
+ /**
17
+ * Function to create a file
18
+ */
19
+ public function createFile($file){
20
+ try{
21
+ $f=fopen($file,'w');
22
+
23
+ fclose($f);
24
+ if(!file_exists($file)) {
25
+ $this->log("UNBXD_MODULE:Couldn't create the file");
26
+ return false;
27
+ }
28
+ $this->log("UNBXD_MODULE: created the file");
29
+ return true;
30
+ } catch (Exception $ex) {
31
+ $this->log("UNBXD_MODULE:Error while creating the file");
32
+ $this->log($ex->getMessage());
33
+ return false;
34
+ }
35
+ }
36
+
37
+ /**
38
+ * Function to append the contents to the file
39
+ */
40
+ public function appendTofile($fileName, $content){
41
+ try {
42
+ if(file_put_contents($fileName, $content, FILE_APPEND)) {
43
+ return true;
44
+ } else {
45
+ return false;
46
+ }
47
+ } catch(Exception $ex) {
48
+ $this->log("UNBXD_MODULE:Error while appending the contents to feed file");
49
+ $this->log($ex->getMessage());
50
+ return false;
51
+ }
52
+ }
53
+
54
+ /**
55
+ * Function to appened the contents to the file
56
+ */
57
+ public function log($content){
58
+ try{
59
+ $resp = file_put_contents($this->logFileName, date('Y-m-d H:i:s').$content."\n", FILE_APPEND);
60
+ if($resp){
61
+ return true;
62
+ } else {
63
+ error_log("UNBXD_MODULE:Error while appending the contents to log file");
64
+ return false;
65
+ }
66
+ return true;
67
+ }catch(Exception $ex) {
68
+ error_log("UNBXD_MODULE:Error while appending the contents to log file");
69
+ Mage::throwException($ex->getMessage());
70
+ return false;
71
+ }
72
+ }
73
+ }
74
+ ?>
app/code/local/Unbxd/Datafeeder/Model/Feed/Jsonbuilder/Jsonbuilder.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Unbxd_Datafeeder_Model_Feed_Jsonbuilder_Jsonbuilder {
4
+
5
+
6
+
7
+ }
8
+
9
+ ?>
app/code/local/Unbxd/Datafeeder/Model/Feed/Jsonbuilder/Productbuilder.php ADDED
@@ -0,0 +1,316 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Unbxd_Datafeeder_Model_Feed_Jsonbuilder_Productbuilder extends Unbxd_Datafeeder_Model_Feed_Jsonbuilder_Jsonbuilder {
4
+
5
+ const DATA_TYPE = "data_type";
6
+ const MULTIVALUED = "multiValued";
7
+ const NUMBER = "number";
8
+ const DECIMAL = "decimal";
9
+ const DATE = "date";
10
+ const IMAGE_HEIGHT = "image_height";
11
+ const IMAGE_WIDTH = "image_width";
12
+ const GENERATE_IMAGE = "generate_image";
13
+
14
+ /*
15
+ * method to get the products in json
16
+ */
17
+ public function getProducts($collection, $fields) {
18
+ $content='';
19
+ $firstLoop = true;
20
+ foreach($collection as $product) {
21
+ if(!$firstLoop) {
22
+ $content = $content . ",";
23
+ }
24
+
25
+ $productArray = $this->getProduct($product, $fields);
26
+ $productArray = $this->postProcessProduct($productArray, $fields, false);
27
+ $content=$content.json_encode($productArray);
28
+
29
+ $firstLoop = false;
30
+ }
31
+
32
+ return rtrim($content, ",");
33
+ }
34
+
35
+
36
+ /*
37
+ * method to get the product in json
38
+ */
39
+ public function getProduct($product, $fields, $childProduct = false) {
40
+
41
+ $productArray =array();
42
+
43
+ foreach($product->getData('') as $columnHeader=>$columndata){
44
+
45
+ $unbxdFieldName = $this->getUnbxdFieldName($columnHeader, $childProduct);
46
+ if(isset($unbxdFieldName) && $unbxdFieldName != "" && !array_key_exists($unbxdFieldName, $fields)) {
47
+ continue;
48
+ }
49
+
50
+ if($columnHeader=="entity_id"){
51
+ $productArray['uniqueId'] = $columndata;
52
+ }
53
+
54
+ if($columnHeader=="url_path"){
55
+ // handling the url
56
+ $productArray[$unbxdFieldName] = Mage::getUrl('').$columndata;
57
+ } else if (Mage::helper('unbxd_datafeeder/UnbxdIndexingHelper')->isImage($columnHeader)) {
58
+ // handling tthe images
59
+ $attributeValue = $this->getImage($columnHeader, $unbxdFieldName, $product, $fields);
60
+ if(!is_null($attributeValue)) {
61
+ $productArray[$unbxdFieldName] = $attributeValue;
62
+ }
63
+
64
+ } else if( Mage::helper('unbxd_datafeeder/UnbxdIndexingHelper')->isMultiSelect($columnHeader)){
65
+ // handling the array/ multiselect attribute
66
+ $attributeValue = $this->getMultiSelectAttribute($columnHeader, $product);
67
+ if(!is_null($attributeValue)) {
68
+ $productArray[$unbxdFieldName] = $attributeValue;
69
+ }
70
+ } else if (!is_null($columndata) && $columndata != ""){
71
+ //adding the normal attribute
72
+ $productArray[$unbxdFieldName] = $columndata;
73
+ }
74
+ }
75
+ if(!$childProduct) {
76
+ // adding the childProduct
77
+ $productArray = $this->addChildrens($product, $fields, $productArray);
78
+
79
+ $category = $this->getCategoryAttribute($product);
80
+ // adding the category
81
+ $productArray = $category + $productArray;
82
+ }
83
+ return $productArray;
84
+ }
85
+
86
+ /**
87
+ * method to get category content in xml given the product object
88
+ */
89
+ private function getCategoryAttribute($product){
90
+ $cats = $product->getCategoryIds();
91
+ $categoryIds = array();
92
+ $category = array();
93
+ $categoryData = array();
94
+ $index = 0;
95
+ foreach ($cats as $categoryId) {
96
+ $_cat = Mage::helper('unbxd_datafeeder/UnbxdIndexingHelper')->getCategory($categoryId);
97
+ if($_cat == null) {
98
+ continue;
99
+ }
100
+ $categoryName = $_cat->getName();
101
+ if($categoryName == null || $categoryName == "") {
102
+ continue;
103
+ }
104
+ if($index++ < 4) {
105
+ $categoryData['catlevel' . $index . 'Name'] = $categoryName;
106
+ }
107
+ $categoryIds[] = (string)$categoryId;
108
+ $category[] = $categoryName;
109
+ }
110
+ $categoryData['categoryIds'] = $categoryIds;
111
+ $categoryData['category'] = $category;
112
+ return $categoryData;
113
+ }
114
+
115
+ /*
116
+ * method to returns as an array of values given the fieldName and the product
117
+ */
118
+ private function getMultiSelectAttribute($fieldName, $product) {
119
+ $data = explode(",", $product->getData($fieldName));
120
+ $valueAsAnArray = array();
121
+ foreach($data as $eachdata){
122
+ $attributeValue = Mage::getResourceSingleton("datafeeder/attribute")
123
+ ->getAttributeValue($fieldName, trim($eachdata), $product);
124
+ if(!is_null($attributeValue) && $attributeValue != "" && attributeValue != "Use Config") {
125
+ $valueAsAnArray[] = $attributeValue;
126
+ }
127
+ }
128
+ if(sizeof($valueAsAnArray) > 0) {
129
+ return $valueAsAnArray;
130
+ }
131
+ return null;
132
+ }
133
+
134
+ /*
135
+ * generates the image
136
+ */
137
+ private function getImage($fieldName, $unbxdFieldName, $product, $fields) {
138
+
139
+ if($fields[$unbxdFieldName][self::GENERATE_IMAGE] == "1") {
140
+ Mage::getDesign()->setArea('frontend');
141
+ try {
142
+ return (string)Mage::helper('catalog/image')->init($product, $fieldName)
143
+ ->resize($fields[$unbxdFieldName][self::IMAGE_WIDTH],
144
+ $fields[$unbxdFieldName][self::IMAGE_HEIGHT]);
145
+ } catch (Exception $e) {
146
+ error_log("Error while fetching the image" . $e->getMessage());
147
+ }
148
+ }
149
+ return $product->getData($fieldName);
150
+ }
151
+
152
+ /*
153
+ * get unbxd specfic field name for the magento field name
154
+ */
155
+ private function getUnbxdFieldName($columnHeader, $isChild) {
156
+ if($isChild) {
157
+ $unbxdFieldName = $columnHeader . "Associated";
158
+ } else {
159
+ $unbxdFieldName = $columnHeader;
160
+ }
161
+ return $this->renameConflictedFeatureFields($unbxdFieldName);
162
+ }
163
+
164
+ /*
165
+ * Renaming the conflicted unbxd feature fields eg: gender to _gender
166
+ */
167
+ private function renameConflictedFeatureFields($unbxdFieldName) {
168
+ if (in_array($unbxdFieldName, Mage::getResourceSingleton('datafeeder/field')->getConflictedFeatureFieldLust())) {
169
+ return "_" . $unbxdFieldName;
170
+ }
171
+ return $unbxdFieldName;
172
+ }
173
+
174
+ /**
175
+ * gives the children in form of array
176
+ */
177
+ public function addChildrens($product, $fields, $productArray) {
178
+ $type = $product->getData('type_id');
179
+ if ($type == "configurable" || $type == "grouped" ) {
180
+ $associatedProducts = array();
181
+ if ($product->getTypeId() == 'grouped') {
182
+ $childrens = $product->getTypeInstance(true)->getAssociatedProducts($product);
183
+ } else{
184
+ $conf = Mage::getModel('catalog/product_type_configurable')->setProduct($product);
185
+ $childrens = $conf->getUsedProductCollection()
186
+ ->addAttributeToSelect('*')
187
+ ->addFilterByRequiredOptions();
188
+ }
189
+ $conf = Mage::getModel('catalog/product_type_configurable')->setProduct($product);
190
+ $childrens = $conf->getUsedProductCollection()
191
+ ->addAttributeToSelect('*')
192
+ ->addFilterByRequiredOptions();
193
+ foreach ($childrens as $children)
194
+ {
195
+ $childProduct = $this->getProduct($children, $fields, true);
196
+ if(isset($childProduct) && sizeof($childProduct) > 0 ) {
197
+ $childProduct = $this->postProcessProduct($childProduct, $fields, true);
198
+ $associatedProducts[] = $childProduct;
199
+ }
200
+ }
201
+ if( sizeof($associatedProducts) > 0) {
202
+ $productArray["associatedProducts"] = $associatedProducts;
203
+ }
204
+ return $productArray;
205
+ } else {
206
+ return $productArray;
207
+ }
208
+ }
209
+
210
+ /**
211
+ * process the prodcut
212
+ */
213
+ public function postProcessProduct($product, $fields, $isChild=false) {
214
+ if($isChild) {
215
+ $product = $this->convertMultivalued($product);
216
+ } else {
217
+ $product = $this->convertMultivalued($product, $fields);
218
+ }
219
+ $product = $this->convertDataType($product, $fields, $isChild);
220
+ return $product;
221
+ }
222
+
223
+ /*
224
+ * convert the data type according to the dashboard setup
225
+ */
226
+ public function convertDataType($product, $fields) {
227
+ foreach($product as $fieldName => $value) {
228
+ if($fieldName != "associatedProducts") {
229
+ $product[$fieldName] = $this->convertDataTypeByValue($fields[$fieldName], $value);
230
+ }
231
+ }
232
+ return $product;
233
+ }
234
+
235
+ /*
236
+ * method to get the float values
237
+ */
238
+ private function getFloatValues($value) {
239
+ if(is_array($value)) {
240
+ $valueAsAnArray = array();
241
+ foreach ($value as $eachValue) {
242
+ $valueAsAnArray[] = floatval($eachValue);
243
+ }
244
+ return $valueAsAnArray;
245
+ } else {
246
+ return floatval($value);
247
+ }
248
+ }
249
+
250
+
251
+ /*
252
+ * returns the array as number
253
+ */
254
+ private function getNumberValues($value) {
255
+ if(is_array($value)) {
256
+ $valueAsAnArray = array();
257
+ foreach ($value as $eachValue) {
258
+ $valueAsAnArray[] = intval($eachValue);
259
+ }
260
+ return $valueAsAnArray;
261
+ } else {
262
+ return intval($value);
263
+ }
264
+ }
265
+
266
+ /*
267
+ * returns the date value
268
+ */
269
+ private function getDateValues($value) {
270
+ if(is_array($value)) {
271
+ $tempValue = array();
272
+ foreach ($value as $eachValue) {
273
+ $tokens = explode(" ",$eachValue);
274
+ $tempValue[] = $tokens[0].'T'.$tokens[1].'Z';
275
+ }
276
+ return $tempValue;
277
+ }
278
+ $tokens = explode(" ",$value);
279
+ $value = $tokens[0].'T'.$tokens[1].'Z';
280
+ return $value;
281
+ }
282
+
283
+ /*
284
+ * returns the data type value
285
+ */
286
+ private function convertDataTypeByValue($data_type, $value) {
287
+ if($data_type[self::DATA_TYPE] == self::DECIMAL) {
288
+ return $this->getFloatValues($value);
289
+ } else if ($data_type[self::DATA_TYPE] == self::NUMBER) {
290
+ return $this->getNumberValues($value);
291
+ } else if ($data_type[self::DATA_TYPE] == self::DATE) {
292
+ return $this->getDateValues($value);
293
+ }
294
+ return $value;
295
+ }
296
+
297
+ /*
298
+ * returns the product by changing it to multivalued after checking its data type
299
+ */
300
+ public function convertMultivalued($product, $fields = null) {
301
+ foreach($product as $field=>$value) {
302
+ if(is_null($fields) ||
303
+ (($field != "associatedProducts") &&
304
+ (array_key_exists(self::MULTIVALUED,$fields[$field]) &&
305
+ $fields[$field][self::MULTIVALUED]) &&
306
+ !is_array($value))) {
307
+ $valueAsAnArray = array();
308
+ $valueAsAnArray[] = $value;
309
+ $product[$field] = $valueAsAnArray;
310
+ }
311
+ }
312
+ return $product;
313
+ }
314
+ }
315
+
316
+ ?>
app/code/local/Unbxd/Datafeeder/Model/Feed/Jsonbuilder/Schemabuilder.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Unbxd_Datafeeder_Model_Feed_Jsonbuilder_Schemabuilder extends Unbxd_Datafeeder_Model_Feed_Jsonbuilder_Jsonbuilder {
4
+
5
+
6
+ const SCHEMA = 'schema';
7
+ const FIELD_NAME = "fieldName";
8
+ const DATA_TYPE = "dataType";
9
+ const MULTIVALUED = "multiValued";
10
+ const AUTOSUGGEST = "autoSuggest";
11
+ const TRUE = "true";
12
+ const FALSE = "false";
13
+
14
+ const FIELD_STATUS = 'status';
15
+ const FIELD_DATA_TYPE = 'data_type';
16
+ const FIELD_AUTOSUGGEST = 'autosuggest';
17
+
18
+ public function getSchema($fields) {
19
+ $jsonString = "";
20
+ $fieldList = array();
21
+ $featuredFields = Mage::getResourceSingleton("datafeeder/field")->getFeaturedFields();
22
+ $conflictedFeatureFields = Mage::getResourceSingleton("datafeeder/field")->getConflictedFeatureFieldLust();
23
+ foreach($fields as $fieldName=>$values ) {
24
+ if((array_key_exists(self::FIELD_STATUS, $values) && $values[self::FIELD_STATUS] == 1)
25
+ || !array_key_exists($fieldName, $featuredFields)) {
26
+ $origFieldName = $fieldName;
27
+ if($fieldName[0] == "_") {
28
+ $origFieldName = (in_array(substr($fieldName, 1, strlen($fieldName)), $conflictedFeatureFields))
29
+ ? substr($fieldName, 1, strlen($fieldName))
30
+ : $fieldName;
31
+ }
32
+ $fieldList[] = array(self::FIELD_NAME => $fieldName,
33
+ self::DATA_TYPE => $values[self::FIELD_DATA_TYPE],
34
+ self::MULTIVALUED => ($this->endsWith($fieldName, "Associated")?self::TRUE:(Mage::helper('unbxd_datafeeder/UnbxdIndexingHelper')
35
+ ->isMultiSelect($origFieldName)?
36
+ self::TRUE:self::FALSE)),
37
+ self::AUTOSUGGEST => ($values[self::FIELD_AUTOSUGGEST] == 1?
38
+ self::TRUE: self::FALSE));
39
+ }
40
+ }
41
+ return json_encode($fieldList);
42
+ }
43
+
44
+
45
+ function endsWith($haystack, $needle)
46
+ {
47
+ return $needle === "" || substr($haystack, -strlen($needle)) === $needle;
48
+ }
49
+ }
50
+
51
+ ?>
app/code/local/Unbxd/Datafeeder/Model/Feed/Jsonbuilder/Taxonomybuilder.php ADDED
@@ -0,0 +1,209 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Unbxd_Datafeeder_Model_Feed_Jsonbuilder_Taxonomybuilder extends Unbxd_Datafeeder_Model_Feed_Jsonbuilder_Jsonbuilder {
4
+
5
+ var $file='unbxdTaxonomy.xml';
6
+
7
+ public function __construct(){
8
+ //$this->file = Mage::getBaseDir('tmp').DS.'unbxdTaxonomy.xml';
9
+ }
10
+
11
+ /**
12
+ * Function to appened the contents to the file
13
+ */
14
+ private function appendTofile($content){
15
+
16
+ try{
17
+
18
+ file_put_contents($this->file, $content, FILE_APPEND);
19
+ return true;
20
+ }catch(Exception $Ex){
21
+ error_log("UNBXD_MODULE:Error while appending the contents to file");
22
+ error_log($Ex->getMessage());
23
+ return false;
24
+ }
25
+ }
26
+
27
+ private function log($content){
28
+ try{
29
+ file_put_contents($this->logFile, date('Y-m-d H:i:s').$content."\n", FILE_APPEND);
30
+ return true;
31
+ }catch(Exception $Ex){
32
+ error_log("UNBXD_MODULE:Error while appending the contents to file");
33
+ Mage::throwException($Ex->getMessage());
34
+ return false;
35
+ }
36
+ }
37
+
38
+ /**
39
+ * Function to delete the file
40
+ */
41
+ private function deleteFile(){
42
+ unlink($this->file);
43
+ }
44
+
45
+
46
+ private function writeJSONProductsContents($site){
47
+ $stores= $this->getStores($site);
48
+ foreach( $stores as $store){
49
+ $categories=$this->getStoreCategories($store);
50
+ $content='';
51
+ $count=0;
52
+ foreach($categories as $category){
53
+ if( $category->getName()== "" ){
54
+ continue;
55
+ }
56
+ $content =$content.$this->getCategoryContent($category);
57
+ $category_obj = Mage::getModel('catalog/category')->load($category->getId());
58
+ $childrens = $category_obj->getAllChildren(true);
59
+ $childrenCategories = Mage::getModel('catalog/category')->getCollection()->addIdFilter($childrens)->addAttributeToSelect('*')->load();
60
+
61
+ foreach($childrenCategories as $childCategory){
62
+ $content=$content.$this->getCategoryContent($childCategory);
63
+ }
64
+ }
65
+ }
66
+ return $content;
67
+ }
68
+
69
+ private function getCategoryContent($category){
70
+ $content=array();
71
+ $content["nodeName"]= $category->getName();
72
+ $content["parentNodeId"] = array((string)$category->getParentId());
73
+ $content["nodeId"] =(string)$category->getId();
74
+ return json_encode($content).',';
75
+ }
76
+
77
+
78
+
79
+ private function getAllCategories($site){
80
+ $collection = Mage::getModel('catalog/category')->getCollection()
81
+ ->setStoreId($this->getStores($site))
82
+ ->addAttributeToSelect('name')
83
+ ->addAttributeToSelect('id');
84
+
85
+ return $collection->load();
86
+
87
+ }
88
+
89
+ private function getStores($site){
90
+ $sites=Mage::app()->getWebsites();
91
+ foreach( $sites as $eachSite){
92
+ if(strcasecmp ( $eachSite->getName(), $site ) == 0 ){
93
+ return $eachSite->getStores();
94
+ }
95
+ }
96
+ }
97
+
98
+
99
+
100
+ private function getAttributesInJSON($columnHeader,$columndata){
101
+
102
+ return '"'.$columnHeader.'"'.':'.'"'.$content.'"';
103
+ }
104
+
105
+ private function _escapeXMLHeader($columnHeader){
106
+
107
+ return str_replace(' ','_',$columnHeader);
108
+ }
109
+
110
+
111
+
112
+ public function createTaxonomyFeed($site){
113
+
114
+ $content=$this->writeJSONProductsContents($site);
115
+
116
+ if(!$content){
117
+ return false;
118
+ }
119
+ $this->log('writing content');
120
+
121
+ return rtrim($content, ",");;
122
+ }
123
+
124
+ public function createMappingFeed($collection){
125
+
126
+ $content=$this->writeJSONMappingContents($collection);
127
+
128
+ if(!$content){
129
+
130
+ return false;
131
+ }
132
+
133
+ $this->log('writing content');
134
+
135
+ return rtrim($content, ",");
136
+
137
+ }
138
+
139
+ private function writeJSONMappingContents($collection)
140
+ {
141
+ $content='';
142
+ foreach($collection as $mapping) {
143
+
144
+ $content =$content.$this->getMappingContent( $mapping);
145
+ }
146
+ return $content;
147
+
148
+ }
149
+
150
+
151
+
152
+ private function getMappingContent($mapping){
153
+
154
+ $content=array();
155
+ $content["uniqueId"]= (string)$mapping['entity_id'];
156
+ $content["unbxdNodeId"] = explode(",", $mapping['category_id']);
157
+ return json_encode($content).',';
158
+ }
159
+
160
+ public function validateSite($site){
161
+ $sites=Mage::app()->getWebsites();
162
+ if( !isset($site) || $site == "") {
163
+ return false;
164
+ }
165
+ foreach( $sites as $eachSite){
166
+ if(strcasecmp ( $eachSite->getName(), $site ) == 0 ){
167
+ return $eachSite->getWebsiteId();
168
+ }
169
+ }
170
+ return -1;
171
+ }
172
+
173
+ public function getStoreCategories($store, $sorted=false, $asCollection=false, $toLoad=true)
174
+ {
175
+ $parent = $store->getRootCategoryId();
176
+
177
+ /**
178
+ * Check if parent node of the store still exists
179
+ */
180
+ $category = Mage::getModel('catalog/category');
181
+ /* @var $category Mage_Catalog_Model_Category */
182
+ if (!$category->checkId($parent)) {
183
+ if ($asCollection) {
184
+ return new Varien_Data_Collection();
185
+ }
186
+ return array();
187
+ }
188
+
189
+ $recursionLevel = max(0, (int) Mage::app()->getStore()->getConfig('catalog/navigation/max_depth'));
190
+ $tree = Mage::getResourceModel('catalog/category_tree');
191
+ /* @var $tree Mage_Catalog_Model_Resource_Category_Tree */
192
+ $nodes = $tree->loadNode($parent)
193
+ ->loadChildren($recursionLevel)
194
+ ->getChildren();
195
+
196
+ $tree->addCollectionData(null, $sorted, $parent, $toLoad, false);
197
+ if ($asCollection) {
198
+ return $tree->getCollection();
199
+ }
200
+ return $nodes;
201
+ }
202
+
203
+
204
+
205
+ public function updateAction($action,$value){
206
+ Mage::getResourceSingleton("datafeeder/conf")->updateAction($action, $value);
207
+ }
208
+ }
209
+ ?>
app/code/local/Unbxd/Datafeeder/Model/Field.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Unbxd_Datafeeder_Model_Field extends Mage_Core_Model_Abstract {
4
+
5
+ protected function _construct()
6
+ {
7
+ $this->_init('datafeeder/field');
8
+ }
9
+ }
10
+
11
+ ?>
app/code/local/Unbxd/Datafeeder/Model/Mysql4/Attribute.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Unbxd_Datafeeder_Model_Mysql4_Attribute {
4
+
5
+ protected $attributeMap = array();
6
+ public function getAttributeValue($attributeCode, $value, $product){
7
+ if(!isset($this->attributeMap[$value])){
8
+ if(!($product instanceof Mage_Catalog_Model_Product)){
9
+ return null;
10
+ }
11
+ $options = Mage::getResourceModel('catalog/product')->getAttribute($attributeCode)
12
+ ->getSource()->getAllOptions();
13
+ foreach($options as $option){
14
+ $this->attributeMap[$option["value"]] = $option["label"];
15
+ }
16
+ }
17
+ return $this->attributeMap[$value];
18
+ }
19
+
20
+ }
21
+
22
+ ?>
app/code/local/Unbxd/Datafeeder/Model/Mysql4/Conf.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Unbxd_Datafeeder_Model_Mysql4_Conf extends Mage_Core_Model_Mysql4_Abstract
4
+ {
5
+ protected function _construct()
6
+ {
7
+ $this->_init('datafeeder/conf', 'uconfig_id');
8
+ }
9
+
10
+ public function getValue($action)
11
+ {
12
+ $collection=Mage::getModel('datafeeder/conf')->getCollection()
13
+ ->addFieldToFilter('action',$action);
14
+
15
+ $count=0;
16
+ foreach($collection as $coll){
17
+ $count++;
18
+ $value=$coll->getvalue();
19
+ }
20
+ if($count==0){
21
+ $collection=Mage::getModel('datafeeder/conf')
22
+ ->setAction($action)->setValue("empty")->save();
23
+ $value="empty";
24
+ }
25
+ return $value;
26
+ }
27
+
28
+ public function updateAction($action,$value)
29
+ {
30
+ if (!isset($value) || $value == "") {
31
+ return;
32
+ }
33
+ $collection=Mage::getModel('datafeeder/conf')->getCollection()
34
+ ->addFieldToFilter('action',$action);
35
+
36
+ $count=0;
37
+ foreach($collection as $coll){
38
+ $count++;
39
+ Mage::getModel('datafeeder/conf')->load($coll->getId())->setValue($value)->save();
40
+ }
41
+ if($count==0){
42
+ $collection=Mage::getModel('datafeeder/conf')
43
+ ->setAction($action)->setValue($value)->save();
44
+ }
45
+ }
46
+ }
47
+ ?>
app/code/local/Unbxd/Datafeeder/Model/Mysql4/Conf/Collection.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Unbxd_Datafeeder_Model_Mysql4_Conf_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
4
+ {
5
+
6
+ public function _construct()
7
+ {
8
+ $this->_init('datafeeder/conf');
9
+ }
10
+
11
+ }
12
+
13
+
14
+
15
+
16
+ ?>
app/code/local/Unbxd/Datafeeder/Model/Mysql4/Field.php ADDED
@@ -0,0 +1,192 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Unbxd_Datafeeder_Model_Mysql4_Field extends Mage_Core_Model_Mysql4_Abstract
4
+ {
5
+
6
+ const STATUS = 'status';
7
+ const DATA_TYPE = 'data_type';
8
+ const SITE = 'site';
9
+ const FIELD_NAME = "name";
10
+ const TABLE_NAME = 'unbxd_field';
11
+ const AUTOSUGGEST = 'autosuggest';
12
+ const MULTIVALUED = 'multiValued';
13
+ const IMAGE_HEIGHT = "image_height";
14
+ const IMAGE_WIDTH = "image_width";
15
+ const GENERATE_IMAGE = "generate_image";
16
+
17
+ protected function _construct()
18
+ {
19
+ $this->_init('datafeeder/field', 'field_id');
20
+ }
21
+
22
+ /*
23
+ * Method to get Unbxd Fields Configuration as Mapping give the site
24
+ */
25
+ public function getFieldMapping($site, $enabledFields = false) {
26
+ $results = Mage::getModel('datafeeder/field')->getCollection()->addFieldToFilter(self::SITE, $site);
27
+ $fieldMapping = array();
28
+ $_reader = Mage::getSingleton('core/resource')->getConnection('core_read');
29
+ if(method_exists($_reader, 'getTableName')) {
30
+ $table = $_reader->getTableName(self::TABLE_NAME);
31
+ } else {
32
+ $table = self::TABLE_NAME;
33
+ }
34
+ $select = $_reader->select();
35
+ $select->from($table);
36
+ $filterCond = self::SITE . " = '" . $site . "'";
37
+ if($enabledFields) {
38
+ $filterCond = $filterCond . " AND " . self::STATUS ."='1'";
39
+ }
40
+
41
+ $select->where($filterCond);
42
+ $results = $_reader->fetchAll($select);
43
+
44
+ foreach($results as $eachResult) {
45
+ $fieldMapping[$eachResult[self::FIELD_NAME]] = array(self::STATUS => $eachResult[self::STATUS],
46
+ self::DATA_TYPE => $eachResult[self::DATA_TYPE],
47
+ self::AUTOSUGGEST => $eachResult[self::AUTOSUGGEST],
48
+ self::IMAGE_HEIGHT =>$eachResult[self::IMAGE_HEIGHT],
49
+ self::IMAGE_WIDTH => $eachResult[self::IMAGE_WIDTH],
50
+ self::GENERATE_IMAGE =>$eachResult[self::GENERATE_IMAGE]
51
+ );
52
+ }
53
+ return $fieldMapping;
54
+ }
55
+
56
+ /**
57
+ * Returns the fields as an array of field Name to value
58
+ **/
59
+ public function getFields($site) {
60
+ $fieldMapping = $this->getFieldMapping($site);
61
+ $deltaUpdate = array();
62
+ $attributes = Mage::helper('unbxd_datafeeder/UnbxdIndexingHelper')->getAttributes();
63
+ $escapedFields = $this->getConflictedFeatureFieldLust();
64
+ foreach($attributes as $attribute){
65
+ $fieldName = $attribute->getAttributeCode();
66
+
67
+ if (in_array($fieldName, $escapedFields)) {
68
+ $fieldName = "_".$fieldName;
69
+ }
70
+ if (!array_key_exists($fieldName, $fieldMapping)) {
71
+ $deltaUpdate[$fieldName] = array(self::STATUS => 1, self::DATA_TYPE => 'longText');
72
+ $fieldMapping[$fieldName] = array(self::STATUS => 1,
73
+ self::DATA_TYPE => 'longText',
74
+ self::AUTOSUGGEST => 1,
75
+ self::IMAGE_HEIGHT => 0,
76
+ self::IMAGE_WIDTH =>0,
77
+ self::GENERATE_IMAGE =>0);
78
+ }
79
+ if(!array_key_exists($fieldName."Associated", $fieldMapping)) {
80
+ $deltaUpdate[$fieldName."Associated"] = array(self::STATUS => 0, self::DATA_TYPE => 'longText');
81
+ $fieldMapping[$fieldName."Associated"] = array(self::STATUS => 0,
82
+ self::DATA_TYPE => 'longText',
83
+ self::AUTOSUGGEST => 1,
84
+ self::IMAGE_HEIGHT => 0,
85
+ self::IMAGE_WIDTH =>0,
86
+ self::GENERATE_IMAGE =>0);
87
+ }
88
+ }
89
+ if(sizeof($deltaUpdate) > 0) {
90
+ $this->saveField($deltaUpdate, $site);
91
+ }
92
+ return $fieldMapping;
93
+ }
94
+
95
+ /*
96
+ * update fields
97
+ */
98
+ public function updateFields($fieldMapping, $site) {
99
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
100
+ if(method_exists($write, 'getTableName')) {
101
+ $table = $write->getTableName(self::TABLE_NAME);
102
+ } else {
103
+ $table = self::TABLE_NAME;
104
+ }
105
+ foreach($fieldMapping as $fieldName=>$values) {
106
+ $values = json_decode($values, true);
107
+ if (!isset($values[self::STATUS]) || !isset($values[self::DATA_TYPE]) ||
108
+ !($values[self::STATUS] == 0 || $values[self::STATUS] == 1)) {
109
+ throw new Exception("Invalid data with field " . $fieldName);
110
+ }
111
+ $updateQuery = 'UPDATE `'. $table .'` set '.
112
+ self::STATUS ." = '".$values[self::STATUS]."' , ".
113
+ self::DATA_TYPE." = '". $values[self::DATA_TYPE]."' , ".
114
+ self::AUTOSUGGEST." = '". $values[self::AUTOSUGGEST]."' , ".
115
+ self::IMAGE_HEIGHT." = '". (is_int($values[self::IMAGE_HEIGHT])?$values[self::IMAGE_HEIGHT]:0) ."' , ".
116
+ self::IMAGE_WIDTH ." = '". (is_int($values[self::IMAGE_WIDTH])?$values[self::IMAGE_WIDTH]:0)."' , ".
117
+ self::GENERATE_IMAGE." = '".$values[self::GENERATE_IMAGE]."' ".
118
+ ' where '.self::SITE . "='". $site . "' AND " . self::FIELD_NAME . "='".$fieldName."'";
119
+ $write->query($updateQuery);
120
+ }
121
+ }
122
+
123
+ /*
124
+ * method to save the fieldMapping information
125
+ */
126
+ public function saveField($fieldMapping, $site) {
127
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
128
+ $insertingRequestArray = array();
129
+ foreach($fieldMapping as $field=>$value) {
130
+ $insertingRequest = array();
131
+ $insertingRequest[self::FIELD_NAME] = $field;
132
+ $insertingRequest[self::STATUS] = $value[self::STATUS];
133
+ $insertingRequest[self::SITE] = $site;
134
+ $insertingRequest[self::DATA_TYPE] = $value[self::DATA_TYPE];
135
+ $insertingRequest[self::AUTOSUGGEST] = $value[self::AUTOSUGGEST];
136
+ $insertingRequest[self::IMAGE_HEIGHT] = $value[self::IMAGE_HEIGHT];
137
+ $insertingRequest[self::IMAGE_WIDTH] = $value[self::IMAGE_WIDTH];
138
+ $insertingRequest[self::GENERATE_IMAGE] = $value[self::GENERATE_IMAGE];
139
+ $insertingRequestArray[] = $insertingRequest;
140
+ }
141
+ if(method_exists($write, 'getTableName')) {
142
+ $table = $write->getTableName(self::TABLE_NAME);
143
+ } else {
144
+ $table = self::TABLE_NAME;
145
+ }
146
+
147
+ $write->insertMultiple($table, $insertingRequestArray);
148
+ }
149
+
150
+ /*
151
+ * method to get the featured fields
152
+ */
153
+ public function getFeaturedFields() {
154
+ $featuredFields = array();
155
+ $featuredFields["uniqueId"]=$this->getField("text", "false", "false");
156
+ $featuredFields["sellingPrice"]=$this->getField("decimal", "false", "false");
157
+ $featuredFields["discount"]=$this->getField("decimal", "false", "false");
158
+ $featuredFields["rating"]=$this->getField("decimal", "false", "false");
159
+ $featuredFields["brandId"]=$this->getField("text", "false", "false");
160
+ $featuredFields["catlevel1Name"]=$this->getField("text", "false", "false");
161
+ $featuredFields["catlevel2Name"]=$this->getField("text", "false", "false");
162
+ $featuredFields["catlevel3Name"]=$this->getField("text", "false", "false");
163
+ $featuredFields["catlevel4Name"]=$this->getField("text", "false", "false");
164
+ $featuredFields["category"]=$this->getField("text", "true", "true");
165
+ $featuredFields["subCategory"]=$this->getField("text", "true", "true");
166
+ $featuredFields["color"]=$this->getField("text", "true", "false");
167
+ $featuredFields["size"]=$this->getField("text", "true", "false");
168
+ $featuredFields["availability"]=$this->getField("bool", "false", "false");
169
+ $featuredFields["description"]=$this->getField("longText", "false", "false");
170
+ $featuredFields["imageUrl"]=$this->getField("link", "true", "false");
171
+ $featuredFields["productUrl"]=$this->getField("link", "false", "false");
172
+ $featuredFields["brand"]=$this->getField("text", "false", "true");
173
+ $featuredFields["price"]=$this->getField("decimal", "false", "false");
174
+ $featuredFields["title"]=$this->getField("text", "false", "true");
175
+ $featuredFields["gender"]=$this->getField("text", "false", "false");
176
+ $featuredFields["unbxdVisibility"]=$this->getField("text", "false", "false");
177
+ return $featuredFields;
178
+ }
179
+
180
+ public function getField($dataType, $multiValued, $autosuggest) {
181
+ return array( self::DATA_TYPE => $dataType,
182
+ self::MULTIVALUED => ($multiValued=="true")?1:0,
183
+ self::AUTOSUGGEST => ($autosuggest=="true")?1:0 );
184
+
185
+ }
186
+
187
+
188
+ public function getConflictedFeatureFieldLust() {
189
+ return array('gender');
190
+ }
191
+ }
192
+ ?>
app/code/local/Unbxd/Datafeeder/Model/Mysql4/Field/Collection.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Unbxd_Datafeeder_Model_Mysql4_Field_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
4
+ {
5
+
6
+ public function _construct()
7
+ {
8
+ $this->_init('datafeeder/field');
9
+ }
10
+
11
+ }
12
+
13
+
14
+
15
+
16
+ ?>
app/code/local/Unbxd/Datafeeder/Model/Mysql4/Resource/Attribute.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Unbxd_Datafeeder_Model_Resource_Attribute{
4
+
5
+ $attributeMap = array();
6
+ public function getAttributeValue($attributeCode, $label, $product){
7
+ if(!isset($this->attributeMap[$label])){
8
+ if(!($product instanceof Mage_Catalog_Model_Product)){
9
+ return null;
10
+ }
11
+ $options = $product->getAttribute($attributeCode)
12
+ ->getSource()->getAllOptions();
13
+ foreach($options as $option){
14
+ $this->attributeMap[$option["label"]] = $option["value"];
15
+ }
16
+ }
17
+ return $this->attributeMap[$label];
18
+ }
19
+
20
+ }
21
+
22
+ ?>
app/code/local/Unbxd/Datafeeder/Model/Mysql4/Upgrade.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Unbxd_Datafeeder_Model_Mysql4_Upgrade {
3
+
4
+ public function upgrade010To105() {
5
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
6
+ $unbxdFieldTable = $write->getTableName('unbxd_field');
7
+ $unbxdConfTable = $write->getTableName('unbxd_datafeeder_conf');
8
+ $write->query("
9
+ DROP TABLE IF EXISTS `{$unbxdFieldTable}`;
10
+
11
+ CREATE TABLE `{$unbxdFieldTable}` (
12
+ `field_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
13
+ `name` varchar(100) NOT NULL DEFAULT '',
14
+ `status` int(1) NOT NULL DEFAULT '1',
15
+ `site` varchar(100) NOT NULL DEFAULT '',
16
+ `data_type` varchar(20) NOT NULL DEFAULT 'longText',
17
+ `autosuggest` int(1) NOT NULL DEFAULT '0',
18
+ `image_height` int(5) NOT NULL DEFAULT '0',
19
+ `image_width` int(5) NOT NULL DEFAULT '0',
20
+ `generate_image` int(1) NOT NULL DEFAULT '0',
21
+ PRIMARY KEY (`field_id`)
22
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
23
+
24
+ DROP TABLE IF EXISTS `{$unbxdConfTable}`;
25
+
26
+ CREATE TABLE `{$unbxdConfTable}` (
27
+ `uconfig_id` int(10) unsigned NOT NULL auto_increment,
28
+ `action` varchar(255) NOT NULL default '',
29
+ `value` varchar(255),
30
+ PRIMARY KEY (`uconfig_id`)
31
+
32
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
33
+ ");
34
+ }
35
+
36
+ }
37
+ ?>
app/code/local/Unbxd/Datafeeder/controllers/ConfigController.php ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Unbxd_Datafeeder_ConfigController extends Mage_Core_Controller_Front_Action
3
+ {
4
+
5
+ public function indexAction(){
6
+ $fromdate="1970-01-01 00:00:00";
7
+ $site=$this->getRequest()->getParam("site");
8
+ Mage::getSingleton('unbxd_datafeeder/feed_feedmanager')->process($fromdate,$site);
9
+ echo "Done";
10
+ }
11
+
12
+ /**
13
+ * gets all the stores
14
+ */
15
+ public function getAllstoreAction(){
16
+
17
+ $allStores = Mage::app()->getStores();
18
+
19
+ foreach ($allStores as $_eachStoreId => $val)
20
+ {
21
+ $_storeCode = Mage::app()->getStore($_eachStoreId)->getCode();
22
+ $_storeName = Mage::app()->getStore($_eachStoreId)->getName();
23
+ $_storeId = Mage::app()->getStore($_eachStoreId)->getId();
24
+ echo $_storeId."<br/>";
25
+ echo $_storeCode."<br/>";
26
+ echo $_storeName."<br/>";
27
+ }
28
+ $allsites=Mage::app()->getWebsites();
29
+ foreach($allsites as $site){
30
+ echo $site->getName();
31
+ }
32
+ }
33
+
34
+ /**
35
+ * resets the lock if the feed has been locked
36
+ **/
37
+ public function resetAction(){
38
+ $site=$this->getRequest()->getParam("site");
39
+ Mage::getResourceSingleton("datafeeder/conf")->updateAction($site.'/status','0');
40
+ $this->getResponse()->setBody("success");
41
+ $this->getResponse()->setHttpResponseCode(200);
42
+ }
43
+
44
+ public function getstoreviewAction(){
45
+
46
+ echo gettype(Mage::getModel('datafeeder/field'));
47
+ $collection= Mage::getModel("datafeeder/field")->getCollection();
48
+ foreach($collection as $coll){
49
+ echo $coll->getName();
50
+ }
51
+ }
52
+
53
+ public function progressAction()
54
+ {
55
+ $site = $this->getRequest()->getParam("site");
56
+ $status = Mage::getResourceSingleton("datafeeder/conf")->getValue($site."/status");
57
+ if($status == 'empty'){
58
+ $status = '0';
59
+ }
60
+ echo '{"status":"'.$status.'"}';
61
+ }
62
+
63
+ public function getfeedconfAction(){
64
+ $site = $this->getRequest()->getParam("site");
65
+ if(isset($site) && $site != ""){
66
+ $response = array();
67
+ $response["feed"] = Mage::getResourceSingleton("datafeeder/conf")->getValue($site."/feed");
68
+ $response["tax"] = Mage::getResourceSingleton("datafeeder/conf")->getValue($site."/tax");
69
+ $response["siteName"] = Mage::getResourceSingleton("datafeeder/conf")->getValue($site."/siteName");
70
+ echo json_encode($response);
71
+ }
72
+ }
73
+
74
+ public function upgradedbAction() {
75
+ Mage::getResourceSingleton("datafeeder/upgrade")->upgrade010To105();
76
+ echo json_encode( array('success' => 'true' ));
77
+ }
78
+ }
79
+ ?>
80
+
app/code/local/Unbxd/Datafeeder/controllers/FieldController.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Unbxd_Datafeeder_FieldController extends Mage_Core_Controller_Front_Action
4
+ {
5
+
6
+ const FIELD_MODEL = 'datafeeder/field';
7
+
8
+ public function configAction() {
9
+ $site=$this->getRequest()->getParam("site");
10
+ if(!isset($site)){
11
+ echo '{"failed": "no site sent"}';
12
+ return;
13
+ }
14
+ $fields = Mage::getResourceSingleton(self::FIELD_MODEL)->getFields($site);
15
+ foreach ($fields as $field => $value) {
16
+ if (Mage::helper('unbxd_datafeeder/UnbxdIndexingHelper')->isImage($field)) {
17
+
18
+ $value["is_image"] = "true";
19
+ $fields[$field] = $value;
20
+ }
21
+ }
22
+ echo json_encode($fields);
23
+ }
24
+
25
+ public function saveAction()
26
+ {
27
+ $params=$this->getRequest()->getParams();
28
+ if(!isset($params) || count($params) == 0) {
29
+ echo json_encode(array("success"=>"false", "message"=>"No Fields Passed"));
30
+ return;
31
+ }
32
+ $singleProductData = json_decode(reset($params), true);
33
+ if(!isset($singleProductData)) {
34
+ echo json_encode(array("success"=>"false", "message"=>"Improper Data format"));
35
+ return;
36
+ }
37
+ $site = $singleProductData["site_name"];
38
+ if (!isset($site)) {
39
+ echo json_encode(array("success"=>"false", "message"=>"site needed"));
40
+ return;
41
+ }
42
+ try {
43
+ $fields = Mage::getResourceSingleton(self::FIELD_MODEL)->updateFields($params,$site);
44
+ } catch(Exception $ex) {
45
+ error_log($ex->getMessage());
46
+ echo json_encode(array("success"=>"false", "message" => $ex));
47
+ return;
48
+ }
49
+ echo json_encode(array("success"=>"true"));
50
+ }
51
+ }
52
+ ?>
app/code/local/Unbxd/Datafeeder/controllers/IndexController.php ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Unbxd_Datafeeder_IndexController extends Mage_Adminhtml_Controller_Action {
4
+
5
+ protected function _getSession()
6
+ {
7
+ return Mage::getSingleton('catalog/session');
8
+ }
9
+
10
+ public function saveapiAction()
11
+ {
12
+ Mage::getResourceSingleton("datafeeder/conf")->updateAction("apiKey", $this->getRequest()->getparam("apikey"));
13
+ $this->loadLayout();
14
+ $this->_addContent($this->getLayout()->createBlock('unbxd_datafeeder/index')->setTemplate('datafeeder/conf.phtml'));
15
+ $this->renderLayout();
16
+ }
17
+
18
+ public function savefeedconfAction(){
19
+ Mage::getResourceSingleton("datafeeder/conf")->updateAction($this->getRequest()->getparam("site")."/feed", $this->getRequest()->getparam("feedName"));
20
+ Mage::getResourceSingleton("datafeeder/conf")->updateAction($this->getRequest()->getparam("site")."/tax", $this->getRequest()->getparam("feedName"));
21
+ Mage::getResourceSingleton("datafeeder/conf")->updateAction($this->getRequest()->getparam("site")."/siteName", $this->getRequest()->getparam("siteName"));
22
+
23
+ $this->loadLayout();
24
+ $this->_addContent($this->getLayout()->createBlock('unbxd_datafeeder/index')->setTemplate('datafeeder/conf.phtml'));
25
+ $this->renderLayout();
26
+ }
27
+
28
+ public function indexAction()
29
+ {
30
+ $this->loadLayout();
31
+ $this->_addContent($this->getLayout()->createBlock('unbxd_datafeeder/index')->setTemplate('datafeeder/conf.phtml'));
32
+ $this->renderLayout();
33
+ }
34
+
35
+ public function fullindexAction(){
36
+ $_helper=Mage::helper('unbxd_datafeeder/UnbxdIndexingHelper');
37
+ $fromdate="1970-01-01 00:00:00";
38
+ $site=$this->getRequest()->getPost("site");
39
+ //$_helper->indexUnbxdFeed($fromdate,$site);
40
+ Mage::getSingleton('unbxd_datafeeder/feed_feedmanager')->process($fromdate,$site);
41
+ echo "Done";
42
+ }
43
+
44
+ public function taxonomyindexAction(){
45
+ $_helper=Mage::helper('unbxd_datafeeder/UnbxdTaxonomyHelper');
46
+ $site=$this->getRequest()->getPost("site");
47
+ $_helper->indexUnbxdFeed($site);
48
+ }
49
+
50
+ public function incrementalindexAction()
51
+ {
52
+ $_helper=Mage::helper('unbxd_datafeeder/UnbxdIndexingHelper');
53
+ $fromdate=Mage::getResourceSingleton("datafeeder/conf")->getValue("Lastindex");
54
+ if(is_null($fromdate)){
55
+ $fromdate="1970-01-01 00:00:00";
56
+ }
57
+ $site=$this->getRequest()->getPost("site");
58
+ $_helper->indexUnbxdFeed($fromdate,$site);
59
+ echo "Done";
60
+ }
61
+ } ?>
app/code/local/Unbxd/Datafeeder/etc/adminhtml.xml ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <menu>
4
+ <unbxd_datafeeder translate="title" module="unbxd_datafeeder">
5
+ <title>Unbxd</title>
6
+ <sort_order>30</sort_order>
7
+ <children>
8
+ <upload translate="title" module="unbxd_datafeeder">
9
+ <title>Upload Configuration</title>
10
+ <sort_order>11</sort_order>
11
+ <action>datafeeder/index/index</action>
12
+ </upload>
13
+ </children>
14
+ </unbxd_datafeeder>
15
+ </menu>
16
+ </config>
app/code/local/Unbxd/Datafeeder/etc/config.xml ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Unbxd_Datafeeder>
5
+ <version>1.0.5</version>
6
+ </Unbxd_Datafeeder>
7
+ </modules>
8
+ <frontend>
9
+ <routers>
10
+ <datafeeder>
11
+ <use>standard</use>
12
+ <args>
13
+ <module>Unbxd_Datafeeder</module>
14
+ <frontName>datafeeder</frontName>
15
+ </args>
16
+ </datafeeder>
17
+ </routers>
18
+ </frontend>
19
+ <global>
20
+ <models>
21
+ <unbxd_datafeeder>
22
+ <class>Unbxd_Datafeeder_Model</class>
23
+ <resourceModel>unbxd_datafeeder_resource</resourceModel>
24
+ </unbxd_datafeeder>
25
+ <unbxd_datafeeder_resource>
26
+ <class>Unbxd_Datafeeder_Model_Resource</class>
27
+ </unbxd_datafeeder_resource>
28
+ </models>
29
+ <blocks>
30
+ <unbxd_datafeeder>
31
+ <class>Unbxd_Datafeeder_Block</class>
32
+ </unbxd_datafeeder>
33
+ </blocks>
34
+ </global>
35
+ <global>
36
+ <helpers>
37
+ <unbxd_datafeeder>
38
+ <class>Unbxd_Datafeeder_Helper</class>
39
+ </unbxd_datafeeder>
40
+ </helpers>
41
+ </global>
42
+ <admin>
43
+ <routers>
44
+ <unbxd_router>
45
+ <use>admin</use>
46
+ <args>
47
+ <module>Unbxd_Datafeeder</module>
48
+ <frontName>datafeeder</frontName>
49
+ </args>
50
+ </unbxd_router>
51
+ </routers>
52
+ </admin>
53
+ <adminhtml>
54
+ <!-- The <layout> updates allow us to define our block layouts in a separate file so are aren't messin' with the Magento layout files. -->
55
+ <layout>
56
+ <updates>
57
+ <unbxd_datafeeder>
58
+ <file>unbxd_datafeeder.xml</file>
59
+ </unbxd_datafeeder>
60
+ </updates>
61
+ </layout>
62
+ <!-- The <acl> section is for access control. Here we define the pieces where access can be controlled within a role. -->
63
+ <acl>
64
+ <resources>
65
+ <admin>
66
+ <children>
67
+ <unbxd_datafeeder>
68
+ <title>Unbxd Menu Item</title>
69
+ <children>
70
+ <example translate="title" module="unbxd_datafeeder">
71
+ <title>Example Menu Item</title>
72
+ </example>
73
+ </children>
74
+ </unbxd_datafeeder>
75
+ </children>
76
+ </admin>
77
+ </resources>
78
+ </acl>
79
+ </adminhtml>
80
+ <global>
81
+ <models>
82
+ <datafeeder>
83
+ <class>Unbxd_Datafeeder_Model</class>
84
+ <resourceModel>datafeeder_mysql4</resourceModel>
85
+ </datafeeder>
86
+ <datafeeder_mysql4>
87
+ <class>Unbxd_Datafeeder_Model_Mysql4</class>
88
+ <entities>
89
+ <conf>
90
+ <table>unbxd_datafeeder_conf</table>
91
+ </conf>
92
+ <field>
93
+ <table>unbxd_field</table>
94
+ </field>
95
+ </entities>
96
+ </datafeeder_mysql4>
97
+ </models>
98
+ <resources>
99
+ <datafeeder_setup>
100
+ <setup>
101
+ <module>Unbxd_Datafeeder</module>
102
+ </setup>
103
+ <connection>
104
+ <use>core_setup</use>
105
+ </connection>
106
+ </datafeeder_setup>
107
+ <datafeeder_write>
108
+ <connection>
109
+ <use>core_write</use>
110
+ </connection>
111
+ </datafeeder_write>
112
+ <datafeeder_read>
113
+ <connection>
114
+ <use>core_read</use>
115
+ </connection>
116
+ </datafeeder_read>
117
+ </resources>
118
+ </global>
119
+ </config>
app/code/local/Unbxd/Datafeeder/scripts/Cron.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once 'abstract.php';
3
+
4
+ class Unbxd_Datafeeder_Scripts_Cron extends Mage_Shell_Abstract
5
+ {
6
+
7
+ public function _getIndexer()
8
+ {
9
+ return Mage::helper('unbxd_datafeeder/UnbxdIndexingHelper');
10
+ }
11
+
12
+ public function run(){
13
+ $_helper = _getIndexer();
14
+ $fromdate="1970-01-01 00:00:00";
15
+ $site='Main Site';
16
+
17
+ $_helper->indexUnbxdFeed($fromdate,$site);
18
+ }
19
+
20
+ }
21
+
22
+
23
+ $shell = new Unbxd_Datafeeder_Scripts_Cron();
24
+ $shell->run();
25
+ ?>
app/code/local/Unbxd/Datafeeder/scripts/abstract.php ADDED
@@ -0,0 +1,218 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Shell
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Shell scripts abstract class
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Shell
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ abstract class Mage_Shell_Abstract
35
+ {
36
+ /**
37
+ * Is include Mage and initialize application
38
+ *
39
+ * @var bool
40
+ */
41
+ protected $_includeMage = true;
42
+
43
+ /**
44
+ * Magento Root path
45
+ *
46
+ * @var string
47
+ */
48
+ protected $_rootPath;
49
+
50
+ /**
51
+ * Initialize application with code (store, website code)
52
+ *
53
+ * @var string
54
+ */
55
+ protected $_appCode = 'admin';
56
+
57
+ /**
58
+ * Initialize application code type (store, website, store_group)
59
+ *
60
+ * @var string
61
+ */
62
+ protected $_appType = 'store';
63
+
64
+ /**
65
+ * Input arguments
66
+ *
67
+ * @var array
68
+ */
69
+ protected $_args = array();
70
+
71
+ /**
72
+ * Initialize application and parse input parameters
73
+ *
74
+ */
75
+ public function __construct()
76
+ {
77
+ if ($this->_includeMage) {
78
+ require_once $this->_getRootPath() . 'app' . DIRECTORY_SEPARATOR . 'Mage.php';
79
+ Mage::app($this->_appCode, $this->_appType);
80
+ }
81
+
82
+ $this->_applyPhpVariables();
83
+ $this->_parseArgs();
84
+ $this->_construct();
85
+ $this->_validate();
86
+ $this->_showHelp();
87
+ }
88
+
89
+ /**
90
+ * Get Magento Root path (with last directory separator)
91
+ *
92
+ * @return string
93
+ */
94
+ protected function _getRootPath()
95
+ {
96
+ if (is_null($this->_rootPath)) {
97
+ $this->_rootPath = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR;
98
+ }
99
+ return $this->_rootPath;
100
+ }
101
+
102
+ /**
103
+ * Parse .htaccess file and apply php settings to shell script
104
+ *
105
+ */
106
+ protected function _applyPhpVariables()
107
+ {
108
+ $htaccess = $this->_getRootPath() . '.htaccess';
109
+ if (file_exists($htaccess)) {
110
+ // parse htaccess file
111
+ $data = file_get_contents($htaccess);
112
+ $matches = array();
113
+ preg_match_all('#^\s+?php_value\s+([a-z_]+)\s+(.+)$#siUm', $data, $matches, PREG_SET_ORDER);
114
+ if ($matches) {
115
+ foreach ($matches as $match) {
116
+ @ini_set($match[1], str_replace("\r", '', $match[2]));
117
+ }
118
+ }
119
+ preg_match_all('#^\s+?php_flag\s+([a-z_]+)\s+(.+)$#siUm', $data, $matches, PREG_SET_ORDER);
120
+ if ($matches) {
121
+ foreach ($matches as $match) {
122
+ @ini_set($match[1], str_replace("\r", '', $match[2]));
123
+ }
124
+ }
125
+ }
126
+ }
127
+
128
+ /**
129
+ * Parse input arguments
130
+ *
131
+ * @return Mage_Shell_Abstract
132
+ */
133
+ protected function _parseArgs()
134
+ {
135
+ $current = null;
136
+ foreach ($_SERVER['argv'] as $arg) {
137
+ $match = array();
138
+ if (preg_match('#^--([\w\d_-]{1,})$#', $arg, $match) || preg_match('#^-([\w\d_]{1,})$#', $arg, $match)) {
139
+ $current = $match[1];
140
+ $this->_args[$current] = true;
141
+ } else {
142
+ if ($current) {
143
+ $this->_args[$current] = $arg;
144
+ } else if (preg_match('#^([\w\d_]{1,})$#', $arg, $match)) {
145
+ $this->_args[$match[1]] = true;
146
+ }
147
+ }
148
+ }
149
+ return $this;
150
+ }
151
+
152
+ /**
153
+ * Additional initialize instruction
154
+ *
155
+ * @return Mage_Shell_Abstract
156
+ */
157
+ protected function _construct()
158
+ {
159
+ return $this;
160
+ }
161
+
162
+ /**
163
+ * Validate arguments
164
+ *
165
+ */
166
+ protected function _validate()
167
+ {
168
+ if (isset($_SERVER['REQUEST_METHOD'])) {
169
+ die('This script cannot be run from Browser. This is the shell script.');
170
+ }
171
+ }
172
+
173
+ /**
174
+ * Run script
175
+ *
176
+ */
177
+ abstract public function run();
178
+
179
+ /**
180
+ * Check is show usage help
181
+ *
182
+ */
183
+ protected function _showHelp()
184
+ {
185
+ if (isset($this->_args['h']) || isset($this->_args['help'])) {
186
+ die($this->usageHelp());
187
+ }
188
+ }
189
+
190
+ /**
191
+ * Retrieve Usage Help Message
192
+ *
193
+ */
194
+ public function usageHelp()
195
+ {
196
+ return <<<USAGE
197
+ Usage: php -f script.php -- [options]
198
+
199
+ -h Short alias for help
200
+ help This help
201
+ USAGE;
202
+ }
203
+
204
+ /**
205
+ * Retrieve argument value by name or false
206
+ *
207
+ * @param string $name the argument name
208
+ * @return mixed
209
+ */
210
+ public function getArg($name)
211
+ {
212
+ if (isset($this->_args[$name])) {
213
+ return $this->_args[$name];
214
+ }
215
+ return false;
216
+ }
217
+ }
218
+
app/code/local/Unbxd/Datafeeder/sql/datafeeder_setup/mysql4-install-1.0.5.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ $installer = $this;
5
+ /* @var $installer Mage_Core_Model_Resource_Setup */
6
+
7
+ $installer->startSetup();
8
+
9
+ $installer->run("
10
+
11
+ DROP TABLE IF EXISTS `{$installer->getTable('unbxd_field')}`;
12
+
13
+ CREATE TABLE `{$installer->getTable('unbxd_field')}` (
14
+ `field_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
15
+ `name` varchar(100) NOT NULL DEFAULT '',
16
+ `status` int(1) NOT NULL DEFAULT '1',
17
+ `site` varchar(100) NOT NULL DEFAULT '',
18
+ `data_type` varchar(20) NOT NULL DEFAULT 'longText',
19
+ `autosuggest` int(1) NOT NULL DEFAULT '0',
20
+ `image_height` int(5) NOT NULL DEFAULT '0',
21
+ `image_width` int(5) NOT NULL DEFAULT '0',
22
+ `generate_image` int(1) NOT NULL DEFAULT '0',
23
+ PRIMARY KEY (`field_id`)
24
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
25
+
26
+ DROP TABLE IF EXISTS `{$installer->getTable('unbxd_datafeeder_conf')}`;
27
+
28
+ CREATE TABLE `{$installer->getTable('unbxd_datafeeder_conf')}` (
29
+ `uconfig_id` int(10) unsigned NOT NULL auto_increment,
30
+ `action` varchar(255) NOT NULL default '',
31
+ `value` varchar(255),
32
+ PRIMARY KEY (`uconfig_id`)
33
+
34
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
35
+
36
+ ");
37
+ $installer->endSetup();
38
+
39
+
app/code/local/Unbxd/Datafeeder/sql/datafeeder_setup/mysql4-upgrade-0.1.0-1.0.5.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ $installer = $this;
5
+ /* @var $installer Mage_Core_Model_Resource_Setup */
6
+
7
+ $installer->startSetup();
8
+
9
+ $installer->run("
10
+
11
+ DROP TABLE IF EXISTS `{$installer->getTable('unbxd_field')}`;
12
+
13
+ CREATE TABLE `{$installer->getTable('unbxd_field')}` (
14
+ `field_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
15
+ `name` varchar(100) NOT NULL DEFAULT '',
16
+ `status` int(1) NOT NULL DEFAULT '1',
17
+ `site` varchar(100) NOT NULL DEFAULT '',
18
+ `data_type` varchar(20) NOT NULL DEFAULT 'longText',
19
+ `autosuggest` int(1) NOT NULL DEFAULT '0',
20
+ `image_height` int(5) NOT NULL DEFAULT '0',
21
+ `image_width` int(5) NOT NULL DEFAULT '0',
22
+ `generate_image` int(1) NOT NULL DEFAULT '0',
23
+ PRIMARY KEY (`field_id`)
24
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
25
+
26
+ DROP TABLE IF EXISTS `{$installer->getTable('unbxd_datafeeder_conf')}`;
27
+
28
+ CREATE TABLE `{$installer->getTable('unbxd_datafeeder_conf')}` (
29
+ `uconfig_id` int(10) unsigned NOT NULL auto_increment,
30
+ `action` varchar(255) NOT NULL default '',
31
+ `value` varchar(255),
32
+ PRIMARY KEY (`uconfig_id`)
33
+
34
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
35
+
36
+ ");
37
+ $installer->endSetup();
38
+
39
+
app/design/adminhtml/base/default/template/datafeeder/conf.phtml ADDED
@@ -0,0 +1,439 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script src="//code.jquery.com/jquery-1.8.0.min.js"></script>
2
+ <script src="//malsup.github.com/jquery.form.js"></script>
3
+ <style type="text/css">
4
+ td
5
+ {
6
+ margin-left:100cm;
7
+ padding:10px;
8
+ vertical-align:left;
9
+ }
10
+ .datafeeder-form input[type="text"] {
11
+ width: 300px;
12
+ }
13
+
14
+ .fieldRowSelected {
15
+ background-color: #45b5c1;
16
+ }
17
+
18
+ .text_td {
19
+ padding-top: 6px;
20
+ width: 117px;
21
+ }
22
+
23
+ .plus {
24
+ background:url('http://unbxd.com/img/CircledPlus.png') no-repeat;
25
+ height: 24px;
26
+ width: 24px;
27
+ }
28
+
29
+ .minus {
30
+ background:url('http://unbxd.com/img/CircledMinus.png') no-repeat;
31
+ height: 24px;
32
+ width: 24px;
33
+ }
34
+
35
+ .hidden_image_textBox {
36
+ display: none;
37
+ }
38
+
39
+ .form-list td.value select {
40
+ width: 110px;
41
+ }
42
+
43
+ #field-list td {
44
+ width: 120px;
45
+ }
46
+
47
+ </style>
48
+ <script type="text/javascript">
49
+ var $jq = jQuery.noConflict();
50
+ </script>
51
+ <frameset cols="50%,50%">
52
+ <frame name="actual_frame">
53
+ <div class="datafeeder-form" onload="allset()">
54
+ <form action="<?php echo $this->getSaveApiUrl();?>" method="POST" >
55
+
56
+ <span><b>Unbxd API Key: </b><span>
57
+ <input type="text" name="apikey" style="margin-left: 10px;" value="<?php echo $this->getApiKey(); ?>">
58
+ <input type="submit" style="margin-left: 10px;" value="SAVE"/>
59
+ </form>
60
+ <form action="<?php echo $this->saveFeedConf();?>" method="POST" >
61
+ <p class="switcher">
62
+ <label for="store_switcher"><b>Choose Store View: </b><label>
63
+
64
+ <select id="site" class="site" name="site" onload="newajaxcall('<?php echo $this->getFeedConf(); ?>')" onchange="newajaxcall('<?php echo $this->getFeedConf();?>')">
65
+ <?php $allsites=Mage::app()->getWebsites();?>
66
+ <?php foreach ($allsites as $site):?>
67
+ <option value="<?php echo $site->getName()?>"><?php echo $site->getName()?></option>
68
+ <?php endforeach;?>
69
+ </select>
70
+ </p>
71
+
72
+
73
+ <table class="form-list" onload="allset()" id="form-list1" name="form-list" cellspacing="0" style="background:none repeat scroll 0 0 #FAFAFA;border=1px solid #D6D6D6;width: 100%;" width="5000px">
74
+ <div class="datafeeder-form" width="parent" style="background:none repeat scroll 0 0 #6F8992;padding:5px 10px; color: white;">
75
+ FEED CONFIGURATION
76
+ </div>
77
+ <tr>
78
+ <td class="label">
79
+ <b>Unbxd Site Key: </b>
80
+ </td>
81
+ <td class="value">
82
+ <input type="text" id="siteName" name="siteName" value="" disabled/>
83
+ </td>
84
+ </tr>
85
+ </tr>
86
+ <tr>
87
+ <td class="label">
88
+ </td>
89
+ <td class="value">
90
+ <input type="button" name="editButton" value="EDIT"/> <input style="margin-left: 10px;" type="submit" value="SAVE"/>
91
+ </td>
92
+ </tr>
93
+ </table>
94
+
95
+ <input name="form_key" type="hidden" value="<?php echo Mage::getSingleton('core/session')->getFormKey() ?>" />
96
+ </form>
97
+ <script type="text/javascript">
98
+
99
+ $jq('[name=editButton]').click(function(evt){
100
+ $jq('[name="feedName"]').attr('disabled', false);
101
+ $jq('[name="siteName"]').attr('disabled', false);
102
+ });
103
+
104
+ function progressbar()
105
+ {
106
+ $jq.ajax({
107
+ //async:false,
108
+ url: "<?php echo $this->getProgressUrl(); ?>",
109
+ type:"POST",
110
+ dataType:"json",
111
+ data:{"form_key":"<?php echo Mage::getSingleton('core/session')->getFormKey()?>",
112
+ "site": $jq('[name=site]').val()
113
+ },
114
+ success: function(data) {
115
+ document.getElementById("ProgressBar").innerHTML="";
116
+ if(data.status=="0"){
117
+ document.getElementById("ProgressBar").innerHTML="<b>Status: Indexed</b>";
118
+ document.getElementById("fullupload").disabled=false;
119
+ }else if(data.status=="1"){
120
+ document.getElementById("ProgressBar").innerHTML="<b>Status: Indexing</b>";
121
+ document.getElementById("fullupload").disabled=true;
122
+ }
123
+ }
124
+ });
125
+
126
+ }
127
+
128
+ function callSetInterval()
129
+ {
130
+ setInterval(progressbar,20000);
131
+ }
132
+
133
+ function newajaxcall(ajaxurl){
134
+ $jq.ajax({
135
+
136
+ url: ajaxurl,
137
+ timeout:30000,
138
+ type:"POST",
139
+ dataType: "json",
140
+ data:{"form_key":"<?php echo Mage::getSingleton('core/session')->getFormKey()?>",
141
+ "site":$jq('[name=site]').val(),
142
+ },
143
+
144
+ success: function(data) {
145
+
146
+ if(data.feed !== "empty") $jq('[name=feedName]').val(data.feed); else $jq('[name=feedName]').val("");
147
+ if(data.siteName !== "empty") $jq('[name=siteName]').val(data.siteName); else $jq('[name=siteName]').val("");
148
+ },
149
+
150
+ fail: function(XMLHttpRequest, textStatus, errorThrown) {
151
+ }
152
+ });
153
+ }
154
+
155
+ newajaxcall("<?php echo $this->getFeedConf();?>");
156
+
157
+ function makeajaxcall(ajaxurl){
158
+
159
+ $jq.ajax({
160
+
161
+ url: ajaxurl,
162
+ timeout:100000,
163
+ type:"POST",
164
+ data:{"form_key":"<?php echo Mage::getSingleton('core/session')->getFormKey()?>",
165
+ "site": $jq('[name=site]').val()
166
+ },
167
+
168
+ complete: function(xhr, statusText){
169
+ },
170
+
171
+ done: function(data) {
172
+ console.log(data);
173
+ },
174
+
175
+ fail: function(XMLHttpRequest, textStatus, errorThrown) {
176
+ }
177
+ });
178
+ }
179
+
180
+ $jq('#config_edit_form').ready(function(){
181
+ createTable('<?php echo $this->getEditUrl();?>');
182
+ });
183
+
184
+ function saveFieldConf()
185
+ {
186
+ site = $jq('[name=site]').val();
187
+ fields = {}
188
+ $jq("#field-list").find("tr").each( function() {
189
+ var field = {};
190
+ if ($jq(this).find(".label").text() != "") {
191
+ field["status"] = ($jq(this).find('[name=status]').find(":selected").text() == "Enabled") ? 1 :0;
192
+ field["autosuggest"] = ($jq(this).find('[name=autosuggest]').find(":selected").text() == "Enabled") ? 1 :0;
193
+ field["data_type"] = $jq(this).find('[name=dataType]').find(":selected").text();
194
+ field["site_name"] = $jq('[name=site]').val();
195
+ field["generate_image"] = $jq(this).find('[id=generate_image]').is(':checked')?1:0;
196
+ element = this.querySelector('#image_height');
197
+ if(element) {
198
+ field["image_height"] = parseInt(element.value);
199
+ }
200
+ element = this.querySelector('#image_width') ;
201
+ if (element) {
202
+ field["image_width"] = parseInt(element.value);
203
+ }
204
+ fields[$jq(this).find(".label").text()] = JSON.stringify(field);
205
+
206
+ childProductField = {};
207
+ if (this.className == "fieldRowSelected"){
208
+ childProductField["status"] = field["status"];
209
+ } else {
210
+ childProductField["status"] = 0;
211
+ }
212
+ childProductField["autosuggest"] = field["autosuggest"];
213
+ childProductField["data_type"] = field["data_type"];
214
+ childProductField["site_name"] = field["site_name"];
215
+ childProductField["generate_image"] = field["generate_image"];
216
+ childProductField["image_width"] = field["image_width"];
217
+ childProductField["image_height"] = field["image_height"];
218
+ fields[$jq(this).find(".label").text() + "Associated"] = JSON.stringify(childProductField);
219
+
220
+ }
221
+ });
222
+ $jq.ajax({
223
+ url: "<?php echo $this->getSaveFieldUrl();?>",
224
+ timeout:30000,
225
+ type:"POST",
226
+ dataType: "json",
227
+ data:fields
228
+ }).done( function(data) {
229
+ createTable('<?php echo $this->getEditUrl();?>');
230
+ });
231
+
232
+ }
233
+
234
+ function createTable(ajaxurl)
235
+ {
236
+ site= $jq("#site").val();
237
+ $jq.ajax({
238
+ url: ajaxurl,
239
+ type:"POST",
240
+ data:{"site":site},
241
+ }).done( function(data) {
242
+ jarray = $jq.parseJSON(data);
243
+ tableHtml="<tbody>";
244
+ $jq("#field-list").find("tr").remove();
245
+ tableHtml += addFieldConfTableHeader();
246
+ $jq.each(jarray, function(key, value) {
247
+ childExists = false;
248
+ if ((key + "Associated") in jarray && jarray[key + "Associated"]["status"] == "1") {
249
+ childExists = true
250
+ }
251
+ if( key.substr(-10) != "Associated" ) {
252
+ tableHtml += constructRow(key, value, childExists);
253
+ }
254
+ });
255
+ tableHtml+="</tbody>";
256
+ $jq('#field-list').append(tableHtml)
257
+ });
258
+ }
259
+
260
+ function addFieldConfTableHeader() {
261
+ return "<tr>" +
262
+ "<th>Field Name</th>" +
263
+ "<th>Status</th>" +
264
+ "<th>Data Type</th>" +
265
+ "<th>Autosuggest</th>" +
266
+ "<th>Add to configurable product</th>" +
267
+ "<th>Image configuration</th>" +
268
+ '<td class="scope-label"></td>' +
269
+ "</tr>";
270
+ }
271
+
272
+ function constructRow(key, value, childExists) {
273
+ tableString = "";
274
+ tableString += '<tr ' + (childExists?'class="fieldRowSelected"':"") + '>';
275
+ tableString += '<td class="label" name="fieldName"><div class="text_td">'+key+"</div></td>";
276
+ tableString += constructBooleanSelect("status", value);
277
+ tableString += constructDataType(key, value);
278
+ tableString += constructBooleanSelect("autosuggest", value);
279
+ tableString += constructAddToConfigurableFieldList(childExists);
280
+ tableString += constructImageConf(key, value);
281
+ tableString +='</tr>';
282
+ return tableString;
283
+ }
284
+
285
+ function constructImageConf(key, value) {
286
+ if(!("is_image" in value) || value["is_image"] != "true") {
287
+ return "";
288
+ }
289
+ tableString = "";
290
+ tableString += '<td><input type="button" value="EDIT" onclick="editImageConf(this)"/>'
291
+ tableString += '<div class="hidden_image_textBox">';
292
+ image_generation_enabled = (value["generate_image"] == 1)? true : false;
293
+ tableString += '<input id="generate_image" onchange="toggleTextBox(this)" type="checkbox" ' + ((image_generation_enabled)?'checked':'')+'/>';
294
+ tableString += '<input id="image_height" type="text" value="' + value["image_height"]+ '" '+ (image_generation_enabled? '':'disabled')+'"/>';
295
+ tableString += '<input id="image_width" type="text" value="' + value["image_width"]+ '" '+ (image_generation_enabled? '':'disabled')+'"/>';
296
+ tableString += '<input value = "update" type="button" onclick="hideDiv(this);"/>';
297
+ tableString += '</div>';
298
+ tableString += '</td>';
299
+ return tableString;
300
+ }
301
+
302
+ function toggleTextBox(element) {
303
+ active = element.checked ? false: true;
304
+ element.parentElement.children[1].disabled = active;
305
+ element.parentElement.children[2].disabled = active;
306
+ }
307
+
308
+ function hideDiv(element) {
309
+ element.parentElement.parentElement.children[1].className = "hidden_image_textBox";
310
+ element.parentElement.parentElement.children[0].className = "";
311
+ }
312
+
313
+ function editImageConf(element) {
314
+ element.parentElement.children[1].className = "";
315
+ element.className = "hidden_image_textBox";
316
+ }
317
+
318
+ function getRowSelected(element) {
319
+ if(element.parentElement.parentElement.className == "fieldRowSelected") {
320
+ element.parentElement.parentElement.className = "";
321
+ element.children[0].className = "plus";
322
+ return;
323
+ }
324
+ if($jq.find(".fieldRowSelected").length > 10) {
325
+ alert("Cant select more than 10 fields");
326
+ return;
327
+ }
328
+ element.children[0].className = "minus";
329
+ element.parentElement.parentElement.addClassName("fieldRowSelected");
330
+ }
331
+
332
+ function constructAddToConfigurableFieldList(childExists) {
333
+ tableString = '<td><a href="javascript:void(0)" onclick="getRowSelected(this)" title="Add this field in configurable/grouped product">';
334
+ tableString += '<div ';
335
+ if(!childExists) {
336
+ tableString += 'class="plus"';
337
+ } else {
338
+ tableString += 'class="minus"';
339
+ }
340
+ tableString += "/></a></td>";
341
+ return tableString;
342
+ }
343
+
344
+ function constructBooleanSelect(key, value) {
345
+ tableString = '<td class="value"><div class="text_td"><select name=' + key + '>'+"<option";
346
+ if(value[key]=="0"){
347
+ tableString +=' selected="selected"';
348
+ }
349
+ tableString+=' value="0">Disabled</option><option';
350
+ if(value[key]!="0"){
351
+ tableString +=' selected="selected"';
352
+ }
353
+ tableString +=' value="1">Enabled</option></select></div></td>';
354
+ return tableString;
355
+ }
356
+
357
+ function constructDataTypeOption(data_type, compare_data_type) {
358
+ tableString = "<option";
359
+
360
+ if(data_type == compare_data_type){
361
+ tableString +=' selected="selected"';
362
+ }
363
+ tableString+=' value="' + compare_data_type + '">' + compare_data_type + '</option>';
364
+ return tableString;
365
+ }
366
+
367
+ function constructDataType(key, value) {
368
+ tableString = '<td class="value"><div class="text_td"><select name="dataType">';
369
+ tableString += constructDataTypeOption(value["data_type"], "text");
370
+ tableString += constructDataTypeOption(value["data_type"], "longText");
371
+ tableString += constructDataTypeOption(value["data_type"], "link");
372
+ tableString += constructDataTypeOption(value["data_type"], "decimal");
373
+ tableString += constructDataTypeOption(value["data_type"], "number");
374
+ tableString += constructDataTypeOption(value["data_type"], "date");
375
+ //tableString += constructDataTypeOption(value["data_type"], "bool");
376
+
377
+ tableString +='</select></div></td>';
378
+ return tableString;
379
+ }
380
+
381
+ setInterval(progressbar,10000);
382
+ </script>
383
+
384
+
385
+ <table class="form-list" width="parent" id="form-list2" name="form-list" cellspacing="0" style="background:none repeat scroll 0 0 #FAFAFA;border=1px solid #D6D6D6;width: 100%;">
386
+ <div class="datafeeder-form" width="parent" style="background:none repeat scroll 0 0 #6F8992;padding:5px 10px;color: white;">
387
+ <div class="refreshDiv" style="float: right;"><span id="ProgressBar"></span><input type="button" id="refresh" onclick="progressbar()" value="REFRESH" style="margin-left: 10px;vertical-align: top;"></div>
388
+ <b>UPLOAD &amp; INDEX (manual)</b>
389
+ </div>
390
+
391
+ <tr>
392
+ <td class="label"><b>PRODUCT FEED UPLOAD: </b></td>
393
+ <td class="value"><input type="button" id="fullupload" onclick="makeajaxcall('<?php echo $this->getFullIndexFormAction(); ?>')" value="START"/></td>
394
+
395
+ </tr>
396
+
397
+ </table>
398
+
399
+ <input name="form_key" type="hidden" value="<?php echo Mage::getSingleton('core/session')->getFormKey() ?>"/>
400
+ </div>
401
+ </frame>
402
+ <frame name="login_frame"></frame>
403
+ </frameset>
404
+
405
+ <div class="editconfig">
406
+ <div class="content-header">
407
+ <table cellspacing="0">
408
+ <tr>
409
+ <td>
410
+ <h3 <?php if($this->getHeaderCss()): ?>
411
+ class="<?php echo $this->getHeaderCss()?>" <?php endif; ?>>
412
+ <?php echo Mage::helper('adminhtml')->__("FIELD CONFIGURATION") ?>
413
+ </h3>
414
+ </td>
415
+ <td class="form-buttons">
416
+ <input type="button" style='background:url("images/btn_bg.gif") repeat-x scroll 0 100% #FFAC47;border-color:#ED6502 #A04300 #A04300 #ED6502;border-style:solid;border-width:1px;color:#FFFFFF;font:bold 12px arial,helvetica,sans-serif;text-align:center !important;white-space:nowrap;padding: 3px;' onclick="saveFieldConf()" value="SAVE"/>
417
+ </td>
418
+ </tr>
419
+ </table>
420
+ </div>
421
+ <div class="unbxd_edit_config" style="background:none repeat scroll 0 0 #FAFAFA;border:1px solid #D6D6D6">
422
+
423
+ <form action="<?php echo $this->getSaveFieldUrl() ?>" method="post"
424
+ id="config_edit_form" onload="createTable('<?php echo $this->getEditUrl();?>')">
425
+ <input name="site_name" id= "site_name" type="hidden" />
426
+ <!--<center>-->
427
+ <p class="switcher">
428
+ <label for="store_switcher"><b> Field Configuration </b><label>
429
+ </p>
430
+
431
+ <table class="form-list" id="field-list" name="form-list" cellspacing="0" style="color: #2F2F2F;
432
+ font: 12px/1.5em Arial,Helvetica,sans-serif; margin-left: 1%;">
433
+ </table>
434
+
435
+ <input name="form_key" type="hidden" value="<?php echo Mage::getSingleton('core/session')->getFormKey() ?>" />
436
+
437
+ </form>
438
+ </div>
439
+ </div>
app/etc/modules/Unbxd_Datafeeder.xml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <config>
2
+ <modules>
3
+ <Unbxd_Datafeeder>
4
+ <active>true</active>
5
+ <codePool>local</codePool>
6
+ </Unbxd_Datafeeder>
7
+ </modules>
8
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>unbxd_recommendation</name>
4
+ <version>1.0.6</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>helps integrating the unbxd recommender widgets</summary>
10
+ <description>helps integrating the unbxd recommender widgets</description>
11
+ <notes>supports all the unbxd recommendor widgets</notes>
12
+ <authors><author><name>ananthesh</name><user>ananthesh</user><email>ananthesh@unbxd.com</email></author></authors>
13
+ <date>2014-08-28</date>
14
+ <time>07:45:09</time>
15
+ <contents><target name="magelocal"><dir name="Unbxd"><dir name="Datafeeder"><dir name="Block"><file name="Edit.php" hash="6cc7e0396c298656c2529d2651bc0ae1"/><file name="Index.php" hash="9114009eae54970145fbb849cfc22dfd"/></dir><dir name="Helper"><file name="Analyticshelper.php" hash="9c841be95363d1e100e9a00c7d95f7d6"/><file name="Data.php" hash="cc32188ca72c365a3177b8439188f4b0"/><file name="UnbxdIndexingHelper.php" hash="e4299a181161ba65d80bf579aaea0502"/><file name="UnbxdTaxonomyHelper.php" hash="9c16f370fa44807d8524c549c1ddb017"/><file name=".DS_Store" hash="801d9a1a1f478b210726cfc656cec74f"/></dir><dir name="Model"><file name="Attribute.php" hash="9b7e4dea003568ffb016b60f20b35e74"/><file name="Conf.php" hash="b9a9627d779f473b7ab1696fd44a877b"/><file name="Facet.php" hash="a778acee165d1ff0162be6664f4ecf1a"/><dir name="Feed"><file name="Feedcreator.php" hash="675028dc51d02e4be956336bdbc89113"/><file name="Feedmanager.php" hash="c21018ecd585098fcca1ae360a6c2b85"/><file name="Filemanager.php" hash="5200abf7349679edec7e617619c8d8b3"/><dir name="Jsonbuilder"><file name="Jsonbuilder.php" hash="77635e52b5ec7c39dae78094efed566e"/><file name="Productbuilder.php" hash="38bb898b6fcc2e97a6d74b3bf9edce41"/><file name="Schemabuilder.php" hash="240d31fc4a3829d075d0ed83daf2ddae"/><file name="Taxonomybuilder.php" hash="75463b9c001b443f7d64470d5347ea59"/></dir></dir><file name="Field.php" hash="4206919e3762907aba7d38b39733deba"/><dir name="Mysql4"><file name="Attribute.php" hash="7ec9732a1399db03dec0b6002d1aeb58"/><dir name="Conf"><file name="Collection.php" hash="fa30f58432618d2822ce0e3fe1483efe"/></dir><file name="Conf.php" hash="ad03b89d6bd43893f171fb08e142fbc0"/><dir name="Field"><file name="Collection.php" hash="5c9a40a3f2df168531c1af18be63bf16"/></dir><file name="Field.php" hash="61c8a1a5aa7b763925896b4f74bf4a56"/><dir name="Resource"><file name="Attribute.php" hash="9353baa4f14eeb342de93d20c566bfee"/></dir><file name="Upgrade.php" hash="e3e259f32cdcf58d2dca2a21d6262767"/></dir></dir><dir name="controllers"><file name="ConfigController.php" hash="e9b049ba4913e4733a251035f9654beb"/><file name="FieldController.php" hash="0c93a9c339d718179641c0a47cccaa6c"/><file name="IndexController.php" hash="90a2150b94caa81fd598d01f3e0c124b"/></dir><dir name="etc"><file name="adminhtml.xml" hash="243eca656901fd022f8119a3ad46b569"/><file name="config.xml" hash="7c26ae17786870ee2536d68f8d9d868c"/></dir><dir name="scripts"><file name="Cron.php" hash="087a021cf47794f337e4ce0130b2d3b7"/><file name="abstract.php" hash="757e66bc99da02c274a0d9723923329e"/></dir><dir name="sql"><dir name="datafeeder_setup"><file name="mysql4-install-1.0.5.php" hash="27ecb984b7419e2fc58433db370fe43d"/><file name="mysql4-upgrade-0.1.0-1.0.5.php" hash="27ecb984b7419e2fc58433db370fe43d"/></dir></dir><file name=".DS_Store" hash="b4a356bd7741138b66aa79afcc4abd2f"/></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="base"><dir name="default"><dir name="template"><dir name="datafeeder"><file name="conf.phtml" hash="87911c34bc9c06f617d83e8d70b4c81d"/></dir></dir></dir></dir></dir></target><target name="mageweb"><dir name="shell"><file name="UnbxdFeed.php" hash="2b70f51b04c4b62b4a51aca0efae7050"/></dir></target><target name="mageetc"><dir name="modules"><file name="Unbxd_Datafeeder.xml" hash="73f1469ef7c4f5c4eef05900302239de"/></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>
shell/UnbxdFeed.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once 'abstract.php';
3
+
4
+ class Unbxd_Datafeeder_Scripts_UnbxdFeed extends Mage_Shell_Abstract
5
+ {
6
+
7
+ public function _getIndexer()
8
+ {
9
+ return Mage::helper('unbxd_datafeeder/UnbxdIndexingHelper');
10
+ }
11
+
12
+ public function run(){
13
+ $_helper = $this->_getIndexer();
14
+ $fromdate="1970-01-01 00:00:00";
15
+ $site='Main Website';
16
+
17
+ $_helper->indexUnbxdFeed($fromdate,$site);
18
+ }
19
+
20
+ }
21
+
22
+
23
+ $shell = new Unbxd_Datafeeder_Scripts_UnbxdFeed();
24
+ $shell->run();
25
+ ?>