Commenti disabilitati su Escludere gli attributi vuoti o nulli in Magento

Per qualche strana ragione, gli sviluppatori di Magento hanno deciso che un attributo vuoto non deve essere vuoto, ma piuttosto “No” o “N/A”, a seconda del suo tipo. Questo non è solo fastidioso, ma in alcuni casi può far vedere informazioni errate il che confonderebbe i visitatori e le vendite potenzialmente perse.

Fortunatamente, c’è una soluzione rapida che risolve il problema. Aprite il file /app/design/frontend/default/template/catalog/product/view/attribute.phtml in un editor e trovare le seguenti righe:

<?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; ?>

e sostituirle con:

<?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->htmlEscape($this->__($_data['label'])) ?></th>
        <td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
    </tr>
    <?php } ?>
<?php endforeach; ?>

Salva il file e hai finito.

Comments are closed.