Magento:Can';我没有孩子
由于某些原因,在尝试获取类别子类别时,此代码返回NULLMagento:Can';我没有孩子,magento,Magento,由于某些原因,在尝试获取类别子类别时,此代码返回NULL <?php var_dump($_category->getChildrenCategories()); ?> 以下是.phmtl文件中的完整代码 <ul id="nav_vert"> <?php foreach ($this->getStoreCategories() as $_category): ?> <?php if ($
<?php var_dump($_category->getChildrenCategories()); ?>
以下是.phmtl文件中的完整代码
<ul id="nav_vert">
<?php foreach ($this->getStoreCategories() as $_category): ?>
<?php if ($_category->getIsActive()) { ?>
<?php $open = $this->isCategoryActive($_category); ?>
<?php $potential = $_category->hasChildren(); ?>
<li><a href="<?php echo $this->getCategoryUrl($_category); ?>"<?php if($open) { echo ' class="open"'; } ?><?php if($potential) { echo ' class="potential"'; } ?> ><?php if($potential&&$open) { echo 'v '; } elseif($potential) { echo '> '; }else{ echo ' '; }?><?php echo $_category->getName();?></a>
<?php if ($open && $potential): ?>
<?php var_dump($_category->getChildrenCategories()); ?>
<ul>
<?php foreach ($_category->getChildrenCategories() as $subcategory): ?>
<?php $subCat = Mage::getModel('catalog/category')->load($subcategory); ?>
<?php $open = $this->isCategoryActive($subCat); ?>
<?php $potential = $subCat->hasChildren(); ?>
<li><a href="<?php echo $this->getCategoryUrl($subCat); ?>"<?php if($open) { echo ' class="subopen"'; } ?><?php if($potential) { echo ' class="potential"'; } ?><?php if(!$potential&&$open) { echo ' class="final"'; } ?> ><?php if($potential&&$open) { echo ':: '; } elseif($potential) { echo '> '; }?><?php echo $subCat->getName(); ?> (<?php echo $subCat->getProductCount(); ?>)</a>
<?php if ($open && $potential): ?>
<ul>
<?php foreach ($subcategory->getChildrenCategories() as $subsubcategory): ?>
<?php $subsubCat = Mage::getModel('catalog/category')->load($subsubcategory); ?>
<?php $open = $this->isCategoryActive($subsubCat) ?>
<li><a href="<?php echo $this->getCategoryUrl($subsubCat); ?>" <?php if($open) { echo ' class="final"'; } ?>><?php echo $subsubCat->getName(); ?> (<?php echo $subsubCat->getProductCount(); ?>)</a></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</li>
<?php } ?>
<?php endforeach ?>
</ul>
-
-
这一行总是返回true
<?php $potential = $_category->hasChildren(); ?>
我知道这个类别有孩子
有人能提出为什么这不起作用吗
这是我在页面中放置phtml的方式:
<reference name="left">
<block type="catalog/navigation" name="catalog.vertnav" template="catalog/navigation/vert_nav.phtml" before="-" />
</reference>
Magento 1.5.1.0版尝试使用
$\u category->getChildrenCategories()
(而不是$\u category->getChildrenCategories()
)
祝你度过轻松的一天,
Pesach尝试使用
$\u category->getChildrenCategories()
(而不是$\u category->getChildrenCategories()
)
祝你度过轻松的一天,
Pesach您也可以试试这个
foreach ($_category->getCategories($_category) as $subcategory):
是一个更复杂的表单,但它也允许您进行更多的控制。通过指定递归级别,您不仅可以检索子级,还可以检索孙子级…您可能还想试试这个
foreach ($_category->getCategories($_category) as $subcategory):
是一个更复杂的表单,但它也允许您进行更多的控制。通过指定递归级别,您不仅可以检索子级,还可以检索子级…尝试使用此代码
$this->getCurrentCategory()->getChildrenCategories()
希望这有助于尝试使用此代码
$this->getCurrentCategory()->getChildrenCategories()
<?php $helper = $this->helper('catalog/category') ?>
<?php $categories = $this->getStoreCategories() ?>
<?php foreach($categories as $category): ?>
<?php $subcategories = $category->getChildren() ?>
<?php foreach($subcategories as $subcategory): ?>
<?php $subsubcategories = $subcategory->getChildren() ?>
<?php foreach($subsubcategories as $subsubcategory): ?>
<?php endforeach; ?><!-- end foreach subsubcategories -->
<?php endforeach; ?><!-- end foreach subcategories -->
<?php endforeach; ?><!-- end foreach categories -->
希望这有帮助
<?php $helper = $this->helper('catalog/category') ?>
<?php $categories = $this->getStoreCategories() ?>
<?php foreach($categories as $category): ?>
<?php $subcategories = $category->getChildren() ?>
<?php foreach($subcategories as $subcategory): ?>
<?php $subsubcategories = $subcategory->getChildren() ?>
<?php foreach($subsubcategories as $subsubcategory): ?>
<?php endforeach; ?><!-- end foreach subsubcategories -->
<?php endforeach; ?><!-- end foreach subcategories -->
<?php endforeach; ?><!-- end foreach categories -->
这是提取子类别背后的基本思想。因此,您可以相应地处理它。
这是提取子类别背后的基本思想。因此,您可以相应地处理它。我最初有getChildren,但它似乎会使页面崩溃。我在某个地方读到过他们在某个时候把它从getChildren改为getChildrenCategories?如果你试图
var\u dump($subcategory)
那么它肯定会使页面崩溃,或者至少会耗尽内存。改用var\u dump($subcategory->debug())
,您可能会发现getChildren
工作正常。我最初有getChildren,但它似乎会使页面崩溃。我在某个地方读到过他们在某个时候把它从getChildren改为getChildrenCategories?如果你试图var\u dump($subcategory)
那么它肯定会使页面崩溃,或者至少会耗尽内存。改用var\u dump($subcategory->debug())
,您可能会发现getChildren
工作正常。我尝试了您的函数,但
也返回NULL。我开始认为块没有访问这些方法的权限?我尝试了你的函数,但是
也返回NULL。我开始觉得区块没有这些方法?