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 api resource
29: *
30: * @category Mage
31: * @package Mage_Catalog
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_Catalog_Model_Api_Resource extends Mage_Api_Model_Resource_Abstract
35: {
36: /**
37: * Default ignored attribute codes
38: *
39: * @var array
40: */
41: protected $_ignoredAttributeCodes = array('entity_id', 'attribute_set_id', 'entity_type_id');
42:
43: /**
44: * Default ignored attribute types
45: *
46: * @var array
47: */
48: protected $_ignoredAttributeTypes = array();
49:
50: /**
51: * Field name in session for saving store id
52: * @var string
53: */
54: protected $_storeIdSessionField = 'store_id';
55:
56: /**
57: * Name of resource model in ACL list
58: * @var string
59: */
60: protected $_resourceAttributeAclName = 'catalog/category/attributes/field_';
61:
62: /**
63: * Check is attribute allowed
64: *
65: * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute
66: * @param array $attributes
67: * @return boolean
68: */
69: protected function _isAllowedAttribute($attribute, $attributes = null)
70: {
71:
72: if (Mage::getSingleton('api/server')->getApiName() == 'rest') {
73: if (!$this->_checkAttributeAcl($attribute)) {
74: return false;
75: }
76: }
77:
78: if (is_array($attributes)
79: && !( in_array($attribute->getAttributeCode(), $attributes)
80: || in_array($attribute->getAttributeId(), $attributes))) {
81: return false;
82: }
83:
84: return !in_array($attribute->getFrontendInput(), $this->_ignoredAttributeTypes)
85: && !in_array($attribute->getAttributeCode(), $this->_ignoredAttributeCodes);
86: }
87:
88: /**
89: * Retrives store id from store code, if no store id specified,
90: * it use seted session or admin store
91: *
92: * @param string|int $store
93: * @return int
94: */
95: protected function _getStoreId($store = null)
96: {
97: if (is_null($store)) {
98: $store = ($this->_getSession()->hasData($this->_storeIdSessionField)
99: ? $this->_getSession()->getData($this->_storeIdSessionField) : 0);
100: }
101:
102: try {
103: $storeId = Mage::app()->getStore($store)->getId();
104: } catch (Mage_Core_Model_Store_Exception $e) {
105: $this->_fault('store_not_exists');
106: }
107:
108: return $storeId;
109: }
110:
111: /**
112: * Return loaded product instance
113: *
114: * @param int|string $productId (SKU or ID)
115: * @param int|string $store
116: * @param string $identifierType
117: * @return Mage_Catalog_Model_Product
118: */
119: protected function _getProduct($productId, $store = null, $identifierType = null)
120: {
121: $product = Mage::helper('catalog/product')->getProduct($productId, $this->_getStoreId($store), $identifierType);
122: if (is_null($product->getId())) {
123: $this->_fault('product_not_exists');
124: }
125: return $product;
126: }
127:
128: /**
129: * Set current store for catalog.
130: *
131: * @param string|int $store
132: * @return int
133: */
134: public function currentStore($store=null)
135: {
136: if (!is_null($store)) {
137: try {
138: $storeId = Mage::app()->getStore($store)->getId();
139: } catch (Mage_Core_Model_Store_Exception $e) {
140: $this->_fault('store_not_exists');
141: }
142:
143: $this->_getSession()->setData($this->_storeIdSessionField, $storeId);
144: }
145:
146: return $this->_getStoreId();
147: }
148: } // Class Mage_Catalog_Model_Api_Resource End
149: