btsfreak77 Posted April 25, 2020 Share Posted April 25, 2020 Hi! This is happening in version 1.7.6.3. There is a bug in the order logic of prestashop. Invoices of orders that have not been paid yet never display any payment method. It is thus not possible to print a complete invocie before an order is paid. The issue is that if we have a payment (e.g. bankwire), it results in an initial order status that is not logable and it will will not create an entry in ps_order_payments. (That is happening in PaymentModule.php -> validateOrder()). That is correct so far, no invoice is accessible yet. If we then change the status of the order to a status that is logable, but not paid yet (e.g. "Waiting for payment, order is printed"), invoices get accessible, but if we print them (PDF), there is no entry in the field "payment method". The reason is that /pdf/invoice.payment-tab.tpl uses the method $order_invoice->getOrderPaymentCollection(), which uses OrderPayment::getByInvoiceId() and this doesnt return anything because there is no order_payment existing for this order. Why is there no order_payment existing? Because when the status of the order is changed (as explained before) and the order is not paid yet, OrderHistory.php->changeIdOrderState() checks if an order is paid before it creates a payment. As a result, non-paid orders will never have a payment but the invoice template needs that payment to display the payment method. Link to comment Share on other sites More sharing options...
Nishith Nesdiya Posted April 25, 2020 Share Posted April 25, 2020 Hi.. this is not bug Invoices of orders depend on order status Goto admin-> shop peramater -> order settings -> Statuses and enable in Invoices for perticular order status Thanks Link to comment Share on other sites More sharing options...
btsfreak77 Posted April 25, 2020 Author Share Posted April 25, 2020 (edited) That doesnt help. As I described above, if invoices is activated but the order is not paid, no payment is added to the order. In my above example, invoices is activated for the status "Waiting for payment, order is printed", still there is no order_payment created in the database if we change to it. (I explained what is happening in the code and why). We can print the invoice, yes, but no payment is displayed because it wasnt added yet (because it needs to paid to be added). Edited April 25, 2020 by btsfreak77 (see edit history) Link to comment Share on other sites More sharing options...
btsfreak77 Posted April 25, 2020 Author Share Posted April 25, 2020 (edited) OrderHistory.php->changeIdOrderState() has a clear check in there: check on line 377 if ($new_os->paid == 1) { ... [add entries to ps_order_payment and ps_order_invocie_payment] Edited April 25, 2020 by btsfreak77 (see edit history) Link to comment Share on other sites More sharing options...
btsfreak77 Posted April 25, 2020 Author Share Posted April 25, 2020 I would agree that this is not necessarily a problem of the order process, but then the template should not use $order_invoice->getOrderPaymentCollection(), because at the time of the invoice creation (and thus template execution), those payments do not exist yet. Link to comment Share on other sites More sharing options...
btsfreak77 Posted April 25, 2020 Author Share Posted April 25, 2020 The following code change in the invoice template would fix the issue, just to cater for the case of invoices of non-paid orders that don't have payments created for them yet: /pdf/invoice.payment-tab.tpl <table id="payment-tab" width="100%"> <tr> <td class="payment center small grey bold" width="44%">{l s='Payment Method' d='Shop.Pdf' pdf='true'}</td> <td class="payment left white" width="56%"> <table width="100%" border="0"> {if count($order_invoice->getOrderPaymentCollection()) > 0} {foreach from=$order_invoice->getOrderPaymentCollection() item=payment} <tr> <td class="right small">{$payment->payment_method}</td> <td class="right small">{displayPrice currency=$payment->id_currency price=$payment->amount}</td> </tr> {/foreach} {else} <tr> <td class="right small">{$order->payment}</td> <td class="right small">{displayPrice currency=$order->id_currency price=$order->total_paid}</td> </tr> {/if} </table> </td> </tr> </table> 4 Link to comment Share on other sites More sharing options...
miba Posted August 6, 2021 Share Posted August 6, 2021 @ btsfreak77 Thanks for the contribution, I was able to solve my problem with it. Michel Link to comment Share on other sites More sharing options...
Yulia Vitun Posted September 6, 2022 Share Posted September 6, 2022 On 4/25/2020 at 2:10 PM, btsfreak77 said: The following code change in the invoice template would fix the issue, just to cater for the case of invoices of non-paid orders that don't have payments created for them yet: /pdf/invoice.payment-tab.tpl <table id="payment-tab" width="100%"> <tr> <td class="payment center small grey bold" width="44%">{l s='Payment Method' d='Shop.Pdf' pdf='true'}</td> <td class="payment left white" width="56%"> <table width="100%" border="0"> {if count($order_invoice->getOrderPaymentCollection()) > 0} {foreach from=$order_invoice->getOrderPaymentCollection() item=payment} <tr> <td class="right small">{$payment->payment_method}</td> <td class="right small">{displayPrice currency=$payment->id_currency price=$payment->amount}</td> </tr> {/foreach} {else} <tr> <td class="right small">{$order->payment}</td> <td class="right small">{displayPrice currency=$order->id_currency price=$order->total_paid}</td> </tr> {/if} </table> </td> </tr> </table> This method helped me for PS 1.7.8.7 to show COD (cash on delivery) on invoice 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