EasySocialShop_Api_Paging - Version 1.0.0

Version Notes

First stable release.
Tested on 1.7.0.0 and 1.6.2.0 versions.

Download this release

Release Info

Developer Alexey Bass
Extension EasySocialShop_Api_Paging
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/local/EasySocialShop/Catalog/Model/Product/Api.php ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Rewrites original Mage_Catalog_Model_Product_Api to limit result set.
5
+ *
6
+ * @category EasySocialShop
7
+ * @package EasySocialShop_Catalog
8
+ * @author Alexey Bass (@alexey_bass)
9
+ * @see Mage_Catalog_Model_Product_Api::items
10
+ */
11
+ class EasySocialShop_Catalog_Model_Product_Api extends Mage_Catalog_Model_Product_Api
12
+ {
13
+ /**
14
+ * Retrieve list of products with basic info (id, sku, type, set, name)
15
+ *
16
+ * @param array $filters
17
+ * @param string|int $store
18
+ * @return array
19
+ */
20
+ public function items($filters = null, $store = null)
21
+ {
22
+ $collection = Mage::getModel('catalog/product')->getCollection()
23
+ ->addStoreFilter($this->_getStoreId($store))
24
+ ->addAttributeToSelect('name');
25
+
26
+ # defaults for paging
27
+ $paging = array(
28
+ 'start' => 1,
29
+ 'size' => -1,
30
+ );
31
+
32
+ if (is_array($filters)) {
33
+
34
+ # cut our custom paging markers from Mage filter so it will not fail
35
+ if (isset($filters['page-start'])) {
36
+ if (is_numeric($filters['page-start'])) {
37
+ $paging['start'] = ($filters['page-start'] > 0) ? (int) $filters['page-start'] : 1;
38
+ }
39
+ unset($filters['page-start']);
40
+ }
41
+ if (isset($filters['page-size'])) {
42
+ if (is_numeric($filters['page-size'])) {
43
+ $paging['size'] = ($filters['page-size'] >= 0) ? (int) $filters['page-size'] : -1;
44
+ }
45
+ unset($filters['page-size']);
46
+ }
47
+
48
+ try {
49
+ foreach ($filters as $field => $value) {
50
+ if (isset($this->_filtersMap[$field])) {
51
+ $field = $this->_filtersMap[$field];
52
+ }
53
+
54
+ $collection->addFieldToFilter($field, $value);
55
+ }
56
+ } catch (Mage_Core_Exception $e) {
57
+ $this->_fault('filters_invalid', $e->getMessage());
58
+ }
59
+ }
60
+
61
+ # if size is not set, size is all collection
62
+ if ($paging['size'] === -1) {
63
+ $paging['size'] = count($collection);
64
+ }
65
+
66
+ $result = array();
67
+
68
+ $i = -1;
69
+ $startI = ($paging['start'] - 1) * $paging['size'];
70
+ $endI = ($paging['size'] > 1) ? ($paging['start'] * $paging['size'] - 1) : $startI;
71
+ foreach ($collection as $product) {
72
+ $i++;
73
+ if ($i > $endI) {
74
+ break;
75
+ }
76
+ if ($i < $startI) {
77
+ continue;
78
+ }
79
+
80
+ // $result[] = $product->getData();
81
+ $result[] = array( // Basic product data
82
+ 'product_id' => $product->getId(),
83
+ 'sku' => $product->getSku(),
84
+ 'name' => $product->getName(),
85
+ 'set' => $product->getAttributeSetId(),
86
+ 'type' => $product->getTypeId(),
87
+ 'category_ids' => $product->getCategoryIds()
88
+ );
89
+ }
90
+
91
+ return $result;
92
+ }
93
+ }
app/code/local/EasySocialShop/Catalog/etc/config.xml ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <!--
3
+ /**
4
+ * @category EasySocialShop
5
+ * @package EasySocialShop_Catalog
6
+ * @author Alexey Bass (@alexey_bass)
7
+ */
8
+ -->
9
+ <config>
10
+ <modules>
11
+ <EasySocialShop_Catalog>
12
+ <version>0.1.0</version>
13
+ </EasySocialShop_Catalog>
14
+ </modules>
15
+ <global>
16
+ <models>
17
+ <catalog>
18
+ <rewrite>
19
+ <product_api>EasySocialShop_Catalog_Model_Product_Api</product_api>
20
+ </rewrite>
21
+ </catalog>
22
+ </models>
23
+ </global>
24
+ </config>
app/etc/modules/EasySocialShop_Catalog.xml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <!--
3
+ /**
4
+ * @category EasySocialShop
5
+ * @package EasySocialShop_Catalog
6
+ * @author Alexey Bass (@alexey_bass)
7
+ */
8
+ -->
9
+ <config>
10
+ <modules>
11
+ <EasySocialShop_Catalog>
12
+ <active>true</active>
13
+ <codePool>local</codePool>
14
+ <depends>
15
+ <Mage_Core />
16
+ <Mage_Catalog />
17
+ </depends>
18
+ </EasySocialShop_Catalog>
19
+ </modules>
20
+ </config>
package.xml ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>EasySocialShop_Api_Paging</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Adds paging functionality to API calls.</summary>
10
+ <description>Adds paging functionality to API calls.</description>
11
+ <notes>First stable release.&#xD;
12
+ Tested on 1.7.0.0 and 1.6.2.0 versions.</notes>
13
+ <authors><author><name>Alexey Bass</name><user>alexey_bass</user><email>alexey.bass@gmail.com</email></author></authors>
14
+ <date>2012-06-24</date>
15
+ <time>15:34:50</time>
16
+ <contents><target name="magelocal"><dir name="EasySocialShop"><dir name="Catalog"><dir name="Model"><dir name="Product"><file name="Api.php" hash="9efff3475d9e3b3cbcd6a0fff1d3bed3"/></dir></dir><dir name="etc"><file name="config.xml" hash="224b057f0eb7dccfb8c2fd9dd7c1de3b"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="EasySocialShop_Catalog.xml" hash="8f34ceddbeb6741f8cfc379710933968"/></dir></target></contents>
17
+ <compatible/>
18
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
19
+ </package>