fernandokerber Posted July 19, 2012 Share Posted July 19, 2012 Hi. I want to put a link in my product page to generate a pdf file to print that product. Just like the Invoice pdf function does. Does anybody could help me on how to display some product information in the pdf file? This is the function that generate the returning invoice pdf file: public static function orderReturn($orderReturn, $mode = 'D', $multiple = false, &$pdf = NULL) { $pdf = new PDF('P', 'mm', 'A4'); self::$orderReturn = $orderReturn; $order = new Order($orderReturn->id_order); self::$order = $order; $pdf->SetAutoPageBreak(true, 35); $pdf->StartPageGroup(); $pdf->AliasNbPages(); $pdf->AddPage(); /* Display address information */ $arrayConf = array('PS_SHOP_NAME', 'PS_SHOP_ADDR1', 'PS_SHOP_ADDR2', 'PS_SHOP_CODE', 'PS_SHOP_CITY', 'PS_SHOP_COUNTRY', 'PS_SHOP_DETAILS', 'PS_SHOP_PHONE', 'PS_SHOP_STATE'); $conf = Configuration::getMultiple($arrayConf); foreach ($conf as $key => $value) $conf[$key] = Tools::iconv('utf-8', self::encoding(), $value); foreach ($arrayConf as $key) if (!isset($conf[$key])) $conf[$key] = ''; $width = 100; $pdf->SetX(10); $pdf->SetY(25); $pdf->SetFont(self::fontname(), '', 9); $addressType = array( 'invoice' => array(), 'delivery' => array()); $patternRules = array( 'avoid' => array( 'address2', 'company', 'phone', 'phone_mobile')); $addressType = self::generateHeaderAddresses($pdf, $order, $addressType, $patternRules, $width); /* * display order information */ $pdf->Ln(12); $pdf->SetFillColor(240, 240, 240); $pdf->SetTextColor(0, 0, 0); $pdf->SetFont(self::fontname(), '', 9); $pdf->Cell(0, 6, self::l('RETURN #').sprintf('%06d', self::$orderReturn->id).' '.self::l('from') . ' ' .Tools::displayDate(self::$orderReturn->date_upd, self::$order->id_lang), 1, 2, 'L'); $pdf->Cell(0, 6, self::l('We have logged your return request.'), 'TRL', 2, 'L'); $pdf->Cell(0, 6, self::l('Your package must be returned to us within').' '.Configuration::get('PS_ORDER_RETURN_NB_DAYS').' '.self::l('days of receiving your order.'), 'BRL', 2, 'L'); $pdf->Ln(5); $pdf->Cell(0, 6, self::l('List of items marked as returned :'), 0, 2, 'L'); $pdf->Ln(5); $pdf->ProdReturnTab(); $pdf->Ln(5); $pdf->SetFont(self::fontname(), 'B', 10); $pdf->Cell(0, 6, self::l('Return reference:').' '.self::l('RET').sprintf('%06d', self::$order->id), 0, 2, 'C'); $pdf->Cell(0, 6, self::l('Please include this number on your return package.'), 0, 2, 'C'); $pdf->Ln(5); $pdf->SetFont(self::fontname(), 'B', 9); $pdf->Cell(0, 6, self::l('REMINDER:'), 0, 2, 'L'); $pdf->SetFont(self::fontname(), '', 9); $pdf->Cell(0, 6, self::l('- All products must be returned in their original packaging without damage or wear.'), 0, 2, 'L'); $pdf->Cell(0, 6, self::l('- Please print out this document and slip it into your package.'), 0, 2, 'L'); $pdf->Cell(0, 6, self::l('- The package should be sent to the following address:'), 0, 2, 'L'); $pdf->Ln(5); $pdf->SetFont(self::fontname(), 'B', 10); $pdf->Cell(0, 5, Tools::strtoupper($conf['PS_SHOP_NAME']), 0, 1, 'C', 1); $pdf->Cell(0, 5, (!empty($conf['PS_SHOP_ADDR1']) ? self::l('Headquarters:').' '.$conf['PS_SHOP_ADDR1'].(!empty($conf['PS_SHOP_ADDR2']) ? ' '.$conf['PS_SHOP_ADDR2'] : '').' '.$conf['PS_SHOP_CODE'].' '.$conf['PS_SHOP_CITY'].' '.$conf['PS_SHOP_COUNTRY'].((isset($conf['PS_SHOP_STATE']) AND !empty($conf['PS_SHOP_STATE'])) ? (', '.$conf['PS_SHOP_STATE']) : '') : ''), 0, 1, 'C', 1); $pdf->Ln(5); $pdf->SetFont(self::fontname(), '', 9); $pdf->Cell(0, 6, self::l('Upon receiving your package, we will notify you by e-mail. We will then begin processing the reimbursement of your order total.'), 0, 2, 'L'); $pdf->Cell(0, 6, self::l('Let us know if you have any questions.'), 0, 2, 'L'); $pdf->Ln(5); $pdf->SetFont(self::fontname(), 'B', 10); $pdf->Cell(0, 6, self::l('If the conditions of return listed above are not respected,'), 'TRL', 2, 'C'); $pdf->Cell(0, 6, self::l('we reserve the right to refuse your package and/or reimbursement.'), 'BRL', 2, 'C'); return $pdf->Output(sprintf('%06d', self::$order->id).'.pdf', $mode); } I copied it with another name ("classProduct") and it works, now I need to show in this class the product photo, description, price, etc. Any ideas? thanks Link to comment Share on other sites More sharing options...
math_php Posted July 20, 2012 Share Posted July 20, 2012 Hello In fact you want - to get all info for an id_product (images, description, ...) ? - to know how to deal with pdf class ? For the first case $id_product = you_must_have_this_value_given_by_your_link $id_lang= Configuration::get('PS_LANG_DEFAULT'); // this is cheating, because you shoud get id_lang with $cookie $product = new Product($id_product,true,$id_lang); $lst_img= $product->getImages(); Good dev 1 Link to comment Share on other sites More sharing options...
fernandokerber Posted July 20, 2012 Author Share Posted July 20, 2012 (edited) Hello In fact you want - to get all info for an id_product (images, description, ...) ? - to know how to deal with pdf class ? For the first case $id_product = you_must_have_this_value_given_by_your_link $id_lang= Configuration::get('PS_LANG_DEFAULT'); // this is cheating, because you shoud get id_lang with $cookie $product = new Product($id_product,true,$id_lang); $lst_img= $product->getImages(); Good dev Hello In fact you want - to get all info for an id_product (images, description, ...) ? - to know how to deal with pdf class ? For the first case $id_product = you_must_have_this_value_given_by_your_link $id_lang= Configuration::get('PS_LANG_DEFAULT'); // this is cheating, because you shoud get id_lang with $cookie $product = new Product($id_product,true,$id_lang); $lst_img= $product->getImages(); Good dev thank you! This information helped me a lot guiding my ideas. I'll pass the "product id" by the GET method from the product page. After doing this I'll print a new PDF using your tips and consulting the FPDF guide at http://www.fpdf.org. Now Ithink I can do it. But if you think you can help me, please go ahead. Thanks! PS: Can you please explain me this line? $id_lang= Configuration::get('PS_LANG_DEFAULT'); // this is cheating, because you shoud get id_lang with $cookie Edited July 20, 2012 by fernandokerber (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now