Php Opencart 2.3-在特色扩展中显示折扣

Php Opencart 2.3-在特色扩展中显示折扣,php,opencart,opencart2.x,opencart2.3,Php,Opencart,Opencart2.x,Opencart2.3,我是Opencart的新手,我试图在特色产品中显示数量折扣,但没有成功。我正在使用Opencart 2.3。基本上,我想要实现的是将变量quantity和price从控制器文件featured.php传递到视图文件featured.tpl 以下是我尝试过的: 1) 在文件/catalog/controller/extension/module/featured.php中$product\u info=$this->model\u catalog\u product->getProduct($pr

我是Opencart的新手,我试图在特色产品中显示数量折扣,但没有成功。我正在使用Opencart 2.3。基本上,我想要实现的是将变量
quantity
price
从控制器文件
featured.php
传递到视图文件
featured.tpl

以下是我尝试过的:

1) 在文件
/catalog/controller/extension/module/featured.php中
$product\u info=$this->model\u catalog\u product->getProduct($product\u id)后面的
我添加了以下代码:

$discounts = $this->model_catalog_product->getProductDiscounts($product_id);

$data['discounts'][] = array();

foreach ($discounts as $discount) {
    $data['discounts'][] = array(
'quantity' => $discount['quantity'],
'price' => $discount['price']
);
}
<?php foreach ($discounts as $discount) { ?>
<span>
<?php echo sprintf($text_discount, $discount['quantity'], $discount['price']); ?>
</span><br>
<?php } ?>
$_['text_discount']            = ' or more ';
2) 在文件
/catalog/view/theme/default/template/extension/module/featured.tpl
中,我添加了以下代码:

$discounts = $this->model_catalog_product->getProductDiscounts($product_id);

$data['discounts'][] = array();

foreach ($discounts as $discount) {
    $data['discounts'][] = array(
'quantity' => $discount['quantity'],
'price' => $discount['price']
);
}
<?php foreach ($discounts as $discount) { ?>
<span>
<?php echo sprintf($text_discount, $discount['quantity'], $discount['price']); ?>
</span><br>
<?php } ?>
$_['text_discount']            = ' or more ';


任何帮助都将不胜感激


我尝试了其他几种代码变体(例如提供的解决方案),但没有成功。

转到catalog\language\en gb\extension\module\featured.php 添加以下代码:

$discounts = $this->model_catalog_product->getProductDiscounts($product_id);

$data['discounts'][] = array();

foreach ($discounts as $discount) {
    $data['discounts'][] = array(
'quantity' => $discount['quantity'],
'price' => $discount['price']
);
}
<?php foreach ($discounts as $discount) { ?>
<span>
<?php echo sprintf($text_discount, $discount['quantity'], $discount['price']); ?>
</span><br>
<?php } ?>
$_['text_discount']            = ' or more ';
转到catalog\controller\extension\module\featured.php 查找以下代码行:

