DataFeedWatch_Connector - Version 0.2.0

Version Notes

DataFeedWatch

Download this release

Release Info

Developer DataFeedWatch
Extension DataFeedWatch_Connector
Version 0.2.0
Comparing to
See all releases


Code changes from version 0.1.3 to 0.2.0

app/code/local/DataFeedWatch/Connector/Model/Datafeedwatch/Api.php ADDED
@@ -0,0 +1,269 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ {
15
+ $this->categories = array();
16
+ }
17
+
18
+ public function version()
19
+ {
20
+ return "0.2.0"; // this needs to be updated in etc/config.xml as well
21
+ }
22
+
23
+ public function product_count($options = array())
24
+ {
25
+ $collection = Mage::getModel(self::CATALOG_PRODUCT_MODEL)
26
+ ->getCollection();
27
+
28
+ if (array_key_exists('store', $options)) {
29
+ $collection->addStoreFilter($this->_getStoreId($options['store']));
30
+ }
31
+
32
+ $apiHelper = Mage::helper('api');
33
+ $filters = $apiHelper->parseFilters($options, $this->_filtersMap);
34
+ try {
35
+ foreach ($filters as $field => $value) {
36
+ $collection->addFieldToFilter($field, $value);
37
+ }
38
+ } catch (Mage_Core_Exception $e) {
39
+ $this->_fault('filters_invalid', $e->getMessage());
40
+ }
41
+
42
+ $numberOfProducts = 0;
43
+ if(!empty($collection)) {
44
+ $numberOfProducts = $collection->getSize();
45
+ }
46
+
47
+ return $numberOfProducts;
48
+ }
49
+
50
+ public function products($options = array())
51
+ {
52
+
53
+ if (!array_key_exists('page', $options)) {
54
+ $options['page'] = 1;
55
+ }
56
+
57
+ if (!array_key_exists('per_page', $options)) {
58
+ $options['per_page'] = 100;
59
+ }
60
+
61
+ $collection = Mage::getModel(self::CATALOG_PRODUCT_MODEL)
62
+ ->getCollection()
63
+ ->addAttributeToSelect('*')
64
+ ->setPage($options['page'],$options['per_page']);
65
+
66
+ if (array_key_exists('store', $options)) {
67
+ $collection->addStoreFilter($this->_getStoreId($options['store']));
68
+ }
69
+
70
+ // clear options that are not filters
71
+ unset($options['page']);
72
+ unset($options['per_page']);
73
+ unset($options['store']);
74
+
75
+ $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
76
+ $imageBaseURL = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).self::CATALOG_PRODUCT_MODEL;
77
+
78
+ $this->_loadCategories();
79
+
80
+ /** @var $apiHelper Mage_Api_Helper_Data */
81
+ $apiHelper = Mage::helper('api');
82
+ $filters = $apiHelper->parseFilters($options, $this->_filtersMap);
83
+ try {
84
+ foreach ($filters as $field => $value) {
85
+ $collection->addFieldToFilter($field, $value);
86
+ }
87
+ } catch (Mage_Core_Exception $e) {
88
+ $this->_fault('filters_invalid', $e->getMessage());
89
+ }
90
+
91
+ $result = array();
92
+ $product_cache = array();
93
+ $price_keys = array('price','special_price');
94
+
95
+ foreach ($collection as $product) {
96
+ $product_result = array( // Basic product data
97
+ 'product_id' => $product->getId(),
98
+ 'sku' => $product->getSku()
99
+ );
100
+
101
+ $parent_id = '0';
102
+
103
+ if ($product->getTypeId() == "simple") {
104
+ $parentIds = Mage::getModel('catalog/product_type_grouped')->getParentIdsByChild($product->getId());
105
+ if (!$parentIds) {
106
+ $parentIds = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($product->getId());
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
+ $inventoryStatus = Mage::getModel(self::STOCK_ITEM_MODEL)->loadByProduct($product);
133
+ if (!empty($inventoryStatus)) {
134
+ $product_result['quantity'] = (int)$inventoryStatus->getQty();
135
+ $product_result['is_in_stock'] = $inventoryStatus->getIsInStock() == '1' ? 1 : 0;
136
+ }
137
+
138
+ // categories
139
+ $category_id = $product->getCategoryIds();
140
+ if (empty($category_id))
141
+ {
142
+ $product_result['category_name'] = '';
143
+ $product_result['category_parent_name'] = '';
144
+ $product_result['category_path'] = '';
145
+ } else {
146
+ $category = $this->categories[$category_id[0]];
147
+ $product_result['category_name'] = $category['name'];
148
+ $product_result['category_parent_name'] = $this->categories[$category['parent_id']]['name'];
149
+ $product_result['category_path'] = implode(' > ', $this->_buildCategoryPath($category['category_id']));
150
+ }
151
+
152
+ $result[] = $product_result;
153
+ }
154
+ return $result;
155
+ }
156
+
157
+ private function _loadCategories()
158
+ {
159
+ $parentId = 1;
160
+
161
+ /* @var $tree Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Tree */
162
+ $tree = Mage::getResourceSingleton('catalog/category_tree')->load();
163
+ $root = $tree->getNodeById($parentId);
164
+
165
+ if($root && $root->getId() == 1) {
166
+ $root->setName(Mage::helper('catalog')->__('Root'));
167
+ }
168
+
169
+ $collection = Mage::getModel('catalog/category')->getCollection()
170
+ ->setStoreId($this->_getStoreId(null))
171
+ ->addAttributeToSelect('name')
172
+ ->addAttributeToSelect('is_active');
173
+
174
+ $tree->addCollectionData($collection, true);
175
+
176
+ return $this->_nodeToArray($root);
177
+ }
178
+
179
+ /**
180
+ * Convert node to array
181
+ *
182
+ * @param Varien_Data_Tree_Node $node
183
+ * @return array
184
+ */
185
+ private function _nodeToArray(Varien_Data_Tree_Node $node)
186
+ {
187
+ $children = $node->getChildren();
188
+ if (!empty($children))
189
+ {
190
+ foreach ($children as $child)
191
+ {
192
+ $this->_nodeToArray($child);
193
+ }
194
+ }
195
+
196
+ $this->categories[$node->getId()] = array(
197
+ 'category_id' => $node->getId(),
198
+ 'parent_id' => $node->getParentId(),
199
+ 'name' => $node->getName(),
200
+ 'is_active' => $node->getIsActive()
201
+ );
202
+ }
203
+
204
+ private function _buildCategoryPath($category_id, &$path = array())
205
+ {
206
+ $category = $this->categories[$category_id];
207
+
208
+ if ($category['parent_id'] != '0')
209
+ {
210
+ $this->_buildCategoryPath($category['parent_id'], $path);
211
+ }
212
+
213
+ if ($category['is_active'] == '1')
214
+ {
215
+ $path[] = $category['name'];
216
+ }
217
+
218
+ return $path;
219
+ }
220
+
221
+ private function _notNeededFields()
222
+ {
223
+ return array(
224
+ 'type' => 0,
225
+ 'type_id' => 0,
226
+ 'set' => 0,
227
+ 'categories' => 0,
228
+ 'websites' => 0,
229
+ 'old_id' => 0,
230
+ 'news_from_date' => 0,
231
+ 'news_to_date' => 0,
232
+ 'category_ids' => 0,
233
+ 'required_options' => 0,
234
+ 'has_options' => 0,
235
+ 'image_label' => 0,
236
+ 'small_image_label' => 0,
237
+ 'thumbnail_label' => 0,
238
+ 'created_at' => 0,
239
+ 'updated_at' => 0,
240
+ 'group_price' => 0,
241
+ 'tier_price' => 0,
242
+ 'msrp_enabled' => 0,
243
+ 'minimal_price' => 0,
244
+ 'msrp_display_actual_price_type' => 0,
245
+ 'msrp' => 0,
246
+ 'enable_googlecheckout' => 0,
247
+ 'is_recurring' => 0,
248
+ 'recurring_profile' => 0,
249
+ 'custom_design' => 0,
250
+ 'custom_design_from' => 0,
251
+ 'custom_design_to' => 0,
252
+ 'custom_layout_update' => 0,
253
+ 'page_layout' => 0,
254
+ 'options_container' => 0,
255
+ 'gift_message_available' => 0,
256
+ 'url_key' => 0,
257
+ 'url_path' => 0,
258
+ 'conopy_diameter' => 0,
259
+ 'image' => 0,
260
+ 'small_image' => 0,
261
+ 'thumbnail' => 0,
262
+ 'media_gallery' => 0,
263
+ 'gallery' => 0,
264
+ 'entity_type_id' => 0,
265
+ 'attribute_set_id' => 0,
266
+ 'entity_id' => 0
267
+ );
268
+ }
269
+ }
app/code/local/DataFeedWatch/Connector/etc/api.xml ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <api>
4
+ <resources>
5
+ <datafeedwatch translate="title" module="connector">
6
+ <title>DataFeedWatch API</title>
7
+ <model>connector/datafeedwatch_api</model>
8
+ <methods>
9
+ <version translate="title" module="connector">
10
+ <title>Retrieve extension version</title>
11
+ </version>
12
+ <products translate="title" module="connector">
13
+ <title>Retrieve products</title>
14
+ </products>
15
+ <product_count translate="title" module="connector">
16
+ <title>Retrieve product count</title>
17
+ </product_count>
18
+ </methods>
19
+ </datafeedwatch>
20
+ </resources>
21
+
22
+ <!--<resources_alias>-->
23
+ <!--<product>catalog_product</product>-->
24
+ <!--</resources_alias>-->
25
+ </api>
26
+ </config>
app/code/local/DataFeedWatch/Connector/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <DataFeedWatch_Connector>
5
- <version>0.1.0</version>
6
  </DataFeedWatch_Connector>
7
  </modules>
8
  <admin>
@@ -49,6 +49,11 @@
49
  </layout>
50
  </adminhtml>
51
  <global>
 
 
 
 
 
52
  <helpers>
53
  <connector>
54
  <class>DataFeedWatch_Connector_Helper</class>
2
  <config>
3
  <modules>
4
  <DataFeedWatch_Connector>
5
+ <version>0.2.0</version>
6
  </DataFeedWatch_Connector>
7
  </modules>
8
  <admin>
49
  </layout>
50
  </adminhtml>
51
  <global>
52
+ <models>
53
+ <connector>
54
+ <class>DataFeedWatch_Connector_Model</class>
55
+ </connector>
56
+ </models>
57
  <helpers>
58
  <connector>
59
  <class>DataFeedWatch_Connector_Helper</class>
app/etc/modules/DataFeedWatch_Connector.xml CHANGED
@@ -4,6 +4,9 @@
4
  <DataFeedWatch_Connector>
5
  <active>true</active>
6
  <codePool>local</codePool>
 
 
 
7
  </DataFeedWatch_Connector>
8
  </modules>
9
  </config>
4
  <DataFeedWatch_Connector>
5
  <active>true</active>
6
  <codePool>local</codePool>
7
+ <depends>
8
+ <Mage_Api />
9
+ </depends>
10
  </DataFeedWatch_Connector>
