我想检查发票页面中每个产品的税收规则。
是否存在存储税收规则的变量,例如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
覆盖
在override/classes/order/
文件夹中创建OrderDetail.php
文件,其中包含以下代码:
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
覆盖
在override/classes/order/
文件夹中创建OrderInvoice.php
文件
此类将包含与我们以前的覆盖相同的代码。只需更改第一行:
<?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>
我认为正确的方法是覆盖OrderInvoice.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>
...
请记住删除cache/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))
...