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_Sales
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: * Sale api resource abstract
29: *
30: * @category Mage
31: * @package Mage_Sales
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_Sales_Model_Api_Resource extends Mage_Api_Model_Resource_Abstract
35: {
36: /**
37: * Default ignored attribute codes per entity type
38: *
39: * @var array
40: */
41: protected $_ignoredAttributeCodes = array(
42: 'global' => array('entity_id', 'attribute_set_id', 'entity_type_id')
43: );
44:
45: /**
46: * Attributes map array per entity type
47: *
48: * @var google
49: */
50: protected $_attributesMap = array(
51: 'global' => array()
52: );
53:
54: /**
55: * Update attributes for entity
56: *
57: * @param array $data
58: * @param Mage_Core_Model_Abstract $object
59: * @param array $attributes
60: * @return Mage_Sales_Model_Api_Resource
61: */
62: protected function _updateAttributes($data, $object, $type, array $attributes = null)
63: {
64:
65: foreach ($data as $attribute=>$value) {
66: if ($this->_isAllowedAttribute($attribute, $type, $attributes)) {
67: $object->setData($attribute, $value);
68: }
69: }
70:
71: return $this;
72: }
73:
74: /**
75: * Retrieve entity attributes values
76: *
77: * @param Mage_Core_Model_Abstract $object
78: * @param array $attributes
79: * @return Mage_Sales_Model_Api_Resource
80: */
81: protected function _getAttributes($object, $type, array $attributes = null)
82: {
83: $result = array();
84:
85: if (!is_object($object)) {
86: return $result;
87: }
88:
89: foreach ($object->getData() as $attribute=>$value) {
90: if ($this->_isAllowedAttribute($attribute, $type, $attributes)) {
91: $result[$attribute] = $value;
92: }
93: }
94:
95: if (isset($this->_attributesMap['global'])) {
96: foreach ($this->_attributesMap['global'] as $alias=>$attributeCode) {
97: $result[$alias] = $object->getData($attributeCode);
98: }
99: }
100:
101: if (isset($this->_attributesMap[$type])) {
102: foreach ($this->_attributesMap[$type] as $alias=>$attributeCode) {
103: $result[$alias] = $object->getData($attributeCode);
104: }
105: }
106:
107: return $result;
108: }
109:
110: /**
111: * Check is attribute allowed to usage
112: *
113: * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute
114: * @param string $entityType
115: * @param array $attributes
116: * @return boolean
117: */
118: protected function _isAllowedAttribute($attributeCode, $type, array $attributes = null)
119: {
120: if (!empty($attributes)
121: && !(in_array($attributeCode, $attributes))) {
122: return false;
123: }
124:
125: if (in_array($attributeCode, $this->_ignoredAttributeCodes['global'])) {
126: return false;
127: }
128:
129: if (isset($this->_ignoredAttributeCodes[$type])
130: && in_array($attributeCode, $this->_ignoredAttributeCodes[$type])) {
131: return false;
132: }
133:
134: return true;
135: }
136: } // Class Mage_Sales_Model_Api_Resource End
137: