GoDataFeed - Version 1.0.0

Version Notes

No Notes

Download this release

Release Info

Developer Magento Core Team
Extension GoDataFeed
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/local/GoDataFeed/Services/Model/Catalog/Product/Api.php ADDED
@@ -0,0 +1,324 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class GoDataFeed_Services_Model_Catalog_Product_Api extends Mage_Catalog_Model_Product_Api
4
+ {
5
+ const STOCK_ITEM_MODEL = 'cataloginventory/stock_item';
6
+ const ATTRIBUTE_SET_MODEL = 'eav/entity_attribute_set';
7
+ const CATALOG_PRODUCT_MODEL = 'catalog/product';
8
+ const CATALOG_CATEGORY_MODEL = 'catalog/category';
9
+ const CONFIGURABLE_PRODUCT_MODEL = "catalog/product_type_configurable";
10
+ const GROUPED_PRODUCT_MODEL = "catalog/product_type_grouped";
11
+
12
+ const PRODUCT_NAME_FIELD = 'name';
13
+ const DESCRIPTION_FIELD = 'description';
14
+ const SHORT_DESCRIPTION_FIELD = 'short_description';
15
+ const CATEGORY_NAME_FIELD = 'name';
16
+
17
+ const CATEGORY_SEPARATOR = ' > ';
18
+
19
+ public function count($filters, $stockQuantityFilterAmount, $store, $responseField)
20
+ {
21
+ $filteredProductsCollection = $this->getProductsFilteredByStockQuantity($filters, $stockQuantityFilterAmount, $store);
22
+
23
+ $numberOfProducts = 0;
24
+ if(!empty($filteredProductsCollection)) {
25
+ $numberOfProducts = $filteredProductsCollection->getSize();
26
+ }
27
+
28
+ return array($responseField => $numberOfProducts);
29
+ }
30
+
31
+ public function extendedList(
32
+ $filters,
33
+ $stockQuantityFilterAmount,
34
+ $store,
35
+ $attributes,
36
+ $customAttributes,
37
+ $qtyConfig,
38
+ $isInStockConfig,
39
+ $attributeSetNameConfig,
40
+ $categoryBreadCrumbConfig,
41
+ $manufacturerNameConfig,
42
+ $absoluteUrlConfig,
43
+ $absoluteImageUrlConfig,
44
+ $scrubProductName,
45
+ $scrubDescription,
46
+ $scrubShortDescription,
47
+ $scrubAttributeSetName,
48
+ $scrubCustomAttribute,
49
+ $pageNumber,
50
+ $productsPerPage)
51
+ {
52
+ $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
53
+ $imageBaseURL = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA)."catalog/product";
54
+
55
+ $resultItems = array();
56
+
57
+ $storeId = $this->_getStoreId($store);
58
+
59
+ // GET PRODUCTS FOR REQUESTED STORE WITH SPECIFIED FILTERS
60
+ $filteredProductsCollection = $filteredProductsCollection = $this->getProductsFilteredByStockQuantity($filters, $stockQuantityFilterAmount, $store);
61
+
62
+ if(!empty($filteredProductsCollection)) {
63
+
64
+ $filteredProducts = array();
65
+
66
+ foreach ($filteredProductsCollection as $product) {
67
+ $filteredProducts[] = $product;
68
+ }
69
+
70
+ $numberOfProducts = count($filteredProducts);
71
+ if($numberOfProducts > 0) {
72
+
73
+ $firstIndexToRetreive = ($pageNumber - 1) * $productsPerPage;
74
+ $lastIndexToRetreive = $firstIndexToRetreive + $productsPerPage - 1;
75
+
76
+ for
77
+ (
78
+ $indexToRetreive = $firstIndexToRetreive;
79
+ $indexToRetreive <= $lastIndexToRetreive && $indexToRetreive < $numberOfProducts;
80
+ $indexToRetreive++
81
+ ) {
82
+
83
+ if(isset($filteredProducts[$indexToRetreive])) {
84
+
85
+ $productToRetreive = $filteredProducts[$indexToRetreive];
86
+ $productIdToRetreive = $productToRetreive->getId();
87
+ $productToRetreive = $this->_getProduct($productIdToRetreive, $storeId, 'id');
88
+
89
+ if(!empty($productToRetreive)) {
90
+
91
+ $resultItem = array();
92
+
93
+ // STANDARD ATTRIBUTES
94
+ foreach ($productToRetreive->getTypeInstance(true)->getEditableAttributes($productToRetreive) as $attribute) {
95
+ if ($this->_isAllowedAttribute($attribute, $attributes)) {
96
+ $resultItem[$attribute->getAttributeCode()] = $productToRetreive->getData($attribute->getAttributeCode());
97
+ }
98
+ }
99
+
100
+ // CUSTOM ATTRIBUTES
101
+ if(!empty($customAttributes) && is_array($customAttributes)) {
102
+ foreach($customAttributes as $customAttribute)
103
+ {
104
+ $attributeField = $productToRetreive->getResource()->getAttribute($customAttribute);
105
+
106
+ //If it's an option or multiselect attribute
107
+ if(!empty($attributeField) && $attributeField->usesSource() && $productToRetreive->getAttributeText($customAttribute)) {
108
+ $attributeFieldValue = $productToRetreive->getAttributeText($customAttribute);
109
+ }
110
+ else {
111
+ $attributeFieldValue = $productToRetreive->getData($customAttribute);
112
+ }
113
+
114
+ if($scrubCustomAttribute) {
115
+ $attributeFieldValue = $this->scrubData($attributeFieldValue);
116
+ }
117
+
118
+ $resultItem[$customAttribute] = $attributeFieldValue;
119
+ }
120
+ }
121
+
122
+ // PRODUCT NAME SCRUBBING
123
+ if(in_array(self::PRODUCT_NAME_FIELD, $attributes) && $scrubProductName) {
124
+ $productName = $resultItem[self::PRODUCT_NAME_FIELD];
125
+ $resultItem[self::PRODUCT_NAME_FIELD] = $this->scrubData($productName);
126
+ }
127
+
128
+ // DESCRIPTION SCRUBBING
129
+ if(in_array(self::DESCRIPTION_FIELD, $attributes) && $scrubDescription) {
130
+ $resultItem[self::DESCRIPTION_FIELD] =
131
+ $this->scrubData($resultItem[self::DESCRIPTION_FIELD]);
132
+ }
133
+
134
+ // SHORT DESCRIPTION SCRUBBING
135
+ if(in_array(self::SHORT_DESCRIPTION_FIELD, $attributes) && $scrubShortDescription) {
136
+ $resultItem[self::SHORT_DESCRIPTION_FIELD] =
137
+ $this->scrubData($resultItem[self::SHORT_DESCRIPTION_FIELD]);
138
+ }
139
+
140
+ // IS IN STOCK & QUANTITY ATTRIBUTES
141
+ $stockQuantityRequested = $qtyConfig[0];
142
+ $stockStatusRequested = $isInStockConfig[0];
143
+ if($stockQuantityRequested || $stockStatusRequested) {
144
+
145
+ $inventoryStatus = Mage::getModel(self::STOCK_ITEM_MODEL)->loadByProduct($productToRetreive);
146
+
147
+ if (!empty($inventoryStatus)) {
148
+
149
+ if($stockQuantityRequested) {
150
+ $responseField = $qtyConfig[1];
151
+ $resultItem[$responseField] = $inventoryStatus->getQty();
152
+ }
153
+
154
+ if($stockStatusRequested) {
155
+ $responseField = $isInStockConfig[1];
156
+ $resultItem[$responseField] = $inventoryStatus->getIsInStock();
157
+ }
158
+ }
159
+ }
160
+
161
+ // ATTRIBUTE SET NAME
162
+ $attributeSetNameRequested = $attributeSetNameConfig[0];
163
+ if($attributeSetNameRequested) {
164
+
165
+ $attributeSet = Mage::getModel(self::ATTRIBUTE_SET_MODEL)->load($productToRetreive->getAttributeSetId());
166
+ if (!empty($attributeSet)) {
167
+
168
+ $attributeSetName = $attributeSet->getAttributeSetName();
169
+ if($scrubAttributeSetName) {
170
+ $attributeSetName = $this->scrubData($attributeSetName);
171
+ }
172
+
173
+ $responseField = $attributeSetNameConfig[1];
174
+ $resultItem[$responseField] = $attributeSetName;
175
+ }
176
+ }
177
+
178
+ // CATEGORY BREADCRUMB
179
+ $categoryBreadCrumbRequested = $categoryBreadCrumbConfig[0];
180
+ if($categoryBreadCrumbRequested) {
181
+
182
+ $categoryIds = Mage::getResourceSingleton(self::CATALOG_PRODUCT_MODEL)->getCategoryIds($productToRetreive);
183
+
184
+ if (!empty($categoryIds)) {
185
+
186
+ $categoryBreadcrumb = '';
187
+ foreach($categoryIds as $categoryId) {
188
+
189
+ $category = Mage::getModel(self::CATALOG_CATEGORY_MODEL)->setStoreId($storeId)->load($categoryId);
190
+
191
+ if(!empty($category) && $category->getId()) {
192
+ $categoryBreadcrumb .= $category->getData(self::CATEGORY_NAME_FIELD) . self::CATEGORY_SEPARATOR;
193
+ }
194
+ }
195
+
196
+ $categoryBreadcrumb = preg_replace('/' . self::CATEGORY_SEPARATOR . '$/', '', $categoryBreadcrumb);
197
+
198
+ $responseField = $categoryBreadCrumbConfig[1];
199
+ $resultItem[$responseField] = $categoryBreadcrumb;
200
+ }
201
+
202
+ // MANUFACTURER NAME
203
+ $manufacturerNameRequested = $manufacturerNameConfig[0];
204
+ if($manufacturerNameRequested) {
205
+
206
+ $manufacturer = $productToRetreive->getResource()->getAttribute("manufacturer");
207
+ if (!empty($manufacturer)) {
208
+
209
+ $manufacturerName = $manufacturer->getFrontend()->getValue($productToRetreive);
210
+ $manufacturerNameNullValue = $manufacturerNameConfig[2];
211
+ if(empty($manufacturerName) || $manufacturerName == $manufacturerNameNullValue) {
212
+ $manufacturerName = '';
213
+ }
214
+ $responseField = $manufacturerNameConfig[1];
215
+ $resultItem[$responseField] = $manufacturerName;
216
+ }
217
+ }
218
+
219
+ // ABSOLUTE URL & IMAGE
220
+ $absoluteUrlRequested = $absoluteUrlConfig[0];
221
+ $absoluteImageUrlRequested = $absoluteImageUrlConfig[0];
222
+ if($absoluteUrlRequested || $absoluteImageUrlRequested) {
223
+
224
+ $productUrl = $productToRetreive->getUrlKey();
225
+ $productImage = $productToRetreive->getImage();
226
+
227
+ $noSelectionValue = $absoluteImageUrlConfig[2];
228
+
229
+ //If it's a simple product and it's NOT visible then we are getting the URL/ImageURL from the parent (configurable/grouped) product
230
+ if($productToRetreive->getTypeId() == 'simple' && $productToRetreive->getData("visibility") == 1)
231
+ {
232
+ //Checking if the product is a child of a "configurable" product
233
+ $parentProductIds = Mage::getModel(self::CONFIGURABLE_PRODUCT_MODEL)->getParentIdsByChild($productIdToRetreive);
234
+
235
+ //Checking if the product is a child of a "grouped" product
236
+ if(sizeof($parentProductIds) < 1) {
237
+ $parentProductIds = Mage::getModel(self::GROUPED_PRODUCT_MODEL)->getParentIdsByChild($productIdToRetreive);
238
+ }
239
+
240
+ //Setting the URL SEO to the parent URL if a parent is found
241
+ if(isset($parentProductIds[0]))
242
+ {
243
+ $firstParentProduct = Mage::getModel(self::CATALOG_PRODUCT_MODEL)->load($parentProductIds[0]);
244
+ $productUrl = $firstParentProduct->getUrlPath();
245
+
246
+ if($productImage == "" || $productImage == $noSelectionValue) {
247
+ $productImage = $firstParentProduct->getImage();
248
+ }
249
+ }
250
+ //Blanking-out the URL/Image URL since items that are not visible and are not associated with a parent
251
+ else
252
+ {
253
+ $productUrl = null;
254
+ $productImage = null;
255
+ }
256
+ }
257
+
258
+ if($absoluteUrlRequested && !empty($productUrl)) {
259
+ $responseField = $absoluteUrlConfig[1];
260
+ $resultItem[$responseField] = $baseUrl . $productUrl;
261
+ }
262
+
263
+ if($absoluteImageUrlRequested && !empty($productImage) && $productImage != $noSelectionValue) {
264
+ $responseField = $absoluteImageUrlConfig[1];
265
+ $resultItem[$responseField] = $imageBaseURL . $productImage;
266
+ }
267
+ }
268
+
269
+ }
270
+
271
+ $resultItems[] = $resultItem;
272
+ }
273
+ }
274
+ }
275
+ }
276
+ }
277
+
278
+ return $resultItems;
279
+ }
280
+
281
+ private function getProductsFilteredByStockQuantity($filters, $stockQuantityFilterAmount, $store) {
282
+
283
+ $filteredProductsCollection =
284
+ Mage::getModel(self::CATALOG_PRODUCT_MODEL)
285
+ ->getCollection()
286
+ ->joinField(
287
+ 'qty',
288
+ 'cataloginventory/stock_item',
289
+ 'qty',
290
+ 'product_id=entity_id',
291
+ '{{table}}.stock_id=1',
292
+ 'left'
293
+ )
294
+ ->addAttributeToFilter('qty', array('gteq' => $stockQuantityFilterAmount))
295
+ ->addStoreFilter($store);
296
+
297
+ if (is_array($filters)) {
298
+ try {
299
+ foreach ($filters as $field => $value) {
300
+ if (isset($this->_filtersMap[$field])) {
301
+ $field = $this->_filtersMap[$field];
302
+ }
303
+ $filteredProductsCollection->addFieldToFilter($field, $value);
304
+ }
305
+ } catch (Mage_Core_Exception $e) {
306
+ $this->_fault('filters_invalid', $e->getMessage());
307
+ }
308
+ }
309
+
310
+ return $filteredProductsCollection;
311
+ }
312
+
313
+ //Scrubbing various unwanted characters
314
+ private function scrubData($fieldValue)
315
+ {
316
+ $fieldValue = str_replace(chr(10), " ", $fieldValue);
317
+ $fieldValue = str_replace(chr(13), " ", $fieldValue);
318
+ $fieldValue = str_replace("\r", " ", $fieldValue);
319
+ $fieldValue = str_replace("\n", " ", $fieldValue);
320
+ $fieldValue = str_replace("\r\n", " ", $fieldValue);
321
+ $fieldValue = str_replace("\t", " ", $fieldValue);
322
+ return $fieldValue;
323
+ }
324
+ }
app/code/local/GoDataFeed/Services/etc/api.xml ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <api>
4
+ <resources>
5
+ <catalog_product translate="title" module="catalog">
6
+ <title>GoDataFeed Product API</title>
7
+ <model>catalog/product_api</model>
8
+ <acl>catalog/product</acl>
9
+ <methods>
10
+ <count translate="title" module="catalog">
11
+ <title>Retrieve product count</title>
12
+ <acl>catalog/product/info</acl>
13
+ </count>
14
+ <extendedList translate="title" module="catalog">
15
+ <title>Retrieve products list by filters with extended attributes</title>
16
+ <acl>catalog/product/info</acl>
17
+ </extendedList>
18
+ </methods>
19
+ </catalog_product>
20
+ </resources>
21
+ <!--<resources_alias>-->
22
+ <!--<product>catalog_product</product>-->
23
+ <!--</resources_alias>-->
24
+ <!--TODO FAULTS-->
25
+ </api>
26
+ </config>
app/code/local/GoDataFeed/Services/etc/config.xml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <GoDataFeed_Services>
5
+ <version>0.0.1</version>
6
+ <!--<depends>-->
7
+ <!--<Mage_Catalog />-->
8
+ <!--</depends>-->
9
+ </GoDataFeed_Services>
10
+ </modules>
11
+ <global>
12
+ <models>
13
+ <catalog>
14
+ <rewrite>
15
+ <product_api>GoDataFeed_Services_Model_Catalog_Product_Api</product_api>
16
+ </rewrite>
17
+ </catalog>
18
+ </models>
19
+ </global>
20
+ </config>
app/etc/modules/GoDataFeed_Services.xml ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <GoDataFeed_Services>
5
+ <active>true</active>
6
+ <codePool>local</codePool>
7
+ <!--<depends>-->
8
+ <!--<Mage_Catalog />-->
9
+ <!--</depends>-->
10
+ </GoDataFeed_Services>
11
+ </modules>
12
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>GoDataFeed</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://www.godatafeed.com/aboutus.aspx">&#xA9;GoDataFeed All rights reserved</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>A simple and affordable way to optimize your product listings, automate your datafeed submissions and drive more qualified, targeted traffic to your Website.</summary>
10
+ <description>This extension optimizes product retrieval while providing enhanced attributes information. Install this extension to fully benefit GoDataFeed services.</description>
11
+ <notes>No Notes</notes>
12
+ <authors><author><name>GoDataFeedSupport</name><user>auto-converted</user><email>support@godatafeed.com</email></author></authors>
13
+ <date>2012-02-02</date>
14
+ <time>20:00:36</time>
15
+ <contents><target name="magelocal"><dir name="GoDataFeed"><dir name="Services"><dir name="Model"><dir name="Catalog"><dir name="Product"><file name="Api.php" hash="5c1becafb604af858b0c857cdfb7ce10"/></dir></dir></dir><dir name="etc"><file name="api.xml" hash="565bc8cb3899d89f37c0cc27008958f4"/><file name="config.xml" hash="8ecde4bbb6d08c822c1173f279d21bca"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="GoDataFeed_Services.xml" hash="43db0e2dd6a412462d52e77143ec5cdc"/></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies/>
18
+ </package>