有两种不同数量和价格的产品
simple product -1 : qty price
2 150
3 145
5 130
10 100
simple product -2 : qty price
2 195
5 175
9 170
我想以以下格式显示数量和价格:
qty : 2 3 5 9 10
$150 $145 $130 - $100
$195 - $175 $170 -
下面是显示价格和数量的代码
/*
$_tResult = [2, 3, 5, 9, 2, 5, 10]
*/
/*
$_tierPrice value
array(10) {
["price_id"] => string(2) "18"
["website_id"] => string(1) "0"
["all_groups"] => string(1) "1"
["cust_group"] => int(32000)
["price"] => string(8) "150.0000"
["price_qty"] => float(2)
["website_price"] => string(8) "150.0000"
["formated_price"] => string(34) "150.00"
["savePercent"] => float(4)
["formated_price_incl_tax"] => string(34) "150.00"
}
array(10) {
["price_id"] => string(2) "65"
["website_id"] => string(1) "0"
["all_groups"] => string(1) "1"
["cust_group"] => int(32000)
["price"] => string(8) "120.0000"
["price_qty"] => float(3)
["website_price"] => string(8) "120.0000"
["formated_price"] => string(34) "120.00"
["savePercent"] => float(23)
["formated_price_incl_tax"] => string(34) "120.00"
}
array(10) {
["price_id"] => string(2) "61"
["website_id"] => string(1) "0"
["all_groups"] => string(1) "1"
["cust_group"] => int(32000)
["price"] => string(8) "145.0000"
["price_qty"] => float(5)
["website_price"] => string(8) "145.0000"
["formated_price"] => int(5) "145.00"
["savePercent"] => float(7)
["formated_price_incl_tax"] => string(34) "145.00"
}
array(10) {
["price_id"] => string(2) "62"
["website_id"] => string(1) "0"
["all_groups"] => string(1) "1"
["cust_group"] => int(32000)
["price"] => string(8) "130.0000"
["price_qty"] => float(9)
["website_price"] => string(8) "130.0000"
["formated_price"] => int(5) "130.00"
["savePercent"] => float(17)
["formated_price_incl_tax"] => string(34) "130.00"
}
array(10) {
["price_id"] => string(2) "47"
["website_id"] => string(1) "0"
["all_groups"] => string(1) "1"
["cust_group"] => int(32000)
["price"] => string(8) "190.0000"
["price_qty"] => float(2)
["website_price"] => string(8) "190.0000"
["formated_price"] => int(5) "190.00"
["savePercent"] => float(5)
["formated_price_incl_tax"] => string(34) "190.00"
}
array(10) {
["price_id"] => string(2) "63"
["website_id"] => string(1) "0"
["all_groups"] => string(1) "1"
["cust_group"] => int(32000)
["price"] => string(8) "175.0000"
["price_qty"] => float(5)
["website_price"] => string(8) "175.0000"
["formated_price"] => int(5) "175.00"
["savePercent"] => float(13)
["formated_price_incl_tax"] => string(34) "175.00"
}
array(10) {
["price_id"] => string(2) "64"
["website_id"] => string(1) "0"
["all_groups"] => string(1) "1"
["cust_group"] => int(32000)
["price"] => string(8) "195.0000"
["price_qty"] => float(9)
["website_price"] => string(8) "195.0000"
["formated_price"] => int(5) "195.00"
["savePercent"] => float(3)
["formated_price_incl_tax"] => string(34) "195.00"
}
array(10) {
["price_id"] => string(2) "44"
["website_id"] => string(1) "0"
["all_groups"] => string(1) "1"
["cust_group"] => int(32000)
["price"] => string(8) "170.0000"
["price_qty"] => float(10)
["website_price"] => string(8) "170.0000"
["formated_price"] => int(5) "170.00"
["savePercent"] => float(15)
["formated_price_incl_tax"] => string(34) "170.00"
}
*/
<?php $_item->setData('tier_price',null); ?>
<?php $_tierPrices = $this->getTierPrices($_item); ?>
<?php //print_r($_tResult); ?>
<?php foreach ($_tierPrices as $price): ?>
<td>
<?php if(in_array($price['price_qty'],$_tResult)) :?>
<?php echo $price['formated_price']; ?>
<?php else: ?>
<?php echo "-"; ?>
<?php endif; ?>
</td>
<?php endforeach; ?>
下面是代码的实际输出。
qty : 2 3 5 9 10
$150 $145 $130 $100
$195 $175 $170
数组中没有价格值时如何添加“-”