Php Magento API V2检索soap调用catalogCategoryInfo中的自定义属性
我对magento很陌生。我试图获取在categories中创建的cusotm属性,以便在进行soap调用catalogCategoryInfo调用时显示 我使用以下代码创建了自定义属性Php Magento API V2检索soap调用catalogCategoryInfo中的自定义属性,php,web-services,magento,soap,wsdl,Php,Web Services,Magento,Soap,Wsdl,我对magento很陌生。我试图获取在categories中创建的cusotm属性,以便在进行soap调用catalogCategoryInfo调用时显示 我使用以下代码创建了自定义属性 require_once "app/Mage.php"; Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID)); $installer = new
require_once "app/Mage.php";
Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID));
$installer = new Mage_Sales_Model_Mysql4_Setup;
// change details below:
$attribute = array(
'type' => 'int',
'label'=> 'IceCatID',
'input' => 'text',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
'user_defined' => true,
'default' => "",
'group' => "General Information"
);
$installer->addAttribute('catalog_category', 'IceCatID', $attribute);
$installer->endSetup();
这起作用了。我可以在后端查看并将值添加到我的类别中,这些值保持不变
然后我编辑了这个文件
app/code/core/Mage/Catalog/Model/Category/Api.php
并编辑了公共功能级别以包括
foreach ($collection as $category) {
/* @var $category Mage_Catalog_Model_Category */
$result[] = array(
'category_id' => $category->getId(),
'parent_id' => $category->getParentId(),
'name' => $category->getName(),
'is_active' => $category->getIsActive(),
'position' => $category->getPosition(),
'icecat_id' => $category->getIceCatID(),
'level' => $category->getLevel()
);
}
以及受保护的功能_noteToArray
protected function _nodeToArray(Varien_Data_Tree_Node $node)
{
// Only basic category data
$result = array();
$result['category_id'] = $node->getId();
$result['parent_id'] = $node->getParentId();
$result['name'] = $node->getName();
$result['is_active'] = $node->getIsActive();
$result['position'] = $node->getPosition();
$result['icecat_id'] = $node->getIceCatID();
$result['level'] = $node->getLevel();
$result['children'] = array();
foreach ($node->getChildren() as $child) {
$result['children'][] = $this->_nodeToArray($child);
}
return $result;
}
我还编辑了wsdl.xml以包含对新属性的引用
<complexType name="catalogCategoryEntity">
<all>
<element name="category_id" type="xsd:int"/>
<element name="parent_id" type="xsd:int"/>
<element name="name" type="xsd:string"/>
<element name="is_active" type="xsd:int"/>
<element name="position" type="xsd:int"/>
<element name="icecat_id" type="xsd:int"/>
<element name="level" type="xsd:int"/>
<element name="children" type="typens:ArrayOfCatalogCategoryEntities"/>
</all>
</complexType>
<complexType name="catalogCategoryEntityNoChildren">
<all>
<element name="category_id" type="xsd:int"/>
<element name="parent_id" type="xsd:int"/>
<element name="name" type="xsd:string"/>
<element name="is_active" type="xsd:int"/>
<element name="position" type="xsd:int"/>
<element name="icecat_id" type="xsd:int"/>
<element name="level" type="xsd:int"/>
</all>
</complexType>
<complexType name="catalogCategoryTree">
<all>
<element name="category_id" type="xsd:int"/>
<element name="parent_id" type="xsd:int"/>
<element name="name" type="xsd:string"/>
<element name="position" type="xsd:int"/>
<element name="level" type="xsd:int"/>
<element name="icecat_id" type="xsd:int"/>
<element name="children" type="typens:ArrayOfCatalogCategoryEntities"/>
</all>
</complexType>
当我打soap电话时
$result = $proxy->catalogCategoryTree($sessionId);
$tmp = objectToArray($result);
echo "<pre>"; print_r($tmp);
$result=$proxy->catalogCategoryTree($sessionId);
$tmp=objectToArray($result);
回声“;印刷(tmp);
当我看到结果时,有自定义属性的条目,但没有值。我知道我需要编写一个函数来检索它,但我不知道在哪里以及写什么。有什么想法吗?首先,不要编辑核心。如果你只是在核心测试,那没关系 您说您在第112行编辑了Mage_Catalog_Model_Category_Api,添加了
$collection = Mage::getModel('catalog/category')->getCollection()
->setStoreId($storeId)
->addAttributeToSelect('name')
->addAttributeToSelect('is_active');
如果在第99行附近查找上面的几行:
->addAttributeToSelect('is_active')
->addAttributeToSelect('IceCatID');
将IceCatID属性添加到“选择”
->addAttributeToSelect('is_active')
->addAttributeToSelect('IceCatID');