Federico Portoghese Posted May 14, 2015 Share Posted May 14, 2015 Hello, my name is Federico, i'm new to Prestashop and I would need some help about something I have to accomplish with my store. Long story short: I need to see the details of all the products within a group product in my invoice with its own tax rule and price. Long story: I have this group product which costs 24 dollars, no tax applied. This group product does have 2 simple products in it: The product itself which costs 21.50 dollars, no tax applied Another product attached wich costs 2.05 dollars, with 22% tax applied, for a total amount of 2.50 dollars Total of products in my group product is equal to 24 dollars, exactly like the price of the group product itself. All I need to do now is to show this kind of detail in the invoice. It would be great if something like this could be accomplished: If the product is a simple or a virtual one then build the regular invoice. If the product is a group one then show the details of each product in it like following: "Group item name" 24$ "Product 1 name" - price excl. tax 21.50$ - tax 0% - price incl. tax 21.50$ "Product 2 name" - price excl. tax 2.05$ - tax 22% - price incl. tax 2.50$ Grand total 24$ Or something like that. I'm not expert in Prestashop but I think this is possible. The questions are: 1. is this hard to accomplish? 2. how can i do that? If the solution to this problem needs a complex module to be done we're willing to get quotations for having the job done, paying for it. Thank you very much. Link to comment Share on other sites More sharing options...
Federico Portoghese Posted May 14, 2015 Author Share Posted May 14, 2015 (edited) To clarify: I believe I should do something like that override the getContent() and getTemplateByCountry() methods in classes/pdf/HTMLTemplateInvoice.php to something like this /** * Returns the template's HTML content * @return string HTML content */ public function getContent() { $invoice_address = new Address((int)$this->order->id_address_invoice); $country = new Country((int)$invoice_address->id_country); $formatted_invoice_address = AddressFormat::generateAddress($invoice_address, array(), '<br />', ' '); $formatted_delivery_address = ''; if ($this->order->id_address_delivery != $this->order->id_address_invoice) { $delivery_address = new Address((int)$this->order->id_address_delivery); $formatted_delivery_address = AddressFormat::generateAddress($delivery_address, array(), '<br />', ' '); } $customer = new Customer((int)$this->order->id_customer); $order_details = $this->order_invoice->getProducts(); if (Configuration::get('PS_PDF_IMG_INVOICE')) foreach ($order_details as &$order_detail) { if ($order_detail['image'] != null) { $name = 'product_mini_'.(int)$order_detail['product_id'].(isset($order_detail['product_attribute_id']) ? '_'.(int)$order_detail['product_attribute_id'] : '').'.jpg'; $order_detail['image_tag'] = ImageManager::thumbnail(_PS_IMG_DIR_.'p/'.$order_detail['image']->getExistingImgPath().'.jpg', $name, 45, 'jpg', false); if (file_exists(_PS_TMP_IMG_DIR_.$name)) $order_detail['image_size'] = getimagesize(_PS_TMP_IMG_DIR_.$name); else $order_detail['image_size'] = false; } /** * Code i should put here to detect if this is a group product and if it is, * add the sub-products details to $order_details */ } $data = array( 'order' => $this->order, 'order_details' => $order_details, 'cart_rules' => $this->order->getCartRules($this->order_invoice->id), 'delivery_address' => $formatted_delivery_address, 'invoice_address' => $formatted_invoice_address, 'tax_excluded_display' => Group::getPriceDisplayMethod($customer->id_default_group), 'tax_tab' => $this->getTaxTabContent(), 'customer' => $customer ); if (Tools::getValue('debug')) die(json_encode($data)); $this->smarty->assign($data); return $this->smarty->fetch($this->getTemplateByCountry($country->iso_code)); } /** * Returns the invoice template associated to the country iso_code * @param string $iso_country */ protected function getTemplateByCountry($iso_country) { $file = Configuration::get('PS_INVOICE_MODEL'); /** * Code i should put here to detect if the order has a group product, * and switch the template accordingly */ // try to fetch the iso template $template = $this->getTemplate($file.'.'.$iso_country); // else use the default one if (!$template) $template = $this->getTemplate($file); return $template; } But the question remains... how do i accomplish these operations? For example, wich is the method to detect if the product is a group one? Wich is the method to get its sub-products? Thanks so much everyone for helping. Edited May 14, 2015 by Federico Portoghese (see edit history) Link to comment Share on other sites More sharing options...
Federico Portoghese Posted May 14, 2015 Author Share Posted May 14, 2015 Hello. I managed to do it by myself. In the end they're just PHP Classes Here's what I did if someone is interested. I overrided the classes/pdf/HTMLTemplateInvoice.php by adding this pieco of code to the getContent() method /* check wheter or not the products in order are packs and if so adds the item to order details */ foreach ($order_details as &$order_detail) { $product = new PackCore((int)$order_detail['product_id']); if($product->isPack((int)$order_detail['product_id'])) { $order_detail['isPack'] = TRUE; $order_detail['packItems'] = $product->getItems((int)$order_detail['product_id']); } else { $order_detail['isPack'] = FALSE; } } This basically checks if products in order are packs or not using the PackCore class isPack() method.If the product is a pack add a boolean variable to tell "Yeah it is a pack" and then add a the packItems array wich contains each item using the PackCore class getItems() method. All these new variables and arrays are sent to the smarty template and I can use them to format the template accordingly. Hope it helps. Bye bye Link to comment Share on other sites More sharing options...
votre-evenement.be Posted August 10, 2015 Share Posted August 10, 2015 (edited) Hello. I managed to do it by myself. In the end they're just PHP Classes Here's what I did if someone is interested. I overrided the classes/pdf/HTMLTemplateInvoice.php by adding this pieco of code to the getContent() method /* check wheter or not the products in order are packs and if so adds the item to order details */ foreach ($order_details as &$order_detail) { $product = new PackCore((int)$order_detail['product_id']); if($product->isPack((int)$order_detail['product_id'])) { $order_detail['isPack'] = TRUE; $order_detail['packItems'] = $product->getItems((int)$order_detail['product_id']); } else { $order_detail['isPack'] = FALSE; } } This basically checks if products in order are packs or not using the PackCore class isPack() method.If the product is a pack add a boolean variable to tell "Yeah it is a pack" and then add a the packItems array wich contains each item using the PackCore class getItems() method. All these new variables and arrays are sent to the smarty template and I can use them to format the template accordingly. Hope it helps. Bye bye What should I add to the invoice.product-tab.tpl file to recover the retail pack? Thanks Edited August 10, 2015 by votre-evenement.be (see edit history) Link to comment Share on other sites More sharing options...
votre-evenement.be Posted August 11, 2015 Share Posted August 11, 2015 (edited) Could you help me?? I tried this in invoice.product-tab.tpl: {$order_detail.packItems|@count} {if $order_detail.isPack} {foreach from=$order_detail.packItems item=packy} {Pack::getItems($order_detail.id_product, Configuration::get('PS_LANG_DEFAULT'))} {Pack::getItemTable($order_detail.id_product, Configuration::get('PS_LANG_DEFAULT'))} {/foreach} {/if} and return number of packItem and array and nothing else... Are you a suggestion? Thanks Edited August 11, 2015 by votre-evenement.be (see edit history) Link to comment Share on other sites More sharing options...
votre-evenement.be Posted August 12, 2015 Share Posted August 12, 2015 (edited) I supposed that not the perfect code but... {if Pack::isPack($order_detail.id_product)}{assign var=packItems value=Pack::getItemTable($order_detail.id_product, Configuration::get('PS_LANG_DEFAULT'))} {if $packItems|@count > 0} {foreach from=$packItems item=packItem} <br/>{$packItem.name|escape:'html':'UTF-8'} {l s='Quantity' pdf='true'}: {$packItem.pack_quantity} {/foreach} {/if} {/if} it's work Edited August 15, 2015 by votre-evenement.be (see edit history) Link to comment Share on other sites More sharing options...
floxator Posted November 11, 2015 Share Posted November 11, 2015 (edited) Hello there, I try this solution to get items of a pack in invoice template, but it doesn't work. My version is latest (1.6.1.2), and I override getContent() in HTMLTemplateInvoice.php as described then I try the piece of code in invoice.product-tab.tpl. Is there anyone that can find me a solution ? Thanks. Edited November 11, 2015 by floxator (see edit history) Link to comment Share on other sites More sharing options...
tuk66 Posted November 13, 2015 Share Posted November 13, 2015 Another example is at www.presta-addons.com/pdf/Invoice - grouped by categories, packs itemized.pdf Link to comment Share on other sites More sharing options...
votre-evenement.be Posted January 10, 2016 Share Posted January 10, 2016 (edited) Hello there, I try this solution to get items of a pack in invoice template, but it doesn't work. My version is latest (1.6.1.2), and I override getContent() in HTMLTemplateInvoice.php as described then I try the piece of code in invoice.product-tab.tpl. Is there anyone that can find me a solution ? Thanks. Try this <!-- PRODUCTS --> {foreach $order_details as $order_detail} {cycle values=["color_line_even", "color_line_odd"] assign=bgcolor_class} <tr class="product {$bgcolor_class}"> <td class="product center"> {$order_detail.reference} </td> <td class="product left"> {if $display_product_images} <table width="100%"> <tr> <td width="15%"> {if isset($order_detail.image) && $order_detail.image->id} {$order_detail.image_tag} {/if} </td> <td width="5%"> </td> <td width="80%"> {$order_detail.product_name} </td> </tr> </table> {else} {$order_detail.product_name} {if Pack::isPack($order_detail.id_product)}{assign var=packItems value=Pack::getItemTable($order_detail.id_product, Configuration::get('PS_LANG_DEFAULT'))} {if $packItems|@count > 0} {foreach from=$packItems item=packItem} <br/>{$packItem.name|escape:'html':'UTF-8'} {l s='Quantity' pdf='true'}: {$packItem.pack_quantity} {/foreach} {/if} {/if} {/if} </td> <td class="product center"> {$order_detail.order_detail_tax_label} </td> {if isset($layout.before_discount)} .... :-) Edited January 10, 2016 by votre-evenement.be (see edit history) 1 Link to comment Share on other sites More sharing options...
rachel01 Posted June 16, 2020 Share Posted June 16, 2020 Une idée pour la 1.7 ? Link to comment Share on other sites More sharing options...
Futamiya Posted August 2, 2021 Share Posted August 2, 2021 Bonjour, je relance aussi pour savoir s'il y avait une idée pour la 1.7 ? 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