$data['heading_title'] = $this->language->get('heading_title');
$data['text_discount'] = $this->language->get('text_discount');
foreach ($products as $product_id) {
   $product_info = $this->model_catalog_product->getProduct($product_id);
$discounts = $this->model_catalog_product->getProductDiscounts($product_id);

            $product_info['discounts'] = array();

            foreach ($discounts as $discount) {
                $product_info['discounts'][] = array(
                    'quantity' => $discount['quantity'],
                    'price'    => $this->currency->format($this->tax->calculate($discount['price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency'])
                );
            }
$data['products'][] = array(
                    'product_id' => $product_info['product_id'],
'discounts'=>$product_info['discounts'],
 <div class="button-group">
            <button type="button" onclick="cart.add('<?php echo $product['product_id']; ?>');">
添加以下代码行:

$data['heading_title'] = $this->language->get('heading_title');
$data['text_discount'] = $this->language->get('text_discount');
foreach ($products as $product_id) {
   $product_info = $this->model_catalog_product->getProduct($product_id);
$discounts = $this->model_catalog_product->getProductDiscounts($product_id);

            $product_info['discounts'] = array();

            foreach ($discounts as $discount) {
                $product_info['discounts'][] = array(
                    'quantity' => $discount['quantity'],
                    'price'    => $this->currency->format($this->tax->calculate($discount['price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency'])
                );
            }
$data['products'][] = array(
                    'product_id' => $product_info['product_id'],
'discounts'=>$product_info['discounts'],
 <div class="button-group">
            <button type="button" onclick="cart.add('<?php echo $product['product_id']; ?>');">
查找以下代码行:

$data['heading_title'] = $this->language->get('heading_title');
$data['text_discount'] = $this->language->get('text_discount');
foreach ($products as $product_id) {
   $product_info = $this->model_catalog_product->getProduct($product_id);
$discounts = $this->model_catalog_product->getProductDiscounts($product_id);

            $product_info['discounts'] = array();

            foreach ($discounts as $discount) {
                $product_info['discounts'][] = array(
                    'quantity' => $discount['quantity'],
                    'price'    => $this->currency->format($this->tax->calculate($discount['price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency'])
                );
            }
$data['products'][] = array(
                    'product_id' => $product_info['product_id'],
'discounts'=>$product_info['discounts'],
 <div class="button-group">
            <button type="button" onclick="cart.add('<?php echo $product['product_id']; ?>');">
添加以下代码行:

$data['heading_title'] = $this->language->get('heading_title');
$data['text_discount'] = $this->language->get('text_discount');
foreach ($products as $product_id) {
   $product_info = $this->model_catalog_product->getProduct($product_id);
$discounts = $this->model_catalog_product->getProductDiscounts($product_id);

            $product_info['discounts'] = array();

            foreach ($discounts as $discount) {
                $product_info['discounts'][] = array(
                    'quantity' => $discount['quantity'],
                    'price'    => $this->currency->format($this->tax->calculate($discount['price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency'])
                );
            }
$data['products'][] = array(
                    'product_id' => $product_info['product_id'],
'discounts'=>$product_info['discounts'],
 <div class="button-group">
            <button type="button" onclick="cart.add('<?php echo $product['product_id']; ?>');">
查找以下代码行:

$data['heading_title'] = $this->language->get('heading_title');
$data['text_discount'] = $this->language->get('text_discount');
foreach ($products as $product_id) {
   $product_info = $this->model_catalog_product->getProduct($product_id);
$discounts = $this->model_catalog_product->getProductDiscounts($product_id);

            $product_info['discounts'] = array();

            foreach ($discounts as $discount) {
                $product_info['discounts'][] = array(
                    'quantity' => $discount['quantity'],
                    'price'    => $this->currency->format($this->tax->calculate($discount['price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency'])
                );
            }
$data['products'][] = array(
                    'product_id' => $product_info['product_id'],
'discounts'=>$product_info['discounts'],
 <div class="button-group">
            <button type="button" onclick="cart.add('<?php echo $product['product_id']; ?>');">
在其下方添加以下代码行:

$data['heading_title'] = $this->language->get('heading_title');
$data['text_discount'] = $this->language->get('text_discount');
foreach ($products as $product_id) {
   $product_info = $this->model_catalog_product->getProduct($product_id);
$discounts = $this->model_catalog_product->getProductDiscounts($product_id);

            $product_info['discounts'] = array();

            foreach ($discounts as $discount) {
                $product_info['discounts'][] = array(
                    'quantity' => $discount['quantity'],
                    'price'    => $this->currency->format($this->tax->calculate($discount['price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency'])
                );
            }
$data['products'][] = array(
                    'product_id' => $product_info['product_id'],
'discounts'=>$product_info['discounts'],
 <div class="button-group">
            <button type="button" onclick="cart.add('<?php echo $product['product_id']; ?>');">
现在转到catalog\view\theme\YOUR\u ACTIVE\u theme\template\extension\module\featured.tpl

查找以下代码行:

$data['heading_title'] = $this->language->get('heading_title');
$data['text_discount'] = $this->language->get('text_discount');
foreach ($products as $product_id) {
   $product_info = $this->model_catalog_product->getProduct($product_id);
$discounts = $this->model_catalog_product->getProductDiscounts($product_id);

            $product_info['discounts'] = array();

            foreach ($discounts as $discount) {
                $product_info['discounts'][] = array(
                    'quantity' => $discount['quantity'],
                    'price'    => $this->currency->format($this->tax->calculate($discount['price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency'])
                );
            }
$data['products'][] = array(
                    'product_id' => $product_info['product_id'],
'discounts'=>$product_info['discounts'],
 <div class="button-group">
            <button type="button" onclick="cart.add('<?php echo $product['product_id']; ?>');">


转到catalog\language\en gb\extension\module\featured.php 添加以下代码:

$discounts = $this->model_catalog_product->getProductDiscounts($product_id);

$data['discounts'][] = array();

foreach ($discounts as $discount) {
    $data['discounts'][] = array(
'quantity' => $discount['quantity'],
'price' => $discount['price']
);
}
<?php foreach ($discounts as $discount) { ?>
<span>
<?php echo sprintf($text_discount, $discount['quantity'], $discount['price']); ?>
</span><br>
<?php } ?>
$_['text_discount']            = ' or more ';
转到catalog\controller\extension\module\featured.php 查找以下代码行:

$data['heading_title'] = $this->language->get('heading_title');
$data['text_discount'] = $this->language->get('text_discount');
foreach ($products as $product_id) {
   $product_info = $this->model_catalog_product->getProduct($product_id);
$discounts = $this->model_catalog_product->getProductDiscounts($product_id);

            $product_info['discounts'] = array();

            foreach ($discounts as $discount) {
                $product_info['discounts'][] = array(
                    'quantity' => $discount['quantity'],
                    'price'    => $this->currency->format($this->tax->calculate($discount['price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency'])
                );
            }
$data['products'][] = array(
                    'product_id' => $product_info['product_id'],
'discounts'=>$product_info['discounts'],
 <div class="button-group">
            <button type="button" onclick="cart.add('<?php echo $product['product_id']; ?>');">
添加以下代码行:

$data['heading_title'] = $this->language->get('heading_title');
$data['text_discount'] = $this->language->get('text_discount');
foreach ($products as $product_id) {
   $product_info = $this->model_catalog_product->getProduct($product_id);
$discounts = $this->model_catalog_product->getProductDiscounts($product_id);

            $product_info['discounts'] = array();

            foreach ($discounts as $discount) {
                $product_info['discounts'][] = array(
                    'quantity' => $discount['quantity'],
                    'price'    => $this->currency->format($this->tax->calculate($discount['price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency'])
                );
            }
$data['products'][] = array(
                    'product_id' => $product_info['product_id'],
'discounts'=>$product_info['discounts'],
 <div class="button-group">
            <button type="button" onclick="cart.add('<?php echo $product['product_id']; ?>');">
查找以下代码行:

$data['heading_title'] = $this->language->get('heading_title');
$data['text_discount'] = $this->language->get('text_discount');
foreach ($products as $product_id) {
   $product_info = $this->model_catalog_product->getProduct($product_id);
$discounts = $this->model_catalog_product->getProductDiscounts($product_id);

            $product_info['discounts'] = array();

            foreach ($discounts as $discount) {
                $product_info['discounts'][] = array(
                    'quantity' => $discount['quantity'],
                    'price'    => $this->currency->format($this->tax->calculate($discount['price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency'])
                );
            }
$data['products'][] = array(
                    'product_id' => $product_info['product_id'],
'discounts'=>$product_info['discounts'],
 <div class="button-group">
            <button type="button" onclick="cart.add('<?php echo $product['product_id']; ?>');">
添加以下代码行:

$data['heading_title'] = $this->language->get('heading_title');
$data['text_discount'] = $this->language->get('text_discount');
foreach ($products as $product_id) {
   $product_info = $this->model_catalog_product->getProduct($product_id);
$discounts = $this->model_catalog_product->getProductDiscounts($product_id);

            $product_info['discounts'] = array();

            foreach ($discounts as $discount) {
                $product_info['discounts'][] = array(
                    'quantity' => $discount['quantity'],
                    'price'    => $this->currency->format($this->tax->calculate($discount['price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency'])
                );
            }
$data['products'][] = array(
                    'product_id' => $product_info['product_id'],
'discounts'=>$product_info['discounts'],
 <div class="button-group">
            <button type="button" onclick="cart.add('<?php echo $product['product_id']; ?>');">
查找以下代码行:

$data['heading_title'] = $this->language->get('heading_title');
$data['text_discount'] = $this->language->get('text_discount');
foreach ($products as $product_id) {
   $product_info = $this->model_catalog_product->getProduct($product_id);
$discounts = $this->model_catalog_product->getProductDiscounts($product_id);

            $product_info['discounts'] = array();

            foreach ($discounts as $discount) {
                $product_info['discounts'][] = array(
                    'quantity' => $discount['quantity'],
                    'price'    => $this->currency->format($this->tax->calculate($discount['price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency'])
                );
            }
$data['products'][] = array(
                    'product_id' => $product_info['product_id'],
'discounts'=>$product_info['discounts'],
 <div class="button-group">
            <button type="button" onclick="cart.add('<?php echo $product['product_id']; ?>');">
在其下方添加以下代码行:

$data['heading_title'] = $this->language->get('heading_title');
$data['text_discount'] = $this->language->get('text_discount');
foreach ($products as $product_id) {
   $product_info = $this->model_catalog_product->getProduct($product_id);
$discounts = $this->model_catalog_product->getProductDiscounts($product_id);

            $product_info['discounts'] = array();

            foreach ($discounts as $discount) {
                $product_info['discounts'][] = array(
                    'quantity' => $discount['quantity'],
                    'price'    => $this->currency->format($this->tax->calculate($discount['price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency'])
                );
            }
$data['products'][] = array(
                    'product_id' => $product_info['product_id'],
'discounts'=>$product_info['discounts'],
 <div class="button-group">
            <button type="button" onclick="cart.add('<?php echo $product['product_id']; ?>');">
现在转到catalog\view\theme\YOUR\u ACTIVE\u theme\template\extension\module\featured.tpl

查找以下代码行:

$data['heading_title'] = $this->language->get('heading_title');
$data['text_discount'] = $this->language->get('text_discount');
foreach ($products as $product_id) {
   $product_info = $this->model_catalog_product->getProduct($product_id);
$discounts = $this->model_catalog_product->getProductDiscounts($product_id);

            $product_info['discounts'] = array();

            foreach ($discounts as $discount) {
                $product_info['discounts'][] = array(
                    'quantity' => $discount['quantity'],
                    'price'    => $this->currency->format($this->tax->calculate($discount['price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency'])
                );
            }
$data['products'][] = array(
                    'product_id' => $product_info['product_id'],
'discounts'=>$product_info['discounts'],
 <div class="button-group">
            <button type="button" onclick="cart.add('<?php echo $product['product_id']; ?>');">


太神了谢谢!你帮我省了很多工作:)太棒了!谢谢!你帮我省了很多工作:)