如何在PRESTASHOP中将购物车内容创建为pdf输出

时间:2013-06-26 05:26:01

标签: prestashop

我必须在pdf文件中打印购物车内容并下载。

我使用pdfinvoicecontroller.php

尝试了一些代码
  1. 我创建了新的控制器 - controllers / front / CartprintController.php

    类CartprintControllerCore扩展了FrontController     {     protected $ display_header = false;     protected $ display_footer = false;

        public $content_only = true;
    
    protected $template;
    public $filename; 
    
    public function postProcess()
    { 
    if (!$this->context->customer->isLogged() && !Tools::getValue('secure_key'))
    Tools::redirect('index.php?controller=authentication&back=cartprint'); 
    } 
    
    public function display()
    {   
          $displayproducts = $this->context->cart->getProducts();   
    
    $pdf = new PDF($displayproducts, PDF::TEMPLATE_INVOICE_CART, $this->context->smarty, $this->context->language->id);
    
    $pdf->render(); 
    } 
    public function getTemplate()
    { 
    $template = _PS_THEME_PDF_DIR_.'/cartprint.tpl'; 
    
    return $template;
    } 
    }
    
  2. const TEMPLATE_INVOICE_CART ='Cartprint';

  3. 分类/ pdf / PDF.php

    3.然后在pdf / cartprint.tpl

    中创建了一个HTML模板文件
    <table id="cart_summary" class="std">
    <thead>
    <tr>
    <th class="cart_product first_item">{l s='Product'}</th>
    <th class="cart_description item">{l s='Description'}</th>
    
    <th class="cart_unit item">{l s='Unit price'}</th>
    <th class="cart_quantity item">{l s='Qty'}</th>
    <th class="cart_total item">{l s='Total'}</th>
    
    </tr>
    </thead>
    {foreach  $displayproducts  item=prodpef name=prodpef }
    <tr>
    <td class="cart_product first_item">{$prodpef.name}</td>
    <td class="cart_description item">{$prodpef.description_short}</td>
    
    <td class="cart_unit item">{$prodpef.price}</td>>
    <td class="cart_quantity item">{$prodpef.cart_quantity}</td>>
    <td class="cart_total item">{$prodpef.total}</td>> 
    
    </tr>
    {/foreach}
    
    </table>
    

    4.在购物车页面中,我创建了一个链接

    <a href="{$link->getPageLink('cartprint', true, NULL)}" title="{l s='Invoice'}" class="_blank"><img src="{$img_dir}icon/pdf.gif" alt="{l s='Invoice'}" class="icon" /></a>
    

    但我仍然没有得到pdf输出。

    有任何帮助吗?

1 个答案:

答案 0 :(得分:0)

首先,最好覆盖PDF类,然后需要在类dir中创建HTMLTemplateCartPrint.php文件或覆盖类dir以生成pdf文件。

最好的问候。

相关问题