【问题标题】:Display Dedicated IP into viewinvoice.tpl and invoicepdf.tpl in WHMCS?在 WHMCS 中的 viewinvoice.tpl 和 invoicepdf.tpl 中显示专用 IP?
【发布时间】:2018-03-07 22:32:13
【问题描述】:

嗨堆栈我有一个不知道如何解决的问题。我想从客户订单中显示专用 IP,如下所示:

我做了一个简短的检查,发现需要在 viewinvoice.tplinvoicepdf.tpl 文件中完成。我发现专用 ip 存储在数据库中的 tblhosting 表中。

我找到了这段代码:

{php}
$clienthosting = $this->get_template_vars(service);
$dbid = $clienthosting['id'];  
$query = mysql_query("SELECT dedicatedip FROM tblhosting WHERE id = $dbid");  
$result = mysql_fetch_array($query); 
$dedicatedip = $result["dedicatedip"];   
$this->assign("dedicatedip", $dedicatedip); 
{/php} 

最后打印出来:

           <td>{if $dedicatedip gt 0} - {$dedicatedip}{/if}{/if}</td>

这是来自 invoice.tpl 的代码,其中打印来自客户购买的数据:

<tbody>
                            {foreach from=$invoiceitems item=item}
                                <tr>
                                    <td>{$item.description}{if $item.taxed eq "true"} *{/if}</td>
                                    <td class="text-center">{$item.amount}</td>
                                </tr>
                            {/foreach}



                            <tr>
                                <td class="total-row text-right"><strong>{$LANG.invoicessubtotal}</strong></td>
                                <td class="total-row text-center">{$subtotal}</td>
                            </tr>
                            {if $taxrate}
                                <tr>
                                    <td class="total-row text-right"><strong>{$taxrate}% {$taxname}</strong></td>
                                    <td class="total-row text-center">{$tax}</td>
                                </tr>
                            {/if}
                            {if $taxrate2}
                                <tr>
                                    <td class="total-row text-right"><strong>{$taxrate2}% {$taxname2}</strong></td>
                                    <td class="total-row text-center">{$tax2}</td>
                                </tr>
                            {/if}
                            <tr>
                                <td class="total-row text-right"><strong>{$LANG.invoicescredit}</strong></td>
                                <td class="total-row text-center">{$credit}</td>
                            </tr>
                            <tr>
                                <td class="total-row text-right"><strong>{$LANG.invoicestotal}</strong></td>
                                <td class="total-row text-center">{$total}</td>
                            </tr>
                        </tbody>

但这似乎只有在尝试执行时才会产生白屏。这里有什么帮助吗?

【问题讨论】:

    标签: whmcs whmcs-invoice-template


    【解决方案1】:

    whmcs_dir/includes/hooks/中创建php文件(比如:dedicated_ip.php)并添加以下代码:

    <?php
    use WHMCS\Database\Capsule as DB;
    add_hook('ClientAreaPageViewInvoice', 1, function($vars) { 
        $dedicatedIps = [];
    
        foreach ($vars['invoiceitems'] as $k => $item) {
            $ip = '';
            if ($item['type'] == 'Hosting') {
                $hosting = DB::table('tblhosting')->select('dedicatedip')->where('id', $item['relid'])->first();
                if (!is_null($hosting)) {
                    $ip = $hosting->dedicatedip;
                }
            } 
            $dedicatedIps[$k] = $ip;
    
        }
        return ['dedicatedIps' => $dedicatedIps];
    });
    

    此代码将仅在发票视图页面中运行,并为每个发票项目添加一组专用 IP。例如,域将有空 ip。

    然后在 viewinvoice.tpl 中更新发票项目循环如下:

    {foreach from=$invoiceitems item=item key=key}
        <tr>
            <td>
            {$item.description}{if $item.taxed eq "true"} *{/if}
            {if $key|in_array:$dedicatedIps}
            <br>IP: {$dedicatedIps[$key]}
    
            {/if}
            </td>
            <td class="text-center">{$item.amount}</td>
        </tr>
    {/foreach}
    

    【讨论】:

    • 您好,您的回答似乎有效,但是当尝试查看发票时,不要为所有订单显示专用 IP。请参见图片。大多数订单都有专用 IP,但在尝试查看发票时未显示在发票中看。 i.imgur.com/5t0QZXa.png
    • 我给了你大致的思路,你有起点,使用 error_log(print_r($item, true), 3, DIR.'/file 。日志');检查是否给出了 ip。
    • 在 if(...) 内的钩环中
    • 将 {if $key|in_array:$dedicatedIps} 更改为 {if $key|in_array:$dedicatedIps && $dedicatedIps[$key] != ''}
    • 在 phpmyadmin 中运行 SELECT DISTINCT(type) from tblinvoiceitems 并让我知道输出
    猜你喜欢
    • 2023-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多