1

I've created a group product with two simple products.Each simple product has tier pricing.For example,

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

The above code returns all the qty 2 3 5 2 3.How do I remove the repeated "qty" values and show only unique values?

2

@pspahn's comment is correct. array_unique() will remove the duplicates. In your code example, it could be used like this:

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

This will output 2 3 5 based on your example.

Were you just wanting to display the quantities only like this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.