Frage

Ich habe ein Gruppenprodukt mit zwei einfachen Produkten erstellt. Das einfache Produkt hat eine stufe Preisgestaltung. Zum Beispiel, zum Beispiel,

Simple product -1: tier pricing : Qty   Price
                                   2     100
                                   3      75
                                   5      60

Simple product -2: tier pricing:  Qty   Price
                                   2     110
                                   3      80


<?php if ($_hasAssociatedProducts): ?>
    <?php foreach ($_associatedProducts as $_items): ?> 
        <?php $_items->setData('tier_price',null); ?>
        <?php $_tierPrices = $this->getTierPrices($_items); ?>
            <?php foreach ($_tierPrices as $key => $value): ?>
                <th><?php echo $value['price_qty']; ?></th>
            <?php endforeach; ?>
    <?php endforeach; ?>
<?php endif; ?>

Der obige Code gibt alle Qty zurück 2 3 5 2 3Wie entferne ich die wiederholten "Qty" -Werte und zeige nur eindeutige Werte?

War es hilfreich?

Lösung

@Pspahns Kommentar ist korrekt. array_unique() Entfernen Sie die Duplikate. In Ihrem Code -Beispiel könnte es so verwendet werden:

<?php if ($_hasAssociatedProducts): ?>
    <?php $qtys = array(); 
          foreach ($_associatedProducts as $_items): ?> 
        <?php $_items->setData('tier_price',null); ?>
        <?php $_tierPrices = $this->getTierPrices($_items); ?>
            <?php foreach ($_tierPrices as $key => $value): ?>
                <?php $qtys[] = $value['price_qty']; ?>
            <?php endforeach; ?>
    <?php endforeach;
          array_unique($qtys); ?>
    <?php for ($i=0;$i<count($qtys);$i++): ?>
        <th><?php echo $qtys[$i]; ?></th>
    <?php endfor; ?>
<?php endif; ?>

Dies wird ausgeben 2 3 5 Basierend auf Ihrem Beispiel.

Wollten Sie nur die Mengen nur so anzeigen?

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit magento.stackexchange
scroll top