在产品页面 opencart 2 中显示所有折扣代码

displaying all discount code in product page opencart 2

我想在产品页面显示我所有的折扣优惠,我在后端总共有 5 个优惠

这是代码

    <?php foreach ($discounts as $discount) { ?>
    <?php echo $discount['quantity']; ?><?php echo $text_discount; ?><?php echo $discount['price']; ?><br />
    <?php } ?

但结果是第一个报价被忽略了,它从第二个值开始

数组的输出是

 Array ( [0] => Array ( [quantity] => 40 [price] => .00 ) [1] => Array ( [quantity] => 160 [price] => .00 ) [2] => Array ( [quantity] => 320 [price] => .90 ) [3] => Array ( [quantity] => 480 [price] => .50 ) ) 

优惠的后端设置是

有什么方法可以显示所有报价吗?

尝试运行以下操作:

<html>
<head></head>
<body>

<-- Other html code -->

<?php
   foreach($discounts as $discount) {
       echo $discount['quantity'] . ' or more '. $discount['price'] .'<br>';   
   }
?>

<-- Other html code -->

</body>
</html>

在此处更改

public function getProductDiscounts($product_id) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$product_id . "' AND customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "' AND quantity >= 0 AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY quantity ASC, priority ASC, price ASC");

return $query->rows;

}

请将AND quantity > 1改为AND quantity >= 0