Jump to content

Payment method is not shown on invoice until the order is paid.


btsfreak77
 Share

Recommended Posts

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.
 

Share this post


Link to post
Share on other sites

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 by btsfreak77 (see edit history)

Share this post


Link to post
Share on other sites

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. 

Share this post


Link to post
Share on other sites

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>

 

  • Like 3

Share this post


Link to post
Share on other sites

  • 1 year later...
  • 1 year later...
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

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More