0

タイプ yes/no のいくつかの属性を作成しました。ここで、値が yes の属性を list.phtml に表示したいと思います

多くのコードを試しましたが、この問題を解決できませんでした。これは私の最新のコードです:

<?php $attributes = $_product->getAttributes();

   foreach ($attributes as $attribute) {
         $excludeAttr = array();echo $attribute->getIsVisibleOnFront() ;
        if ( !in_array($attribute->getAttributeCode(), $excludeAttr)) {
            $value = $attribute->getFrontend()->getValue($_product);echo $value;
        if (!$_product->hasData($attribute->getAttributeCode())) {
                $value = Mage::helper('catalog')->__('N/A');
            } elseif ((string)$value == '') {
                $value = Mage::helper('catalog')->__('No');
            } elseif ($attribute->getFrontendInput() == 'price' && is_string($value)) {
                $value = Mage::app()->getStore()->convertPrice($value, true);
            }

            if (is_string($value) && strlen($value)) {
                $data[$attribute->getAttributeCode()] = array(
                    'label' => $attribute->getStoreLabel(),
                    'value' => $value,
                    'code'  => $attribute->getAttributeCode()
                );
            }
        }
    }

 if($_additional = $data): ?>

<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): ?>
        <tr>
            <th class="label"><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>
            <td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
        </tr>
    <?php endforeach; ?>
    </tbody>
</table>
<script type="text/javascript">decorateTable('product-attribute-specs-table')</script>

しかし、すべての属性が表示されますが、値が yes の yes/no タイプの属性のみを表示したいと思います。このコードを使用すると、もう1つ問題があります。

 if ($attribute->getIsVisibleOnFront() && !in_array($attribute->getAttributeCode(), $excludeAttr)) {

false を返します。このステートメントが false を返す理由が理解できませんでした。

4

1 に答える 1

2

ついに私は解決策を得ました。基本的にこの条件を追加します

<?php if ($_product->getAttributeText($_data['code']) == "Yes"): ?>

それは働き始めます

于 2012-12-04T04:54:10.197 に答える