0

I am using the SagePay Integration Module. I have created template file for the cart summary / overview (page--cart.tpl). I have also crated hooks to alter forms on the next two pages mytheme_form_commerce_checkout_form_checkout_alter and mytheme_form_commerce_checkout_form_review_alter and configured template files for them using the mytheme_theme hook. The templates are commerce-checkout-form-review.tpl.php and commerce-checkout-form-checkout.tpl.php.

Next I created a template file for the payment page, page--checkout--payment.tpl.php.

SagePay is configured to (only) use Sage Pay Server Integration - specifically Display payment form in an iFrame (can be found at /admin/commerce/config/sagepay).

After investigating the $page variable using Deval/kpr I decided to render

$page ['content']['content']['content']['system_main']

Here is a copy of the code in the template file (page--checkout--payment.tpl.php).

<?php if (isset($page['header'])) {?>
  <?php print render($page['header']); ?>
<?php }?>

<?php kpr ($page); ?>

<div class="content checkOutForm">
  <h2>PROCESS PAYMENT</h2>

  <table width="100%" border="0" cellspacing="5" cellpadding="5">
    <tbody style="color:#000;">
    <tr style="color:#000;line-height: 40px;">
          <th width="20%" align="center">YOUR BASKET</th>
          <th width="20%" align="center">BILLING DETAILS</th>
          <th width="20%" align="center">PAYMENT OPTION</th>
          <th width="20%" align="center"><strong>PROCESS PAYMENT</strong></th>
          <th width="20%" align="center">CONFIRMATION</th>
    </tr>
    </tbody>
  </table>

<p></p>

<?php print render($page ['content']['content']['content']['system_main']); ?>

</div>

<?php if (isset($page['footer'])) {?>
  <?php print render($page['footer']); ?>
<?php } ?>

The problem is this. The line

<?php print render($page ['content']['content']['content']['system_main']); ?>

renders the iFrame, but once that is done, the rest of the page does not get rendered. So the last part which needs to render the page[footer] is not executed.

I tried to save a copy of page[footer] at the beginning of the file, and then render this copy, but same result - footer does not get rendered.

I am assuming either the $page variable is lost / corrupted during the iframe render (unlikely), or the code stops executing after the iframe is rendered and we never get to the footer part (probably - but not sure why).

If I remove the line to render the iFrame, then footer prints out just fine.

My question is this - how I can render the SagePay iFrame form (in an iFrame) ensuring all relevant form fields (hidden, links, etc) is rendered correctly, and still render this inside one of my template files.

  • Solved the problem. It has to do with how SagePay renders the <iframe>; they use short notation which confuses the Drupal Render engine. Mail me if you need help. – JP Dippenaar Apr 1 '15 at 6:25
0

So I had a couple of people asking about this here and on drupal.org - so I figured it would be easier to just tell you what I did.

in commerce_sagepay/inc/commerce_sagepay_server.inc around line 120 there is a piece of code that reads:

  '#markup' => '<iframe style="width: 600px; height:500px" scrolling="no" frameborder="0" name="iframe_sagepay" id="iframe_sagepay" src="' . url('commerce_sagepay/sagepay_waiting_page') . '" />',

I changed this line to

  '#markup' => '<iframe style="width: 600px; height:500px" scrolling="no" frameborder="0" name="iframe_sagepay" id="iframe_sagepay" src="' . url('commerce_sagepay/sagepay_waiting_page') . '"></iframe>',

in other words - explicit close the iframe tag. It solved the problem for me.

Hope this helps someone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.