Opencart:查询数据库以获取tax_rate数据 [英] Opencart: Query the database to get tax_rate data

查看:115
本文介绍了Opencart:查询数据库以获取tax_rate数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在产品管理页面的价格输入附近找到一个计算器助手,我想添加一个文本框来帮助用户计算价格(不含要插入的增值税). 这类似于插件,但我需要查询数据库以获取所有税率的数组,并将其与价格下方的用户选择的tax_class_id进行比较.

I'm trying to get a calculator helper in product admin page, near the price input I want to add a textbox that helps users to calculate the price with Tax VAT exluded to insert. It's something similar to this PLUGIN but I need to query the database to get an array of all Tax Rates and compare them with the tax_class_id selected by user just below the price.

我在此页面中找到了一种请求:admin/controller/localisation/tax_rate.php

I have found a sort of request in this page: admin/controller/localisation/tax_rate.php

if (isset($this->request->post['rate'])) {
    $this->data['rate'] = $this->request->post['rate'];
} elseif (!empty($tax_rate_info)) {
    $this->data['rate'] = $tax_rate_info['rate'];
} else {
    $this->data['rate'] = '';
}

但是我不知道如何查询数据库并在页面admin/view/template/catalog/product_form.tpl中获取数据. 我正在尝试获得与Prestashop的价格管理类似的结果.

But I have no idea how to query the database and get the data inside the page admin/view/template/catalog/product_form.tpl. I'm trying to get a result similar to Prestashop's price management.

请给我一些帮助!

我用在getForm()函数内的admin/controller/catalog/product.php中添加的以下代码解决了这个问题:

I solved with this code added in admin/controller/catalog/product.php placed inside getForm() function:

$sql = 'SELECT tra.rate, tra.type, tru.tax_class_id FROM '.DB_PREFIX.'tax_rate tra LEFT JOIN '.DB_PREFIX.'tax_rule tru ON tru.tax_rate_id = tra.tax_rate_id WHERE tru.tax_class_id IS NOT NULL' ;
$query = $this->db->query($sql);
$rates = array();
foreach($query->rows as $result){
    $rates[] = $result;
}
$this->data['rates'] = $rates;

感谢所有参与者

推荐答案

要获取费率列表,请使用以下代码:

To get list of rates, use this code:

// get tax rates
$sql = 'SELECT * FROM '.DB_PREFIX.'tax_rate ';
$query = $this->db->query($sql);
$rates = array();
foreach($query->rows as $result){
    $rates[] = $result;
}

输出:

Array
(
[0] => Array
    (
        [tax_rate_id] => 86
        [geo_zone_id] => 3
        [name] => VAT (17.5%)
        [rate] => 17.5000
        [type] => P
        [date_added] => 2011-03-09 21:17:10
        [date_modified] => 2011-09-22 22:24:29
    )

[1] => Array
    (
        [tax_rate_id] => 87
        [geo_zone_id] => 3
        [name] => Eco Tax (-2.00)
        [rate] => 2.0000
        [type] => F
        [date_added] => 2011-09-21 21:49:23
        [date_modified] => 2011-09-23 00:40:19
    )

)

上面的代码在控制器中.要将数据传递到模板,请使用类似以下内容:

The code above goes in the controller. To pass data to template use something like:

$this->data['rates'] = $rates;

然后可以通过$rates在视图中访问此数据. 很抱歉没有从一开始就澄清这一点.换句话说,$this->data保留视图的所有变量:$this->data['foo']在模板文件(视图)中变为$foo.

Then this data will be accessible in view through $rates. Sorry for not clarifying this from the start. In other words, $this->data holds all variables for the view: $this->data['foo'] becomes $foo in the template file (view).

这篇关于Opencart:查询数据库以获取tax_rate数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