Domanda

Ho creato un gruppo di prodotti con due semplici prodotto products.Each semplice ha tier pricing.For esempio,

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

il codice restituisce soprattutto il qty 2 3 5 2 3.How posso rimuovere i valori "qty" ripetuti e mostrare solo valori univoci?

È stato utile?

Soluzione

@ di pspahn commento è corretta. array_unique() rimuoverà i duplicati. Nel tuo esempio di codice, potrebbe essere utilizzato in questo modo:

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

Questa 2 3 5 uscita volontà basato sul tuo esempio.

Were voi che vogliono semplicemente per visualizzare i quantità solo in questo modo?

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a magento.stackexchange
scroll top