In Magento how to add class to list depending on the attributes to be displayed?

6

I have foreach which brings me all the children of an X attribute, and I need to add a specific class in the <ul> list to be able to format by CSS according to the Y attribute. However, I can not add the attribute name in the class.

Below is an example taken from app / design / frontend / base / default / tempplate / catalog / layer / filter.phtml

<ol class="filters filter-type">
<?php foreach ($this->getItems() as $_item): ?>
    <li>
        <?php if ($_item->getCount() > 0): ?>
        <a href="<?php echo $this->urlEscape($_item->getUrl()) ?>"><?php echo $_item->getLabel() ?></a>
        <?php else: echo $_item->getLabel() ?>
        <?php endif; ?>
        <?php if ($this->shouldDisplayProductCount()): ?>
        (<?php echo $_item->getCount() ?>)
        <?php endif; ?>
    </li>
<?php endforeach ?>
</ol>

On a category-filtered page, I want the attributes of the products to load those blocks to have a specific class to identify.

Example:

Size

  • 38
  • 39
  • 40

Sex

  • Male
  • Female

Price

  • 30 to 40
  • 50 to 80
  • 100 to 200

Where each block receives a class: filter-size , filter-sex , filter- only I do not know what attribute it will bring and I need it to be dynamic.

    
asked by anonymous 11.12.2013 / 17:49

2 answers

2

Well, let's take some guesses then to be able to show a viable code.

<?php
    $produtos['tipo1'] = [
        // Produtos tipo um
    ];

    $produtos['tipo2'] = [
        // Produtos tipo dois
    ];

    $produtos['tipo3'] = [
        // Produtos tipo três
    ];

    foreach ($produtos as $tipo => $listaProdutos): ?>

    <ol class="filters filter-<?= $tipo ?>">

        <?php foreach ($listaProdutos as $produto): ?>

            <li><?= $produto->nome ?></li>
            <li><?= $produto->descricao ?></li>
            <li><?= $produto->valor ?></li>

        <?php endforeach; ?>

    </ol>
<?php
    endforeach;
?>

Is this what I get in the head now, does it help you?

Att

    
28.12.2013 / 20:16
-3

If I understand correctly, what you want is to add a class in <li> if this filter has any product to be fetched, right?

I think it would look like this:

<li<?php echo ($_item->getCount() > 0):?' class="temitens"':'';?>>

In this way, if you have items it adds a temitens class, otherwise it does nothing.

    
13.12.2013 / 02:29