Prestashop-如何在AdminOrdersController.php中添加应付金额

huangapple go评论66阅读模式
英文:

Prestashop- How to add Amount Due in AdminOrdersController.php

问题

我的Prestashop版本是1.7.5
我想要在AdminOrdersController中添加应付金额的值。应付金额可以使用('total_paid_tax_incl' - 'total_paid_real')来计算。

所以我将它修改为这样

'total_paid_tax_incl' - 'total_paid_real' => array(
    'title' => $this->trans('Amount Due', array(), 'Admin.Global'),
    'align' => 'text-right',
    'type' => 'price',
    'currency' => true,
    'badge_success' => true,
),

但是它会抛出一个错误,警告:遇到非数字值。
尽管'value' 'total_paid_tax_incl'和'total_paid_real'都是decimal(20,6)类型的。

英文:

My Prestashop version is 1.7.5
I wanted to add the amount due value in the AdminOrdersController. Amount due value can be calculated using ('total_paid_tax_incl'-'total_paid_real')

		'total_paid_real' => array(
			'title' => $this->trans('Real Paid', array(), 'Admin.Global'),
			'align' => 'text-right',
			'type' => 'price',
			'currency' => true,
			'badge_success' => true,
		),

So I modified it like this

		'total_paid_tax_incl'-'total_paid_real' => array(
			'title' => $this->trans('Amount Due', array(), 'Admin.Global'),
			'align' => 'text-right',
			'type' => 'price',
			'currency' => true,
			'badge_success' => true,
		),

But It is throwing an error, Warning: A non-numeric value encountered.
Though both value 'total_paid_tax_incl' & 'total_paid_real' are in decimal(20,6)

Can you guys help me to solve the issue?

答案1

得分: 1

在生成订单列表的SQL查询中,您需要添加一个自定义字段,然后使用该字段。

在AdminOrdersController构造函数中添加以下代码:

$this->_select .= ' a.total_paid_tax_incl-a.total_paid_real as `due_value'`;

就在$this->_select = '<default query>'之后添加。

这将允许您在定义列表中显示的列时使用due_value变量:

'due_value' => array(
    'title' => $this->trans('Amount Due', array(), 'Admin.Global'),
    'align' => 'text-right',
    'type' => 'price',
    'currency' => true,
    'badge_success' => true,
    'havingFilter' => true
),

请注意,我添加了havingFilter参数,因为它不是数据库中的标准字段,而是在运行时创建的。

英文:

You need to add a custom field to the SQL query that generates the order list and then use that field.

In the AdminOrdersController constructor, add

$this-&gt;_select .= &#39; a.total_paid_tax_incl-a.total_paid_real as `due_value`&#39;;

Right after $this-&gt;_select = &#39;&lt;default query&gt;&#39;;

This will allow you to use the due_value variable when defining the columns displayed in the list

&#39;due_value&#39; =&gt; array(
             &#39;title&#39; =&gt; $this-&gt;trans(&#39;Amount Due&#39;, array(), &#39;Admin.Global&#39;),
             &#39;align&#39; =&gt; &#39;text-right&#39;,
             &#39;type&#39; =&gt; &#39;price&#39;,
             &#39;currency&#39; =&gt; true,
             &#39;badge_success&#39; =&gt; true,
             &#39;havingFilter&#39; =&gt; true
         ),

Note that I added the havingFilter parameter, because it is not a standard field in the database, but created "on the fly".

huangapple
  • 本文由 发表于 2023年6月1日 17:11:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/76380346.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定