对 prestashop PDF 生成过程感到困惑.处理逻辑的代码在哪里? [英] Confused about prestashop PDF generated process. Where is the code to handle the logic?

查看:70
本文介绍了对 prestashop PDF 生成过程感到困惑.处理逻辑的代码在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想深入了解prestahop里面的结构,修改一些部分.我停在 PDF 中.我想找不到用于处理 AdminPdfgenerateDeliverySlipPDF

I want to deep understand prestahop inside structure and amend some parts. I am stoped in the PDF. I want can't find the controller used to handle the AdminPdf and generateDeliverySlipPDF

    {if $order->delivery_number}
      <a class="btn btn-default _blank" href="{$link->getAdminLink('AdminPdf')|escape:'html':'UTF-8'}&amp;submitAction=generateDeliverySlipPDF&amp;id_order={$order->id}">
      <i class="icon-truck"></i>
    </a>
   {/if}

谁能帮我弄清楚内部流程?我找不到处理 generateDeliverySlipPDF 的方法.

Who can help me figure out the inside processes? I can't find the methods to handle generateDeliverySlipPDF.

推荐答案

AdminPdfController 位于 /controllers/admin/AdminPdfController.php.

url 的 submitAction=generateDeliverySlipPDF 部分将调用此控制器内的方法 processGenerateDeliverySlipPDF().

The submitAction=generateDeliverySlipPDF part of the url will call the method processGenerateDeliverySlipPDF() inside this controller.

这是这个方法:

public function processGenerateDeliverySlipPDF()
{
    if (Tools::isSubmit('id_order')) {
        $this->generateDeliverySlipPDFByIdOrder((int)Tools::getValue('id_order'));
    } elseif (Tools::isSubmit('id_order_invoice')) {
        $this->generateDeliverySlipPDFByIdOrderInvoice((int)Tools::getValue('id_order_invoice'));
    } elseif (Tools::isSubmit('id_delivery')) {
        $order = Order::getByDelivery((int)Tools::getValue('id_delivery'));
        $this->generateDeliverySlipPDFByIdOrder((int)$order->id);
    } else {
        die(Tools::displayError('The order ID -- or the invoice order ID -- is missing.'));
    }
}

在此控制器中,您将找到与此相同的其他方法来生成发票、订单...和其他 PDF.

In this Controller you'll find other methods as this one to generate Invoices, Order, ... and other PDFs.

如果您需要更多信息,请随时询问.

Feel free to ask if you need more informations.

如果您想以适当的方式更改格式,您必须覆盖这些类:

If you want to change format in a proper way you'll have to override those classes:

/override/classes/pdf/PDFGenerator.php:

<?php

/**
 * @since 1.5
 */
class PDFGenerator extends PDFGeneratorCore
{

    /**
     * @param bool $use_cache
     * @param string $orientation
     * @param string $format
     */
    public function __construct($use_cache = false, $orientation = 'P', $format = 'A4')
    {
        TCPDF::__construct($orientation, 'mm', $format, true, 'UTF-8', $use_cache, false);
        $this->setRTL(Context::getContext()->language->is_rtl);
    }
}

/override/classes/pdf/PDF.php:

<?php

/**
 * @since 1.5
 */
class PDF extends PDFCore
{

    /**
     * @param $objects
     * @param $template
     * @param $smarty
     * @param string $orientation
     */
    public function __construct($objects, $template, $smarty, $orientation = 'P', $format = 'A4')
    {
        parent::__construct($objects, $template, $smarty, $orientation);
        $this->pdf_renderer = new PDFGenerator((bool)Configuration::get('PS_PDF_USE_CACHE'), $orientation, $format);
    }
}

/override/controllers/admin/AdminPdfController.php:

<?php

class AdminPdfController extends AdminPdfControllerCore
{
    public function generatePDF($object, $template)
    {
        switch($template) {
            case PDF::TEMPLATE_DELIVERY_SLIP:
                $format = array(210, 50000); // Replace with your desired size
                break;
            default:
                $format = 'A4';
        }

        $pdf = new PDF($object, $template, Context::getContext()->smarty, 'P', $format);
        $pdf->render();
    }
}

现在您可以为每个 PDF 指定格式.您可以在 这里 找到有关 $format 的信息一个>

Now you can specify the format for each PDF. You will find informations about $format at this place

此代码尚未经过测试,但应该可以正常工作.如果您遇到任何问题,请告诉我.

This code has not been tested but should work as expected. Let me know if you encounter any issue.

在添加这些覆盖以清除 Prestashop 内部类路径缓存后,您需要删除 /cache/class_index.php.

You will need to delete /cache/class_index.php after adding those overrides to clear Prestashop internal classes path cache.

这篇关于对 prestashop PDF 生成过程感到困惑.处理逻辑的代码在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