1

enter image description here

I am trying to get the "-1" to show as "5" which would be 1 less than the 6-9 quantity.

My code...

            <?php
            $_product = $this->getProduct();
            $_tierPrices = $this->getTierPrices();
            if (count($_tierPrices) > 0):
                $_data = array();
                $_prevQty = 0;
                $_counter = 0;
                $_tierPrices = array_reverse($_tierPrices);
                foreach ($_tierPrices as $_index => $_price){
                    $_counter++;
                    if($_price['price_qty']>$_prevQty){
                        $label = $_price['price_qty']. '+';
                        $_data[] = array('prev'=>$_prevQty,'next'=>$_price['price_qty'],'label'=>$label,'price'=>$_price['formated_price'],'save'=>$_price['savePercent']);
                        $_prevQty = $_price['price_qty']-1;
                    } else {
                        $label = $_price['price_qty'] . '-' . $_prevQty;
                        $_data[] = array('prev'=>$_prevQty,'next'=>$_price['price_qty'],'label'=>$label,'price'=>$_price['formated_price'],'save'=>$_price['savePercent']);
                        $_prevQty = $_price['price_qty']-1;

                    }
                }
                $_data = array_reverse($_data);

            ?>
<?php $calculate=intval($_row['label'])-1; ?>
                <table width="100%"  align="center" cellpadding="0" cellspacing="0" class="tiered-pricing">
                    <tbody align="center">
                        <tr>
                            <td width="34%" align="center"><b>Quantity</b></td>
                            <td width="33%" align="center"><b>Price</b></td>
                            <td width="33%" align="center"><b>Save</b></td>
                        </tr>

<td><?php echo "1-".$calculate ?></td>
<td><?php echo $this->getPriceHtml($_product, true) ?></td>
<td>--</td>
                    <?php foreach ($_data as $_row): ?>
                        <tr>

                            <td><?php echo $_row['label']; ?></td>
                            <td><?php echo $_row['price']; ?></td>
                            <td><?php echo $_row['save']."%"; ?></td>
                        </tr>
<?php endforeach; ?>
                        <tr>
                          <td colspan="3" height="30px"><i>*Prices will reflect in cart.</i></td>
                        </tr>


                    </tbody>
                </table>
            <?php
            endif;
            ?>
            <!-- Display product tier price -->



    </div>
2
  • Is $_row defined in the $calculate assignment? If not, it could be returning false, which would cause int_val to return 0.
    – travisw
    Commented Jul 13, 2015 at 20:29
  • i am not too sure.. my php skills are minimal at best Commented Jul 13, 2015 at 20:34

1 Answer 1

1

Try this:

<?php $tierFirstQty = number_format($_tierPrices[0]['price_qty']);
if($tierFirstQty > 1) { 
    $newQty = $tierFirstQty - 1; ?>
    <td><?php echo "1-".$newQty?></td>
    <td><?php echo $this->getPriceHtml($_product, true) ?></td>
    <td>--</td>
<?php } ?>
1
  • Glad I could help! You should update this question too to help any future visitors who might end up there instead of here.
    – travisw
    Commented Jul 14, 2015 at 14:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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