有人可以帮我解决以下问题吗?我们在以下代码中显示产品所属的类别列表(我们使用的类别属性是" creareseo_heading")。但是,有时" creareseo_heading"属性为空但行仍显示带有标签但没有值。我相信我们需要一些" if"语句完全隐藏行。我尝试了一切,但无法使其发挥作用。基本上,如果" creareseo_heading"的列表,我需要该行完全消失。类别属性为空。
解决!!!见下文:))
<?php
$_helper = $this->helper('catalog/output');
$_product = $this->getProduct();
$currentCatIds = $_product->getCategoryIds();
$catCollection = Mage::getResourceModel('catalog/category_collection')
->addAttributeToSelect('*')
->addAttributeToFilter('entity_id', $currentCatIds)
->addAttributeToFilter('is_active', 1)
->setOrder('creareseo_heading', 'asc')
->addIsActiveFilter();
?>
<?php if($_additional = $this->getAdditionalData()): ?>
<h2><?php echo $this->__('Additional Information') ?></h2>
<table class="data-table" id="product-attribute-specs-table">
<col width="25%" />
<col />
<tbody>
<?php foreach ($_additional as $_data): ?>
<?php $_attribute = $_product->getResource()->getAttribute($_data['code']);
if (!is_null($_product->getData($_attribute->getAttributeCode())) && ((string)$_attribute->getFrontend()->getValue($_product) != '')) { ?>
<tr>
<th class="label"><?php echo $this->escapeHtml($this->__($_data['label'])) ?></th>
<td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
</tr>
<?php } ?>
<?php endforeach; ?>
<?php
$applicationGuides = array();
foreach($catCollection as $cat){
$c = $cat->getCreareseoHeading();
if (!empty($c)) $applicationGuides[] = $c;
}
?>
<?php if(!empty($applicationGuides)): ?>
<tr>
<th class="label"><?php echo $this->__('Application Guide') ?></th>
<td class="data">
<ul>
<?php foreach($applicationGuides as $cat): ?>
<li><?php echo $cat; ?></li>
<?php endforeach; ?>
</ul>
</td>
</tr>
<?php endif;?>
</tbody>
</table>
<script type="text/javascript">decorateTable('product-attribute-specs-table')</script>
<?php endif;?>
答案 0 :(得分:0)
<?php
/* Build list with no empty values */
$applicationGuides = array();
foreach($catCollection as $cat){
$c = $cat->getCreareseoHeading();
if (!empty($c)) $applicationGuides[] = $c;
}
?>
<?php if(!empty($applicationGuides)): ?>
<tr>
<th class="label"><?php echo $this->__('Application Guide') ?></th>
<td class="data">
<ul>
<?php foreach($applicationGuides as $cat): ?>
<li><?php echo $cat; ?></li>
<?php endforeach; ?>
</ul>
</td>
</tr>
<?php endif;?>
答案 1 :(得分:0)
这对于评论来说太长了,所以添加另一个答案以适应它来帮助您调试问题......
是否报告了任何错误?如果您了解代码,也许您可以逐步更改代码并查看是否获得了预期的结果。如果您不是,那么我建议您首先将此代码块添加到原始代码中,就在我们正在谈论的<tr>
块上方...
<?php
/* Build list with no empty values */
$applicationGuides = array();
foreach($catCollection as $cat){
$c = $cat->getCreareseoHeading();
if (!empty($c)) $applicationGuides[] = $c;
}
var_dump($applicationGuides);
?>