11
  </modules>
12
  </config>
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>DataFeedWatch_Connector</name>
4
- <version>0.1.3</version>
5
  <stability>stable</stability>
6
  <license>GPL</license>
7
  <channel>community</channel>
@@ -10,9 +10,9 @@
10
  <description>DataFeedWatch</description>
11
  <notes>DataFeedWatch</notes>
12
  <authors><author><name>DataFeedWatch</name><user>datafeedwatch</user><email>support@datafeedwatch.com</email></author></authors>
13
- <date>2013-03-01</date>
14
- <time>14:11:17</time>
15
- <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="controllers"><dir name="Adminhtml"><file name="ConnectorbackendController.php" hash="dfa561302ef7eebe656b229fe275a2eb"/></dir></dir><dir name="etc"><file name="config.xml" hash="d0acf798ce2cca1669a54db93ee207d6"/><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="a8d7c5380f228369550b2b0db81bd82a"/></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
18
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>DataFeedWatch_Connector</name>
4
+ <version>0.2.0</version>
5
  <stability>stable</stability>
6
  <license>GPL</license>
7
  <channel>community</channel>
10
  <description>DataFeedWatch</description>
11
  <notes>DataFeedWatch</notes>
12
  <authors><author><name>DataFeedWatch</name><user>datafeedwatch</user><email>support@datafeedwatch.com</email></author></authors>
13
+ <date>2013-06-24</date>
14
+ <time>13:29:54</time>
15
+ <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="a92704c2770feee615fcc753420d4cd7"/></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="8269604fff1d5e0923039d08f4bf101e"/><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>
16
  <compatible/>
17
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
18
  </package>