我想检查发票页面中每种产品的税收规则。
是否存在存储税收规则的变量,例如8%或18%?
就像这样
{if $order_invoice->tax_rule == "18%"}
...
{/if}
答案 0 :(得分:5)
您无法在$order_invoice
中找到此数据。如果您想获得每种产品的税收规则,则需要检查$order_detail
var。摘自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>
答案 1 :(得分:0)
我认为正确的方法是在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
答案 2 :(得分:-1)
根据发货地址,您可能有产品税规则。试试
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))
...