Tier Quantity minus 1
-
13-12-2019 - |
Question
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>
Solution
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 } ?>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange