我已经创建了一个使用两个简单产品的组产品。每个简单的产品具有层次定价。例如

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

以上代码返回所有数量 2 3 5 2 3我如何删除重复的“数量”值并仅显示唯一值?

有帮助吗?

解决方案

@pspahn的评论是正确的。 array_unique() 将删除重复项。在您的代码示例中,可以这样使用:

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

这将输出 2 3 5 根据您的示例。

您只是想像这样显示数量吗?

许可以下: CC-BY-SA归因
scroll top