質問

請求書ページで各商品の税金ルールを確認したい。

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 価値。
これらの 2 行を単に追加しただけです 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>

他のヒント

正しい方法はgetPriducts()関数をOrderinVoice.php

でオーバーライドすることだと思います
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

のrate値を使用する
...
<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))
 ...
.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top