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

时间:2019-07-02 07:23:54

标签: php opencart opencart2.x opencart2.3

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

这是代码

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

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

price from second

并且数组的输出为

 Array ( [0] => Array ( [quantity] => 40 [price] => $5.00 ) [1] => Array ( [quantity] => 160 [price] => $4.00 ) [2] => Array ( [quantity] => 320 [price] => $3.90 ) [3] => Array ( [quantity] => 480 [price] => $3.50 ) ) 

,商品的后端设置为

offers

有什么方法可以显示所有优惠?

2 个答案:

答案 0 :(得分:1)

尝试运行以下内容:

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

答案 1 :(得分:1)

在此处更改

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