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: * Catalog category attribute api
29: *
30: * @category Mage
31: * @package Mage_Catalog
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_Catalog_Model_Category_Attribute_Api extends Mage_Catalog_Model_Api_Resource
35: {
36: public function __construct()
37: {
38: $this->_storeIdSessionField = 'category_store_id';
39: }
40:
41: /**
42: * Retrieve category attributes
43: *
44: * @return array
45: */
46: public function items()
47: {
48: $attributes = Mage::getModel('catalog/category')->getAttributes();
49: $result = array();
50:
51: foreach ($attributes as $attribute) {
52: /* @var $attribute Mage_Catalog_Model_Resource_Eav_Attribute */
53: if ($this->_isAllowedAttribute($attribute)) {
54: if (!$attribute->getId() || $attribute->isScopeGlobal()) {
55: $scope = 'global';
56: } elseif ($attribute->isScopeWebsite()) {
57: $scope = 'website';
58: } else {
59: $scope = 'store';
60: }
61:
62: $result[] = array(
63: 'attribute_id' => $attribute->getId(),
64: 'code' => $attribute->getAttributeCode(),
65: 'type' => $attribute->getFrontendInput(),
66: 'required' => $attribute->getIsRequired(),
67: 'scope' => $scope
68: );
69: }
70: }
71:
72: return $result;
73: }
74:
75: /**
76: * Retrieve category attribute options
77: *
78: * @param int|string $attributeId
79: * @param string|int $store
80: * @return array
81: */
82: public function options($attributeId, $store = null)
83: {
84: $attribute = Mage::getModel('catalog/category')
85: ->setStoreId($this->_getStoreId($store))
86: ->getResource()
87: ->getAttribute($attributeId);
88:
89: if (!$attribute) {
90: $this->_fault('not_exists');
91: }
92:
93: $result = array();
94: if ($attribute->usesSource()) {
95: foreach ($attribute->getSource()->getAllOptions(false) as $optionId=>$optionValue) {
96: if (is_array($optionValue)) {
97: $result[] = $optionValue;
98: } else {
99: $result[] = array(
100: 'value' => $optionId,
101: 'label' => $optionValue
102: );
103: }
104: }
105: }
106:
107: return $result;
108: }
109: } // Class Mage_Catalog_Model_Category_Attribute_Api End
110: