00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Mage_Catalog_Model_Category_Api_V2 extends Mage_Catalog_Model_Category_Api
00035 {
00036
00037
00038
00039
00040
00041
00042
00043
00044 public function info($categoryId, $store = null, $attributes = null)
00045 {
00046 $category = $this->_initCategory($categoryId, $store);
00047
00048
00049 $result = array();
00050 $result['category_id'] = $category->getId();
00051
00052 $result['is_active'] = $category->getIsActive();
00053 $result['position'] = $category->getPosition();
00054 $result['level'] = $category->getLevel();
00055
00056 foreach ($category->getAttributes() as $attribute) {
00057 if ($this->_isAllowedAttribute($attribute, $attributes)) {
00058 $result[$attribute->getAttributeCode()] = $category->getDataUsingMethod($attribute->getAttributeCode());
00059 }
00060 }
00061 $result['parent_id'] = $category->getParentId();
00062 $result['children'] = $category->getChildren();
00063 $result['all_children'] = $category->getAllChildren();
00064
00065 return $result;
00066 }
00067
00068
00069
00070
00071
00072
00073
00074
00075 public function create($parentId, $categoryData, $store = null)
00076 {
00077 $parent_category = $this->_initCategory($parentId);
00078
00079 $category = Mage::getModel('catalog/category')
00080 ->setStoreId($this->_getStoreId($store));
00081
00082 $category->addData(array('path'=>implode('/',$parent_category->getPathIds())));
00083
00084 $category ->setAttributeSetId($category->getDefaultAttributeSetId());
00085
00086
00087 foreach ($category->getAttributes() as $attribute) {
00088 $_attrCode = $attribute->getAttributeCode();
00089 if ($this->_isAllowedAttribute($attribute)
00090 && isset($categoryData->$_attrCode)) {
00091 $category->setData(
00092 $attribute->getAttributeCode(),
00093 $categoryData->$_attrCode
00094 );
00095 }
00096 }
00097 $category->setParentId($parent_category->getId());
00098 try {
00099 $category->save();
00100 } catch (Mage_Core_Exception $e) {
00101 $this->_fault('data_invalid', $e->getMessage());
00102 }
00103
00104 return $category->getId();
00105 }
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115 public function update($categoryId, $categoryData, $store = null)
00116 {
00117 $category = $this->_initCategory($categoryId, $store);
00118
00119 foreach ($category->getAttributes() as $attribute) {
00120 $_attrCode = $attribute->getAttributeCode();
00121 if ($this->_isAllowedAttribute($attribute)
00122 && isset($categoryData->$_attrCode)) {
00123 $category->setData(
00124 $attribute->getAttributeCode(),
00125 $categoryData->$_attrCode
00126 );
00127 }
00128 }
00129
00130 try {
00131 $category->save();
00132 } catch (Mage_Core_Exception $e) {
00133 $this->_fault('data_invalid', $e->getMessage());
00134 }
00135
00136 return true;
00137 }
00138 }