DataFeedWatch_Connector - Version 0.2.5

Version Notes

DataFeedWatch Release version 0.2.5

Download this release

Release Info

Developer DataFeedWatch
Extension DataFeedWatch_Connector
Version 0.2.5
Comparing to
See all releases


Code changes from version 0.2.4 to 0.2.5

app/code/local/DataFeedWatch/Connector/Model/Datafeedwatch/Api.php CHANGED
@@ -1,374 +1,401 @@
1
  <?php
 
 
 
 
 
 
 
 
 
 
 
2
 
3
- class DataFeedWatch_Connector_Model_Datafeedwatch_Api extends Mage_Catalog_Model_Product_Api {
4
-
5
- const STOCK_ITEM_MODEL = 'cataloginventory/stock_item';
6
- const CATALOG_PRODUCT_MODEL = 'catalog/product';
7
-
8
- // category
9
- const CATALOG_CATEGORY_MODEL = 'catalog/category';
10
- const CATEGORY_NAME_FIELD = 'name';
11
- const CATEGORY_SEPARATOR = ' > ';
12
-
13
- public function __construct() {
14
- $this->categories = array();
15
- ini_set('memory_limit','1024M');
16
- }
17
-
18
- public function version() {
19
- return "0.2.4"; // this needs to be updated in etc/config.xml as well
20
  }
21
-
22
- public function product_count($options = array()) {
23
- $collection = Mage::getModel(self::CATALOG_PRODUCT_MODEL)
24
- ->getCollection();
25
-
26
- if (array_key_exists('store', $options)) {
27
- $collection->addStoreFilter($this->_getStoreId($options['store']));
28
- }
29
-
30
- $apiHelper = Mage::helper('api');
31
- $filters = $apiHelper->parseFilters($options, $this->_filtersMap);
32
- try {
33
- foreach ($filters as $field => $value) {
34
- $collection->addFieldToFilter($field, $value);
35
- }
36
- } catch (Mage_Core_Exception $e) {
37
- $this->_fault('filters_invalid', $e->getMessage());
38
  }
39
-
40
- $numberOfProducts = 0;
41
- if (!empty($collection)) {
42
- $numberOfProducts = $collection->getSize();
43
- }
44
-
45
- return round($numberOfProducts);
46
  }
47
-
48
- public function products($options = array()) {
49
-
50
- if (!array_key_exists('page', $options)) {
51
- $options['page'] = 1;
52
- }
53
-
54
- if (!array_key_exists('per_page', $options)) {
55
- $options['per_page'] = 100;
56
- }
57
-
58
- $collection = Mage::getModel(self::CATALOG_PRODUCT_MODEL)
59
- ->getCollection()
60
- ->addAttributeToSelect('*')
61
- ->setPage($options['page'], $options['per_page']);
62
-
63
- if (array_key_exists('store', $options)) {
64
- $collection->addStoreFilter($this->_getStoreId($options['store']));
65
- }
66
-
67
- // clear options that are not filters
68
- unset($options['page']);
69
- unset($options['per_page']);
70
- unset($options['store']);
71
-
72
- $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
73
- $imageBaseURL = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . self::CATALOG_PRODUCT_MODEL;
74
-
75
- $this->_loadCategories();
76
-
77
- /** @var $apiHelper Mage_Api_Helper_Data */
78
- $apiHelper = Mage::helper('api');
79
- $filters = $apiHelper->parseFilters($options, $this->_filtersMap);
80
- try {
81
- foreach ($filters as $field => $value) {
82
- $collection->addFieldToFilter($field, $value);
83
- }
84
- } catch (Mage_Core_Exception $e) {
85
- $this->_fault('filters_invalid', $e->getMessage());
 
 
 
 
 
86
  }
87
-
88
- $result = array();
89
- $product_cache = array();
90
- $price_keys = array('price', 'special_price');
91
-
92
- foreach ($collection as $product) {
93
- $product_result = array(// Basic product data
94
- 'product_id' => $product->getId(),
95
- 'sku' => $product->getSku()
96
- );
97
-
98
- $parent_id = '0';
99
- $configrable = false;
100
-
101
- if ($product->getTypeId() == "simple") {
102
- $parentIds = Mage::getModel('catalog/product_type_grouped')->getParentIdsByChild($product->getId());
103
- if (!$parentIds) {
104
- $parentIds = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($product->getId());
105
- if (isset($parentIds[0])) {
106
- $configrable = true;
107
- }
108
- }
109
  if (isset($parentIds[0])) {
110
- $parent_id = Mage::getModel('catalog/product')->load($parentIds[0])->getId();
111
  }
112
  }
113
-
114
- $product_result['parent_id'] = $parent_id;
115
-
116
- foreach ($product->getAttributes() as $attribute) {
117
- if (!array_key_exists($attribute->getAttributeCode(), $this->_notNeededFields())) {
118
- $value = $product->getData($attribute->getAttributeCode());
119
- if (!empty($value)) {
120
- if (in_array($attribute->getAttributeCode(), $price_keys)) {
121
- $value = sprintf("%.2f", round(trim($attribute->getFrontend()->getValue($product)), 2));
122
- } else {
123
- $value = trim($attribute->getFrontend()->getValue($product));
124
- }
 
 
 
125
  }
126
- $product_result[$attribute->getAttributeCode()] = $value;
127
  }
 
128
  }
129
-
130
- $product = Mage::getModel('catalog/product')->load($product->getId());
131
- // $imageUrl = $product->getImage();
132
- // if(empty($imageUrl)) {
133
- // $product = Mage::getModel('catalog/product')->load($product->getId());
134
- // $imageUrl = $product->getImage();
135
- // }
136
- //
 
137
  // if(empty($imageUrl) || $imageUrl == '') {
138
- // $imageUrl = $product->getMediaConfig()->getMediaUrl($product->getData('image'));
139
- // if(empty($imageUrl) || $imageUrl == '') {
140
- // $imageUrl = Mage::helper('catalog/image')->init($product, 'image');
141
- // }
142
- // } else {
143
- // $imageUrl = $imageBaseURL . $imageUrl;
144
- // }
145
- $imageUrl = (string)$product->getMediaConfig()->getMediaUrl($product->getData('image'));
146
- $imageTmpArr = explode('.', $imageUrl);
147
- $countImgArr = count($imageTmpArr);
148
- if(empty($imageUrl) || $imageUrl == '' || !isset($imageUrl) || $countImgArr < 2) {
149
- $imageUrl = (string) Mage::helper('catalog/image')->init($product, 'image');
150
- }
151
-
152
- $product_result['product_url'] = $baseUrl . $product->getUrlPath();
153
- $product_result['image_url'] = $imageUrl;
154
-
155
- $tmpPrices = array();
156
- if($parent_id && $configrable && $product->getVisibility() == 1) {
157
- $tmpPrices = $this->getDisplayPrice($parent_id);
158
-
159
- } else {
160
- $tmpPrices = $this->getDisplayPrice($product->getId());
161
- }
162
- if(count($tmpPrices)) {
163
- foreach($tmpPrices as $key=>$value) {
164
- $product_result[$key] = $value;
165
- }
166
- }
167
-
168
-
169
- $inventoryStatus = Mage::getModel(self::STOCK_ITEM_MODEL)->loadByProduct($product);
170
- if (!empty($inventoryStatus)) {
171
- $product_result['quantity'] = (int) $inventoryStatus->getQty();
172
- $product_result['is_in_stock'] = $inventoryStatus->getIsInStock() == '1' ? 1 : 0;
173
- }
174
-
175
-
176
-
177
- $result[] = $product_result;
178
  }
179
- return $result;
180
- }
181
-
182
- private function _loadCategories() {
183
- $parentId = 1;
184
-
185
- /* @var $tree Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Tree */
186
- $tree = Mage::getResourceSingleton('catalog/category_tree')->load();
187
- $root = $tree->getNodeById($parentId);
188
-
189
- if ($root && $root->getId() == 1) {
190
- $root->setName(Mage::helper('catalog')->__('Root'));
191
  }
192
-
193
- $collection = Mage::getModel('catalog/category')->getCollection()
194
- ->setStoreId($this->_getStoreId(null))
195
- ->addAttributeToSelect('name')
196
- ->addAttributeToSelect('is_active');
197
-
198
- $tree->addCollectionData($collection, true);
199
-
200
- return $this->_nodeToArray($root);
201
- }
202
-
203
- /**
204
- * Convert node to array
205
- *
206
- * @param Varien_Data_Tree_Node $node
207
- * @return array
208
- */
209
- private function _nodeToArray(Varien_Data_Tree_Node $node) {
210
- $children = $node->getChildren();
211
- if (!empty($children)) {
212
- foreach ($children as $child) {
213
- $this->_nodeToArray($child);
214
  }
215
  }
216
-
217
- $this->categories[$node->getId()] = array(
218
- 'category_id' => $node->getId(),
219
- 'parent_id' => $node->getParentId(),
220
- 'name' => $node->getName(),
221
- 'is_active' => $node->getIsActive()
222
- );
223
- }
224
-
225
- private function _buildCategoryPath($category_id, &$path = array()) {
226
- $category = $this->categories[$category_id];
227
-
228
- if ($category['parent_id'] != '0') {
229
- $this->_buildCategoryPath($category['parent_id'], $path);
230
- }
231
-
232
- if ($category['is_active'] == '1') {
233
- $path[] = $category['name'];
234
  }
235
-
236
- return $path;
 
 
237
  }
238
-
239
- private function _notNeededFields() {
240
- return array(
241
- 'type' => 0,
242
- 'type_id' => 0,
243
- 'set' => 0,
244
- 'categories' => 0,
245
- 'websites' => 0,
246
- 'old_id' => 0,
247
- 'news_from_date' => 0,
248
- 'news_to_date' => 0,
249
- 'category_ids' => 0,
250
- 'required_options' => 0,
251
- 'has_options' => 0,
252
- 'image_label' => 0,
253
- 'small_image_label' => 0,
254
- 'thumbnail_label' => 0,
255
- 'created_at' => 0,
256
- 'updated_at' => 0,
257
- 'group_price' => 0,
258
- 'tier_price' => 0,
259
- 'msrp_enabled' => 0,
260
- 'minimal_price' => 0,
261
- 'msrp_display_actual_price_type' => 0,
262
- 'msrp' => 0,
263
- 'enable_googlecheckout' => 0,
264
- 'is_recurring' => 0,
265
- 'recurring_profile' => 0,
266
- 'custom_design' => 0,
267
- 'custom_design_from' => 0,
268
- 'custom_design_to' => 0,
269
- 'custom_layout_update' => 0,
270
- 'page_layout' => 0,
271
- 'options_container' => 0,
272
- 'gift_message_available' => 0,
273
- 'url_key' => 0,
274
- 'url_path' => 0,
275
- 'conopy_diameter' => 0,
276
- 'image' => 0,
277
- 'small_image' => 0,
278
- 'thumbnail' => 0,
279
- 'media_gallery' => 0,
280
- 'gallery' => 0,
281
- 'entity_type_id' => 0,
282
- 'attribute_set_id' => 0,
283
- 'entity_id' => 0
284
- );
285
  }
286
-
287
- private function getDisplayPrice($product_id = 0) {
288
-
289
- if ($product_id < 1) {
290
- return 0;
291
- }
292
- $prices = array();
293
-
294
- $product = Mage::getModel('catalog/product')->load($product_id);
295
- $store_code = Mage::app()->getStore()->getCode();
296
- $_taxHelper = Mage::helper('tax');
297
- // Get Currency Code
298
- $bas_curncy_code = Mage::app()->getStore()->getBaseCurrencyCode();
299
- $cur_curncy_code = Mage::app()->getStore($store_code)->getCurrentCurrencyCode();
300
-
301
- $allowedCurrencies = Mage::getModel('directory/currency')
302
- ->getConfigAllowCurrencies();
303
- $currencyRates = Mage::getModel('directory/currency')
304
- ->getCurrencyRates($bas_curncy_code, array_values($allowedCurrencies));
305
-
306
- $prices['price_with_tax'] = $_finalPriceInclTax = $_taxHelper->getPrice($product, $product->getPrice(), 2);//$product['price'];
307
- $prices['price'] = $_taxHelper->getPrice($product, $product->getPrice(), NULL);
308
- $prices['special_price'] = 0;
309
- $prices['special_price_with_tax'] = 0;
310
- $prices['special_from_date'] = '';
311
- $prices['special_to_date'] = '';
312
-
313
- $prices['description'] = $product->getDescription();
314
- $prices['short_description'] = $product->getShortDescription();
315
-
316
- $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
317
- $prices['product_url'] = $baseUrl . $product->getUrlPath();
318
- //Setting image
319
- $imageUrl = (string)$product->getMediaConfig()->getMediaUrl($product->getData('image'));
320
- $imageTmpArr = explode('.', $imageUrl);
321
- $countImgArr = count($imageTmpArr);
322
- if(empty($imageUrl) || $imageUrl == '' || !isset($imageUrl) || $countImgArr < 2) {
323
- $imageUrl = (string) Mage::helper('catalog/image')->init($product, 'image');
324
- }
325
-
326
- $prices['image_url'] = $imageUrl;
327
-
328
- $specialTmpPrice = $product->getSpecialPrice();
329
-
330
- if ($specialTmpPrice && (strtotime(date('Y-m-d H:i:s')) < strtotime($product['special_to_date'])
331
- || empty($product['special_to_date']))) {
332
- $prices['special_price'] = $_taxHelper->getPrice($product, $product->getSpecialPrice(), NULL);
333
- $prices['special_price_with_tax'] = $_taxHelper->getPrice($product, $product->getSpecialPrice(), 2);
334
- $prices['special_from_date'] = $product['special_from_date'];
335
- $prices['special_to_date'] = $product['special_to_date'];
336
- //round($product->getSpecialPrice(), 2);
337
  }
338
-
339
- if ($bas_curncy_code != $cur_curncy_code
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
340
  && array_key_exists($bas_curncy_code, $currencyRates)
341
  && array_key_exists($cur_curncy_code, $currencyRates)
342
- ) {
343
- if ($prices['special_price'] && (strtotime(date('Y-m-d H:i:s')) < strtotime($product['special_to_date'])
344
- || empty($product['special_to_date']))) {
345
- $prices['special_price_with_tax'] = Mage::helper('directory')->currencyConvert($prices['special_price_with_tax'], $bas_curncy_code, $cur_curncy_code);
346
- $prices['special_price'] = Mage::helper('directory')->currencyConvert($prices['special_price'], $bas_curncy_code, $cur_curncy_code);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
347
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
348
 
349
- $prices['price_with_tax'] = Mage::helper('directory')->currencyConvert($_finalPriceInclTax, $bas_curncy_code, $cur_curncy_code);
350
- $prices['price'] = Mage::helper('directory')->currencyConvert($prices['price'], $bas_curncy_code, $cur_curncy_code);
 
 
 
 
 
 
351
  }
352
 
353
- // categories
354
- $category_id = $product->getCategoryIds();
355
- if (empty($category_id)) {
356
- $prices['category_name'] = '';
357
- $prices['category_parent_name'] = '';
358
- $prices['category_path'] = '';
359
- } else {
360
- rsort($category_id);
361
- $category = $this->categories[$category_id[0]];
362
- $prices['category_name'] = $category['name'];
363
- $prices['category_parent_name'] = $this->categories[$category['parent_id']]['name'];
364
- $prices['category_path'] = implode(' > ', $this->_buildCategoryPath($category['category_id']));
365
- }
366
-
367
- return $prices;
368
  }
369
-
370
-
371
-
372
-
373
-
374
  }
 
 
1
  <?php
2
+
3
+ class DataFeedWatch_Connector_Model_Datafeedwatch_Api extends Mage_Catalog_Model_Product_Api {
4
+
5
+ const STOCK_ITEM_MODEL = 'cataloginventory/stock_item';
6
+ const CATALOG_PRODUCT_MODEL = 'catalog/product';
7
+
8
+ // category
9
+ const CATALOG_CATEGORY_MODEL = 'catalog/category';
10
+ const CATEGORY_NAME_FIELD = 'name';
11
+ const CATEGORY_SEPARATOR = ' > ';
12
+ public $categories = array();
13
 
14
+ public function __construct() {
15
+ $this->productCategories = array();
16
+ ini_set('memory_limit', '1024M');
17
+ }
18
+
19
+ public function version() {
20
+ return "0.2.5"; // this needs to be updated in etc/config.xml as well
21
+ }
22
+
23
+ public function product_count($options = array()) {
24
+ $collection = Mage::getModel(self::CATALOG_PRODUCT_MODEL)
25
+ ->getCollection();
26
+
27
+ if (array_key_exists('store', $options)) {
28
+ $collection->addStoreFilter($this->_getStoreId($options['store']));
 
 
29
  }
30
+
31
+ $apiHelper = Mage::helper('api');
32
+ $filters = $apiHelper->parseFilters($options, $this->_filtersMap);
33
+ try {
34
+ foreach ($filters as $field => $value) {
35
+ $collection->addFieldToFilter($field, $value);
 
 
 
 
 
 
 
 
 
 
 
36
  }
37
+ } catch (Mage_Core_Exception $e) {
38
+ $this->_fault('filters_invalid', $e->getMessage());
 
 
 
 
 
39
  }
40
+
41
+ $numberOfProducts = 0;
42
+ if (!empty($collection)) {
43
+ $numberOfProducts = $collection->getSize();
44
+ }
45
+
46
+ return round($numberOfProducts);
47
+ }
48
+
49
+ public function products($options = array()) {
50
+
51
+ if (!array_key_exists('page', $options)) {
52
+ $options['page'] = 1;
53
+ }
54
+
55
+ if (!array_key_exists('per_page', $options)) {
56
+ $options['per_page'] = 100;
57
+ }
58
+
59
+ $collection = Mage::getModel(self::CATALOG_PRODUCT_MODEL)
60
+ ->getCollection()
61
+ ->addAttributeToSelect('*')
62
+ ->setPage($options['page'], $options['per_page']);
63
+
64
+ if (array_key_exists('store', $options)) {
65
+ $collection->addStoreFilter($this->_getStoreId($options['store']));
66
+ }
67
+
68
+ // clear options that are not filters
69
+ unset($options['page']);
70
+ unset($options['per_page']);
71
+ unset($options['store']);
72
+
73
+ $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
74
+ $imageBaseURL = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . self::CATALOG_PRODUCT_MODEL;
75
+
76
+ $this->_loadCategories();
77
+
78
+ /** @var $apiHelper Mage_Api_Helper_Data */
79
+ $apiHelper = Mage::helper('api');
80
+ $filters = $apiHelper->parseFilters($options, $this->_filtersMap);
81
+ try {
82
+ foreach ($filters as $field => $value) {
83
+ $collection->addFieldToFilter($field, $value);
84
  }
85
+ } catch (Mage_Core_Exception $e) {
86
+ $this->_fault('filters_invalid', $e->getMessage());
87
+ }
88
+
89
+ $result = array();
90
+ $product_cache = array();
91
+ $price_keys = array('price', 'special_price');
92
+
93
+ foreach ($collection as $product) {
94
+ $product_result = array(// Basic product data
95
+ 'product_id' => $product->getId(),
96
+ 'sku' => $product->getSku()
97
+ );
98
+
99
+ $parent_id = '0';
100
+ $configrable = false;
101
+
102
+ if ($product->getTypeId() == "simple") {
103
+ $parentIds = Mage::getModel('catalog/product_type_grouped')->getParentIdsByChild($product->getId());
104
+ if (!$parentIds) {
105
+ $parentIds = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($product->getId());
 
106
  if (isset($parentIds[0])) {
107
+ $configrable = true;
108
  }
109
  }
110
+ if (isset($parentIds[0])) {
111
+ $parent_id = Mage::getModel('catalog/product')->load($parentIds[0])->getId();
112
+ }
113
+ }
114
+
115
+ $product_result['parent_id'] = $parent_id;
116
+
117
+ foreach ($product->getAttributes() as $attribute) {
118
+ if (!array_key_exists($attribute->getAttributeCode(), $this->_notNeededFields())) {
119
+ $value = $product->getData($attribute->getAttributeCode());
120
+ if (!empty($value)) {
121
+ if (in_array($attribute->getAttributeCode(), $price_keys)) {
122
+ $value = sprintf("%.2f", round(trim($attribute->getFrontend()->getValue($product)), 2));
123
+ } else {
124
+ $value = trim($attribute->getFrontend()->getValue($product));
125
  }
 
126
  }
127
+ $product_result[$attribute->getAttributeCode()] = $value;
128
  }
129
+ }
130
+
131
+ $product = Mage::getModel('catalog/product')->load($product->getId());
132
+ // $imageUrl = $product->getImage();
133
+ // if(empty($imageUrl)) {
134
+ // $product = Mage::getModel('catalog/product')->load($product->getId());
135
+ // $imageUrl = $product->getImage();
136
+ // }
137
+ //
138
  // if(empty($imageUrl) || $imageUrl == '') {
139
+ // $imageUrl = $product->getMediaConfig()->getMediaUrl($product->getData('image'));
140
+ // if(empty($imageUrl) || $imageUrl == '') {
141
+ // $imageUrl = Mage::helper('catalog/image')->init($product, 'image');
142
+ // }
143
+ // } else {
144
+ // $imageUrl = $imageBaseURL . $imageUrl;
145
+ // }
146
+ $imageUrl = (string) $product->getMediaConfig()->getMediaUrl($product->getData('image'));
147
+ $imageTmpArr = explode('.', $imageUrl);
148
+ $countImgArr = count($imageTmpArr);
149
+ if (empty($imageUrl) || $imageUrl == '' || !isset($imageUrl) || $countImgArr < 2) {
150
+ $imageUrl = (string) Mage::helper('catalog/image')->init($product, 'image');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
151
  }
152
+
153
+ $product_result['product_url'] = $baseUrl . $product->getUrlPath();
154
+ $product_result['image_url'] = $imageUrl;
155
+
156
+ $tmpPrices = array();
157
+ if ($parent_id && $configrable && $product->getVisibility() == 1) {
158
+ $tmpPrices = $this->getDisplayPrice($parent_id);
159
+ } else {
160
+ $tmpPrices = $this->getDisplayPrice($product->getId());
 
 
 
161
  }
162
+ if (count($tmpPrices)) {
163
+ foreach ($tmpPrices as $key => $value) {
164
+ $product_result[$key] = $value;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165
  }
166
  }
167
+
168
+
169
+ $inventoryStatus = Mage::getModel(self::STOCK_ITEM_MODEL)->loadByProduct($product);
170
+ if (!empty($inventoryStatus)) {
171
+ $product_result['quantity'] = (int) $inventoryStatus->getQty();
172
+ $product_result['is_in_stock'] = $inventoryStatus->getIsInStock() == '1' ? 1 : 0;
 
 
 
 
 
 
 
 
 
 
 
 
173
  }
174
+
175
+
176
+
177
+ $result[] = $product_result;
178
  }
179
+ return $result;
180
+ }
181
+
182
+ private function _loadCategories() {
183
+ $parentId = 1;
184
+
185
+ /* @var $tree Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Tree */
186
+ $tree = Mage::getResourceSingleton('catalog/category_tree')->load();
187
+ $root = $tree->getNodeById($parentId);
188
+
189
+ if ($root && $root->getId() == 1) {
190
+ $root->setName(Mage::helper('catalog')->__('Root'));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
191
  }
192
+
193
+ $collection = Mage::getModel('catalog/category')->getCollection()
194
+ ->setStoreId($this->_getStoreId(null))
195
+ ->addAttributeToSelect('name')
196
+ ->addAttributeToSelect('is_active');
197
+
198
+ $tree->addCollectionData($collection, true);
199
+
200
+ return $this->_nodeToArray($root);
201
+ }
202
+
203
+ /**
204
+ * Convert node to array
205
+ *
206
+ * @param Varien_Data_Tree_Node $node
207
+ * @return array
208
+ */
209
+ private function _nodeToArray(Varien_Data_Tree_Node $node) {
210
+ $children = $node->getChildren();
211
+ if (!empty($children)) {
212
+ foreach ($children as $child) {
213
+ $this->_nodeToArray($child);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
214
  }
215
+ }
216
+
217
+ $this->categories[$node->getId()] = array(
218
+ 'category_id' => $node->getId(),
219
+ 'parent_id' => $node->getParentId(),
220
+ 'name' => $node->getName(),
221
+ 'is_active' => $node->getIsActive()
222
+ );
223
+ }
224
+
225
+ private function _buildCategoryPath($category_id, &$path = array()) {
226
+ $this->productCategories[] = $category_id;
227
+ $category = $this->categories[$category_id];
228
+
229
+ if ($category['parent_id'] != '0') {
230
+ $this->_buildCategoryPath($category['parent_id'], $path);
231
+ }
232
+
233
+ if ($category['is_active'] == '1') {
234
+ $path[] = $category['name'];
235
+ }
236
+
237
+ return $path;
238
+ }
239
+
240
+ private function _notNeededFields() {
241
+ return array(
242
+ 'type' => 0,
243
+ 'type_id' => 0,
244
+ 'set' => 0,
245
+ 'categories' => 0,
246
+ 'websites' => 0,
247
+ 'old_id' => 0,
248
+ 'news_from_date' => 0,
249
+ 'news_to_date' => 0,
250
+ 'category_ids' => 0,
251
+ 'required_options' => 0,
252
+ 'has_options' => 0,
253
+ 'image_label' => 0,
254
+ 'small_image_label' => 0,
255
+ 'thumbnail_label' => 0,
256
+ 'created_at' => 0,
257
+ 'updated_at' => 0,
258
+ 'group_price' => 0,
259
+ 'tier_price' => 0,
260
+ 'msrp_enabled' => 0,
261
+ 'minimal_price' => 0,
262
+ 'msrp_display_actual_price_type' => 0,
263
+ 'msrp' => 0,
264
+ 'enable_googlecheckout' => 0,
265
+ 'is_recurring' => 0,
266
+ 'recurring_profile' => 0,
267
+ 'custom_design' => 0,
268
+ 'custom_design_from' => 0,
269
+ 'custom_design_to' => 0,
270
+ 'custom_layout_update' => 0,
271
+ 'page_layout' => 0,
272
+ 'options_container' => 0,
273
+ 'gift_message_available' => 0,
274
+ 'url_key' => 0,
275
+ 'url_path' => 0,
276
+ 'image' => 0,
277
+ 'small_image' => 0,
278
+ 'thumbnail' => 0,
279
+ 'media_gallery' => 0,
280
+ 'gallery' => 0,
281
+ 'entity_type_id' => 0,
282
+ 'attribute_set_id' => 0,
283
+ 'entity_id' => 0
284
+ );
285
+ }
286
+
287
+ private function getDisplayPrice($product_id = 0) {
288
+
289
+ if ($product_id < 1) {
290
+ return 0;
291
+ }
292
+ $prices = array();
293
+
294
+ $product = Mage::getModel('catalog/product')->load($product_id);
295
+ $store_code = Mage::app()->getStore()->getCode();
296
+ $_taxHelper = Mage::helper('tax');
297
+ // Get Currency Code
298
+ $bas_curncy_code = Mage::app()->getStore()->getBaseCurrencyCode();
299
+ $cur_curncy_code = Mage::app()->getStore($store_code)->getCurrentCurrencyCode();
300
+
301
+ $allowedCurrencies = Mage::getModel('directory/currency')
302
+ ->getConfigAllowCurrencies();
303
+ $currencyRates = Mage::getModel('directory/currency')
304
+ ->getCurrencyRates($bas_curncy_code, array_values($allowedCurrencies));
305
+
306
+ $prices['price_with_tax'] = $_finalPriceInclTax = $_taxHelper->getPrice($product, $product->getPrice(), 2); //$product['price'];
307
+ $prices['price'] = $_taxHelper->getPrice($product, $product->getPrice(), NULL);
308
+ $prices['special_price'] = 0;
309
+ $prices['special_price_with_tax'] = 0;
310
+ $prices['special_from_date'] = '';
311
+ $prices['special_to_date'] = '';
312
+
313
+ $prices['description'] = $product->getDescription();
314
+ $prices['short_description'] = $product->getShortDescription();
315
+
316
+ $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
317
+ $prices['product_url'] = $baseUrl . $product->getUrlPath();
318
+ //Setting image
319
+ $imageUrl = (string) $product->getMediaConfig()->getMediaUrl($product->getData('image'));
320
+ $imageTmpArr = explode('.', $imageUrl);
321
+ $countImgArr = count($imageTmpArr);
322
+ if (empty($imageUrl) || $imageUrl == '' || !isset($imageUrl) || $countImgArr < 2) {
323
+ $imageUrl = (string) Mage::helper('catalog/image')->init($product, 'image');
324
+ }
325
+
326
+ $prices['image_url'] = $imageUrl;
327
+
328
+ $specialTmpPrice = $product->getSpecialPrice();
329
+
330
+ if ($specialTmpPrice && (strtotime(date('Y-m-d H:i:s')) < strtotime($product['special_to_date'])
331
+ || empty($product['special_to_date']))) {
332
+ $prices['special_price'] = $_taxHelper->getPrice($product, $product->getSpecialPrice(), NULL);
333
+ $prices['special_price_with_tax'] = $_taxHelper->getPrice($product, $product->getSpecialPrice(), 2);
334
+ $prices['special_from_date'] = $product['special_from_date'];
335
+ $prices['special_to_date'] = $product['special_to_date'];
336
+ //round($product->getSpecialPrice(), 2);
337
+ }
338
+
339
+ if ($bas_curncy_code != $cur_curncy_code
340
  && array_key_exists($bas_curncy_code, $currencyRates)
341
  && array_key_exists($cur_curncy_code, $currencyRates)
342
+ ) {
343
+ if ($prices['special_price'] && (strtotime(date('Y-m-d H:i:s')) < strtotime($product['special_to_date'])
344
+ || empty($product['special_to_date']))) {
345
+ $prices['special_price_with_tax'] = Mage::helper('directory')->currencyConvert($prices['special_price_with_tax'], $bas_curncy_code, $cur_curncy_code);
346
+ $prices['special_price'] = Mage::helper('directory')->currencyConvert($prices['special_price'], $bas_curncy_code, $cur_curncy_code);
347
+ }
348
+
349
+ $prices['price_with_tax'] = Mage::helper('directory')->currencyConvert($_finalPriceInclTax, $bas_curncy_code, $cur_curncy_code);
350
+ $prices['price'] = Mage::helper('directory')->currencyConvert($prices['price'], $bas_curncy_code, $cur_curncy_code);
351
+ }
352
+
353
+ // Getting Additional information
354
+ $attributes = $product->getAttributes();
355
+ //$attrs = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product);
356
+ foreach ($attributes as $attribute) {
357
+ if ($attribute->getIsUserDefined()) { //&& $attribute->getIsVisibleOnFront()
358
+ if (!array_key_exists($attribute->getAttributeCode(), $this->_notNeededFields())) {
359
+ $value = $product->getData($attribute->getAttributeCode());
360
+ if (!empty($value)) {
361
+ $value = trim($attribute->getFrontend()->getValue($product));
362
+ }
363
+ $prices[$attribute->getAttributeCode()] = $value;
364
  }
365
+ }
366
+ }
367
+
368
+ // categories
369
+ $category_id = $product->getCategoryIds();
370
+ if (empty($category_id)) {
371
+ $prices['category_name'] = '';
372
+ $prices['category_parent_name'] = '';
373
+ $prices['category_path'] = '';
374
+ } else {
375
+ rsort($category_id);
376
+ $this->productCategories = array();
377
+ $index = '';
378
+ foreach ($category_id as $key => $cate) {
379
+ // if(in_array($cate, $this->productCategories))
380
+ // continue;
381
 
382
+ $category = $this->categories[$cate];
383
+ $prices['category_name'.$index] = $category['name'];
384
+ $prices['category_parent_name'.$index] = $this->categories[$category['parent_id']]['name'];
385
+ $prices['category_path'.$index] = implode(' > ', $this->_buildCategoryPath($category['category_id']));
386
+ if($index == '')
387
+ $index = 1;
388
+ else
389
+ $index = $index+1;
390
  }
391
 
392
+ // $category = $this->categories[$category_id[0]];
393
+ // $prices['category_name'] = $category['name'];
394
+ // $prices['category_parent_name'] = $this->categories[$category['parent_id']]['name'];
395
+ // $prices['category_path'] = implode(' > ', $this->_buildCategoryPath($category['category_id']));
 
 
 
 
 
 
 
 
 
 
 
396
  }
397
+
398
+ return $prices;
 
 
 
399
  }
400
+
401
+ }
app/code/local/DataFeedWatch/Connector/controllers/TestController.php CHANGED
@@ -1,28 +1,34 @@
1
  <?php
 
2
  class DataFeedWatch_Connector_TestController extends Mage_Core_Controller_Front_Action {
3
-
4
  public function indexAction() {
5
-
6
  $this->loadLayout();
7
- $this->_title($this->__("DataFeedWatch"));
8
- $this->renderLayout();
9
-
10
  $collection = Mage::getModel('catalog/product')
11
- ->getCollection()
12
- ->addAttributeToSelect('*')
13
- ->setPage(1, 20);
14
- foreach($collection as $product)
15
- {
16
- echo '<pre>'; print_r($product);
17
- echo 'And images are <br>';
18
- $imageUrl = $product->getImage();
19
- print_r($imageUrl);
20
- echo '<br> second';
21
- $imageUrl = $product->getMediaConfig()->getMediaUrl($product->getData('image'));
22
- print_r($imageUrl);
23
- }
24
- die('nothing found');
25
- }
 
 
 
 
 
 
26
 
27
-
28
  }
1
  <?php
2
+
3
  class DataFeedWatch_Connector_TestController extends Mage_Core_Controller_Front_Action {
4
+
5
  public function indexAction() {
6
+
7
  $this->loadLayout();
8
+ $this->_title($this->__("DataFeedWatch"));
9
+ $this->renderLayout();
10
+
11
  $collection = Mage::getModel('catalog/product')
12
+ ->getCollection()
13
+ ->addAttributeToSelect('*')
14
+ ->setPage(1, 20);
15
+ $productsAtts = array();
16
+ foreach ($collection as $product) {
17
+ $attributes = $product->getAttributes();
18
+ //$attrs = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product);
19
+ foreach ($attributes as $attribute) {
20
+ if ($attribute->getIsUserDefined()) { //&& $attribute->getIsUserDefined()
21
+ $value = $product->getData($attribute->getAttributeCode());
22
+ if (!empty($value)) {
23
+ $value = trim($attribute->getFrontend()->getValue($product));
24
+ }
25
+ $productsAtts[$product->getId()][$attribute->getAttributeCode()] = $value;
26
+ }
27
+ }
28
+ }
29
+ echo '<pre>';
30
+ print_r($productsAtts);
31
+ die('nothing found');
32
+ }
33
 
 
34
  }
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>DataFeedWatch_Connector</name>
4
- <version>0.2.4</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
  <channel>community</channel>
@@ -9,11 +9,11 @@
9
  <summary>DataFeedWatch extension for Magento</summary>
10
  <description>DataFeedWatch enables Magento shops to optimize their product data&#xD;
11
  feed for Google Shopping and other channels</description>
12
- <notes>DataFeedWatch Release version 0.2.4</notes>
13
  <authors><author><name>DataFeedWatch</name><user>Adeel</user><email>adeel.developer@gmail.com</email></author></authors>
14
- <date>2013-11-22</date>
15
- <time>14:05:26</time>
16
- <contents><target name="magelocal"><dir name="DataFeedWatch"><dir name="Connector"><dir name="Block"><dir name="Adminhtml"><file name="Connectorbackend.php" hash="afe5bd4888768229d5b668f466b770b5"/></dir></dir><dir name="Helper"><file name="Data.php" hash="983d7ad023616b365dce180680e4f9f0"/></dir><dir name="Model"><dir name="Datafeedwatch"><file name="Api.php" hash="e4138a980915ec189094c63b01af3b15"/></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="ConnectorbackendController.php" hash="dfa561302ef7eebe656b229fe275a2eb"/></dir><file name="TestController.php" hash="0eebed552b28b181ae167bb59b8f9a72"/></dir><dir name="etc"><file name="api.xml" hash="84e8b97ba0dc25154ff62126640de989"/><file name="config.xml" hash="a48f183854af578bfc8dfeb3f1648617"/><file name="system.xml" hash="ab5e8d56d032ba69c930ab7879484212"/></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="connector.xml" hash="14d59b8e9f66fba5d7c1f8d0f62dfc3c"/></dir><dir name="template"><dir name="connector"><file name="connectorbackend.phtml" hash="87fbcd16a96af52ce352bc45d9aeab4a"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="DataFeedWatch_Connector.xml" hash="d4ef6cebcefd37d5f0546eca344941eb"/></dir></target></contents>
17
  <compatible/>
18
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
19
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>DataFeedWatch_Connector</name>
4
+ <version>0.2.5</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
  <channel>community</channel>
9
  <summary>DataFeedWatch extension for Magento</summary>
10
  <description>DataFeedWatch enables Magento shops to optimize their product data&#xD;
11
  feed for Google Shopping and other channels</description>
12
+ <notes>DataFeedWatch Release version 0.2.5</notes>
13
  <authors><author><name>DataFeedWatch</name><user>Adeel</user><email>adeel.developer@gmail.com</email></author></authors>
14
+ <date>2013-12-10</date>
15
+ <time>15:04:35</time>
16
+ <contents><target name="magelocal"><dir name="DataFeedWatch"><dir name="Connector"><dir name="Block"><dir name="Adminhtml"><file name="Connectorbackend.php" hash="afe5bd4888768229d5b668f466b770b5"/></dir></dir><dir name="Helper"><file name="Data.php" hash="983d7ad023616b365dce180680e4f9f0"/></dir><dir name="Model"><dir name="Datafeedwatch"><file name="Api.php" hash="d69c88b5cbe3ec18e7ab1ca69dea94d3"/></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="ConnectorbackendController.php" hash="dfa561302ef7eebe656b229fe275a2eb"/></dir><file name="TestController.php" hash="c90345d01f53e2a6c84eb29083c4263c"/></dir><dir name="etc"><file name="api.xml" hash="84e8b97ba0dc25154ff62126640de989"/><file name="config.xml" hash="a48f183854af578bfc8dfeb3f1648617"/><file name="system.xml" hash="ab5e8d56d032ba69c930ab7879484212"/></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="connector.xml" hash="14d59b8e9f66fba5d7c1f8d0f62dfc3c"/></dir><dir name="template"><dir name="connector"><file name="connectorbackend.phtml" hash="87fbcd16a96af52ce352bc45d9aeab4a"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="DataFeedWatch_Connector.xml" hash="d4ef6cebcefd37d5f0546eca344941eb"/></dir></target></contents>
17
  <compatible/>
18
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
19
  </package>