如何在Prestashop 1.6发票页面查看税务规则
-
21-12-2019 - |
题
我想在发票页面检查每个产品的税务规则。
是否有存储税收规则(例如 8% 或 18%)的变量?
会是这样的
{if $order_invoice->tax_rule == "18%"}
...
{/if}
解决方案
检查正确的变量
您不会在以下位置找到此数据 $order_invoice
. 。如果您想了解每种产品的税务规则,您需要检查 $order_detail
变种摘自 invoice.tpl
:
<!-- PRODUCTS -->
{foreach $order_details as $order_detail}
{cycle values='#FFF,#DDD' assign=bgcolor}
<tr style="line-height:6px;background-color:{$bgcolor};">
<!-- Here we've got one line, for one product -->
<!-- This product's datas are stored in $order_detail -->
</tr>
您可以在以下位置找到税率: $order_detail.tax_rate
. 。不幸的是,它总是回归 0.000
.
是的...该数据未填写...不开心的一天...
创建一个 OrderDetail
覆盖
创建 OrderDetail.php
文件在 override/classes/order/
文件夹,包含此代码:
class OrderDetail extends OrderDetailCore
{
/**
* Get order products
*
* @return array Products with price, quantity (with taxe and without)
*/
public function getProducts($products = false, $selectedProducts = false, $selectedQty = false)
{
if (!$products)
$products = $this->getProductsDetail();
$order = new Order($this->id_order);
$customized_datas = Product::getAllCustomizedDatas($order->id_cart);
$resultArray = array();
foreach ($products as $row)
{
// Retrieve tax rate
$product = new Product($row['product_id']);
$row['tax_rate'] = $product->getTaxesRate();
// Change qty if selected
if ($selectedQty)
{
$row['product_quantity'] = 0;
foreach ($selectedProducts as $key => $id_product)
if ($row['id_order_detail'] == $id_product)
$row['product_quantity'] = (int)($selectedQty[$key]);
if (!$row['product_quantity'])
continue;
}
$this->setProductImageInformations($row);
$this->setProductCurrentStock($row);
$this->setProductCustomizedDatas($row, $customized_datas);
// Add information for virtual product
if ($row['download_hash'] && !empty($row['download_hash']))
{
$row['filename'] = ProductDownload::getFilenameFromIdProduct((int)$row['product_id']);
// Get the display filename
$row['display_filename'] = ProductDownload::getFilenameFromFilename($row['filename']);
}
$row['id_address_delivery'] = $order->id_address_delivery;
/* Stock product */
$resultArray[(int)$row['id_order_detail']] = $row;
}
if ($customized_datas)
Product::addCustomizationPrice($resultArray, $customized_datas);
return $resultArray;
}
}
此覆盖允许我们编辑 tax_rate
价值。
我只是将这两行添加到 getProducts()
功能 :
foreach ($products as $row)
{
// Retrieve tax rate
$product = new Product($row['product_id']);
$row['tax_rate'] = $product->getTaxesRate();
// ...
}
创建一个 OrderInvoice
覆盖
创建 OrderInvoice.php
文件在 override/classes/order/
文件夹。
该类将包含 相同的代码 正如我们之前的覆盖。只需更改第一行:
<?php
class OrderInvoice extends OrderInvoiceCore
{
// Copy/Paste the same code
}
现在,您可以使用以下命令显示每种产品的税率 {$order_detail.tax_rate}
!!
(奖励)编辑您的模板
让我们更改此模板(此处: pdf/invoice.tpl
)添加“税收规则”列:
<tr style="line-height:4px;">
<!-- Remove 10% from the first column header width -->
<td style="text-align: left; background-color: #4D4D4D; color: #FFF; padding-left: 10px; font-weight: bold; width: {if !$tax_excluded_display}25%{else}35%{/if}">{l s='Product / Reference' pdf='true'}</td>
...
<!-- Add our new column header, 10% width -->
<td style="background-color: #4D4D4D; color: #FFF; text-align: right; font-weight: bold; width: 10%; white-space: nowrap;">{l s='Tax rate' pdf='true'}</td>
...
</tr>
<!-- PRODUCTS -->
{foreach $order_details as $order_detail}
{cycle values='#FFF,#DDD' assign=bgcolor}
<tr style="line-height:6px;background-color:{$bgcolor};">
<!-- Remove 10% from the first column width -->
<td style="text-align: left; width: {if !$tax_excluded_display}25%{else}35%{/if}">{$order_detail.product_name}{if isset($order_detail.product_reference) && !empty($order_detail.product_reference)} ({l s='Reference:' pdf='true'} {$order_detail.product_reference}){/if}</td>
...
<!-- Add our new column, 10% width -->
<td style="text-align: right; width: 10%; white-space: nowrap;">
{$order_detail.tax_rate}
</td>
...
</tr>
其他提示
我认为正确的方法是overtridevoice.php中的getPriducts()函数
foreach ($products as $row)
{
...
$sql = "SELECT tax.rate FROM ps_tax as tax join `ps_order_detail_tax` on ps_order_detail_tax.id_tax = tax.id_tax WHERE ps_order_detail_tax.id_order_detail = " .(int)$row['id_order_detail'] ;
$result = Db::getInstance()->executeS($sql);
$tmp = $result[0];
if (isset($tmp['rate'])){
$row['tax_rate_product'] = $tmp['rate'];
}
else { //No Tax
$row['tax_rate_product'] = "0.000";
}
...
}
.
和使用速率值.tpl
...
<td style="text-alig: right; width: 15%">{$order_detail.tax_rate_product}</td>
...
.
记住删除缓存/ class_index.php
也许您有根据装运地址的产品税规则。尝试
foreach ($products as $row)
.
{
...
// Retrieve tax rate
$product = new Product($row['product_id']);
$row['tax_rate'] = $product->getTaxesRate(new Address((int)$order->id_address_delivery))
...
. 不隶属于 StackOverflow