gpt4 book ai didi

php - 如何在 Magento 中获取子类别?`

转载 作者:行者123 更新时间:2023-12-02 07:09:03 24 4
gpt4 key购买 nike

我正在玩 magento 的主页,我在其中创建了一个选项卡,该选项卡显示了所有类别,包括根目录、类别和子类别(在一个选项卡中)。现在我只想在主选项卡中显示主要类别(其父项是根目录)并且在每个类别下我想列出它们各自的子类别。我写了下面的代码来实现其中的一部分,

模型类

public function getsubCategory($parent)
{

$subcategoryCollection = Mage::getModel('catalog/category')
->getCollection()
->addAttributeToFilter('parent_id', $parent);
return $subcategoryCollection;

block 类

protected function b4Html_subcategory($parent)
{
$catModel = Mage::getModel('Pragtech_Sweet/category');
$mysubCategory = $catModel->getsubCategory($parent);
$this->mysubCategory = $myCategory;
return $mysubCategory;
}

模板文件

$obj = new Pragtech_Sweet_Block_Category();
$collection = $obj->b4Html();
foreach ($collection as $category)
{
$name = $category->getName();
$parent = $category->getParent_id();

foreach ($obj->b4Html_subcategory($parent) as $subcategory)
{
$subname = $subcategory->getName();
//Here Will Go Ther Code For Sub Categories

}

但它不起作用..我无法理解我做错了什么......任何人都可以帮助我

最佳答案

改为这样做:

Mage::getModel('catalog/category')->load('23')->getChildrenCategories();

并迭代结果。

我就是这样发现的:

$object = Mage::getModel('catalog/category'); 
print_r(get_class_methods($object));
print_r($object->load('23')->getChildrenCategories()->toArray());

关于php - 如何在 Magento 中获取子类别?`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7926121/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com