1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Catalog
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27: /**
28: * Abstract API2 class for product categories
29: *
30: * @category Mage
31: * @package Mage_Catalog
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: abstract class Mage_Catalog_Model_Api2_Product_Category_Rest extends Mage_Catalog_Model_Api2_Product_Rest
35: {
36: /**
37: * Product category assign is not available
38: *
39: * @param array $data
40: */
41: protected function _create(array $data)
42: {
43: $this->_critical(self::RESOURCE_METHOD_NOT_ALLOWED);
44: }
45:
46: /**
47: * Product category update is not available
48: *
49: * @param array $data
50: */
51: protected function _update(array $data)
52: {
53: $this->_critical(self::RESOURCE_METHOD_NOT_ALLOWED);
54: }
55:
56: /**
57: * Retrieve product data
58: *
59: * @return array
60: */
61: protected function _retrieveCollection()
62: {
63: $return = array();
64:
65: foreach ($this->_getCategoryIds() as $categoryId) {
66: $return[] = array('category_id' => $categoryId);
67: }
68: return $return;
69: }
70:
71: /**
72: * Only admin have permissions for product category unassign
73: */
74: protected function _delete()
75: {
76: $this->_critical(self::RESOURCE_METHOD_NOT_ALLOWED);
77: }
78:
79: /**
80: * Load category by id
81: *
82: * @param int $categoryId
83: * @return Mage_Catalog_Model_Category
84: */
85: protected function _getCategoryById($categoryId)
86: {
87: /** @var $category Mage_Catalog_Model_Category */
88: $category = Mage::getModel('catalog/category')->setStoreId(0)->load($categoryId);
89: if (!$category->getId()) {
90: $this->_critical('Category not found', Mage_Api2_Model_Server::HTTP_NOT_FOUND);
91: }
92:
93: return $category;
94: }
95:
96: /**
97: * Get assigned categories ids
98: *
99: * @return array
100: */
101: protected function _getCategoryIds()
102: {
103: return $this->_getProduct()->getCategoryCollection()->addIsActiveFilter()->getAllIds();
104: }
105: }
106: