DataFeedWatch_Connector - Version 0.2.2

Version Notes

DataFeedWatch Release version 0.2.2

Download this release

Release Info

Developer DataFeedWatch
Extension DataFeedWatch_Connector
Version 0.2.2
Comparing to
See all releases


Code changes from version 0.2.1 to 0.2.2

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