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 model for product instance
29: *
30: * @category Mage
31: * @package Mage_Catalog
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_Catalog_Model_Api2_Product extends Mage_Api2_Model_Resource
35: {
36: /**
37: * Get available attributes of API resource
38: *
39: * @param string $userType
40: * @param string $operation
41: * @return array
42: */
43: public function getAvailableAttributes($userType, $operation)
44: {
45: $attributes = $this->getAvailableAttributesFromConfig();
46: /** @var $entityType Mage_Eav_Model_Entity_Type */
47: $entityType = Mage::getModel('eav/entity_type')->loadByCode('catalog_product');
48: $entityOnlyAttrs = $this->getEntityOnlyAttributes($userType, $operation);
49: /** @var $attribute Mage_Catalog_Model_Resource_Eav_Attribute */
50: foreach ($entityType->getAttributeCollection() as $attribute) {
51: if ($this->_isAttributeVisible($attribute, $userType)) {
52: $attributes[$attribute->getAttributeCode()] = $attribute->getFrontendLabel();
53: }
54: }
55: $excludedAttrs = $this->getExcludedAttributes($userType, $operation);
56: $includedAttrs = $this->getIncludedAttributes($userType, $operation);
57: foreach ($attributes as $code => $label) {
58: if (in_array($code, $excludedAttrs) || ($includedAttrs && !in_array($code, $includedAttrs))) {
59: unset($attributes[$code]);
60: }
61: if (in_array($code, $entityOnlyAttrs)) {
62: $attributes[$code] .= ' *';
63: }
64: }
65:
66: return $attributes;
67: }
68:
69: /**
70: * Define if attribute should be visible for passed user type
71: *
72: * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute
73: * @param string $userType
74: * @return bool
75: */
76: protected function _isAttributeVisible(Mage_Catalog_Model_Resource_Eav_Attribute $attribute, $userType)
77: {
78: $isAttributeVisible = false;
79: if ($userType == Mage_Api2_Model_Auth_User_Admin::USER_TYPE) {
80: $isAttributeVisible = $attribute->getIsVisible();
81: } else {
82: $systemAttributesForNonAdmin = array(
83: 'sku', 'name', 'short_description', 'description', 'tier_price', 'meta_title', 'meta_description',
84: 'meta_keyword',
85: );
86: if ($attribute->getIsUserDefined()) {
87: $isAttributeVisible = $attribute->getIsVisibleOnFront();
88: } else if (in_array($attribute->getAttributeCode(), $systemAttributesForNonAdmin)) {
89: $isAttributeVisible = true;
90: }
91: }
92: return (bool)$isAttributeVisible;
93: }
94: }
95: