我需要获得属于specyfic类别的所有类别ID。是否可以根据主要类别ID列出所有子类别类别?
答案 0 :(得分:2)
如果您查看method in
课程,您会看到名为Category
的方法:
getSubCategories()
因此,如果你有一个/**
* Return current category childs
*
* @param integer $id_lang Language ID
* @param boolean $active return only active categories
* @return array Categories
*/
public function getSubCategories($id_lang, $active = true)
{
[...]
}
对象,并希望所有活动的子类别都在前面打印,你可以这样做:
$category
答案 1 :(得分:0)
from prestapyt import PrestaShopWebServiceDict
from xml.etree import ElementTree
URL = ''
API_KEY = ''
cat_list = []
def get_categories(category_id):
prestashop = PrestaShopWebServiceDict( URL, API_KEY )
try:
# get first childrens
categories = prestashop.get('categories', category_id)['category']['associations']['categories']['category']
for category in categories:
print "main cat: " + category['id']
cat_list.append(category['id'])
try:
# get second childrens
categories = prestashop.get('categories', category['id'])['category']['associations']['categories']['category']
for category in categories:
print category['id']
cat_list.append(category['id'])
except:
print "Category " + str(category['id']) + " has not children."
except:
print "Category " + str(category_id) + " does not exist."
get_categories(98);
此外我通过api创建了这样的东西,但这只显示了一个孩子,但我必须要求两次(我不需要更低级别)。