Choice bill or invoice in checkout_payment

Ask the community for help and support.
Post Reply
driven22
Posts: 8
Joined: Sun May 30, 2021 2:40 pm

Choice bill or invoice in checkout_payment

Post by driven22 »

I have a litle problem with my code. In checkout_payment I must be able to choose a bill or an invoice. If the customer selects an invoice, he must provide the company's NIF or other data for the invoice. In the previous version of oscommerce it worked for me.

Image

Everything works if I don't have the required invoice field. Unfortunately, the customer will choose the invoice field but will not provide data and the store will go to checkout_confirmation. How to use required so that it works only with the Invoice field and it is allowed to pass with the bill field?

My code:

Code: Select all

<div class="form-group row">
    <label for="inputComments" class="col-form-label col-sm-4 text-sm-right"><?= ENTRY_COMMENTS; ?></label>
    <div class="col-sm-8"><?= tep_draw_textarea_field('comments', 'soft', 60, 5, ($_SESSION['comments'] ?? null), 'id="inputComments" placeholder="' . ENTRY_COMMENTS_PLACEHOLDER . '"'); ?></div>
  </div>
  
  <script src="https://code.jquery.com/jquery-latest.js"></script>
             <script type="text/javascript">
                 $(document).ready(function () {


               $('input[name="inputComments"]').on('click', function() {
    if ($(this).val() === 'true') {
        $('#YOUR_NEW_BOX').removeProp("disabled").show();
    }
    else {
        $('#YOUR_NEW_BOX').prop("disabled", "disabled").hide();
    }
});
   $(function () {
        $("#item_shipping_true").click(function () {
            if ($(this).is(":checked")) {
                $("#YOUR_NEW_BOX").show();
            } else {
                $("#YOUR_NEW_BOX").hide();
            }
        });
    });

               });


</script>

   <div class="contentText">
 <div class="alert alert-warning" style="padding:10px 8px 0px;width: 100%;">
<span>
<label class="btn btn-default"><input type="radio" value="false" name="inputComments" id="item_shipping_false" checked="checked" for="item_shipping_false">  Paragon</label>
</span>
 </div>
 <div class="alert alert-warning" style="padding:10px 8px 0px;width: 100%;">
<span>
<label class="btn btn-default"><input type="radio" value="true" name="inputComments" id="item_shipping_true" for="item_shipping_true">  FAKTURA VAT</label>
</span>
 </div>
 <div class="contentText">
       <div class="form-group row">
    <label for="YOUR_NEW_BOX" class="col-form-label col-sm-4 text-sm-right"><?= ENTRY_COMMENTS; ?></label>

<input id="YOUR_NEW_BOX" class="faktura" type="text" placeholder="Wpisz NIP firmy do faktury-dane ściągniemy automatycznie z GUS /lub wpisz dane osoby prywatnej do faktury" name="YOUR_NEW_BOX"  SIZE="100%" maxlength="100%"  style="display: none">
</th> </div></th>
</div>

 </div>
burt
Lead Developer
Lead Developer
Posts: 2423
Joined: Tue Oct 29, 2019 9:37 am
Has thanked: 49 times
Been thanked: 137 times

Re: Choice bill or invoice in checkout_payment

Post by burt »

From memory there are a couple of payment modules that write data to the next page in the checkout_process. This next page is where you could capture the extra details you need (with no code changes at all).
Gamechanger Addon: Queued Emails, try before you buy.
driven22
Posts: 8
Joined: Sun May 30, 2021 2:40 pm

Re: Choice bill or invoice in checkout_payment

Post by driven22 »

Mostly it works. I have an additional like comment field that the client pays out when it is in payment_checkout. This field contains additional information for the invoice. This information is displayed in admin next to the comment field and is stored in the database. Unfortunately, I can't get this field out for email confirmation? CE worked in oscommerce 2.3.4.1, but in Phoenix I can't set it up. Please give me a hint on how to do it. In the previous version, 2.3.4.1 CE worked.

In tpl_n_checkout:

Code: Select all

 if (!empty($order->info['comments'])) {
    echo tep_db_output($order->info['comments']) . "\n";
  }
  
  //not work in email confirmation
 //if (!empty($order->info['YOUR_NEW_BOX'])) {
//echo tep_db_output($order->info['YOUR_NEW_BOX']) . "\n";
//}

My checkout_payment:

Code: Select all

<?php
/*
  $Id$

  CE Phoenix, E-Commerce made Easy
  https://phoenixcart.org

  Copyright (c) 2021 Phoenix Cart

  Released under the GNU General Public License
*/

  $hooks->register_pipeline('progress');

  $breadcrumb->add(NAVBAR_TITLE_1, $Linker->build('checkout_shipping.php'));
  $breadcrumb->add(NAVBAR_TITLE_2, $Linker->build('checkout_payment.php'));

  $comments_textarea = new Textarea('comments', [
    'cols' => '60',
    'rows' => '5',
    'id' => 'inputComments',
    'placeholder' => ENTRY_COMMENTS_PLACEHOLDER,
  ]);
  if (isset($_SESSION['comments'])) {
    $comments_textarea->set_text($_SESSION['comments']);
  }
  [b]$YOUR_NEW_BOX_textarea = new Textarea('YOUR_NEW_BOX', [
    'cols' => '60',
    'rows' => '5',
    'id' => 'inputYOUR_NEW_BOX',
    'placeholder' => ENTRY_COMMENTS_PLACEHOLDER,[/b]
  ]);
  if (isset($_SESSION['YOUR_NEW_BOX'])) {
    $YOUR_NEW_BOX_textarea->set_text($_SESSION['YOUR_NEW_BOX']);
  }

  require $Template->map('template_top.php', 'component');

  echo $payment_modules->javascript_validation();
?>

<h1 class="display-4"><?= HEADING_TITLE ?></h1>

<?php
  echo new Form('checkout_payment', $Linker->build('checkout_confirmation.php'), 'post', ['onsubmit' => 'return check_form();'], true);

  if (isset($_GET['payment_error']) && is_object(${$_GET['payment_error']}) && ($error = ${$_GET['payment_error']}->get_error())) {
    echo '<div class="alert alert-danger">' . "\n";
    echo '<p class="lead"><b>' . htmlspecialchars($error['title']) . "</b></p>\n";
    echo '<p>' . htmlspecialchars($error['error']) . "</p>\n";
    echo '</div>';
  }

  $selection = $payment_modules->selection();
?>

  <div class="row">
    <div class="col-sm-7">
      <h5 class="pt-2 list-group-item active mb-0"><?= TABLE_HEADING_PAYMENT_METHOD ?></h5>
      <div>
        <table class="table border-right border-left border-bottom table-hover m-0">
          <?php
          foreach ($selection as $choice) {
            ?>
            <tr class="table-selection">
              <td><label for="p_<?= $choice['id'] ?>"><?= $choice['module'] ?></label></td>
              <td class="text-right">
                <?php
                if (count($selection) > 1) {
                  $tickable = new Tickable('payment', ['value' => $choice['id'], 'id' => "p_{$choice['id']}", 'class' => 'custom-control-input'], 'radio');
                  echo '<div class="custom-control custom-radio custom-control-inline">';
                  echo $tickable->require()->tick($choice['id'] === ($_SESSION['payment'] ?? false));
                  echo '<label class="custom-control-label" for="p_' . $choice['id'] . '">&nbsp;</label>';
                  echo '</div>';
                } else {
                  echo new Input('payment', ['value' => $choice['id']], 'hidden');
                }
                ?>
              </td>
            </tr>
          <?php
          if (isset($choice['error'])) {
            ?>
          <tr>
            <td colspan="2"><?= $choice['error'] ?></td>
          </tr>
          <?php
            } elseif (isset($choice['fields']) && is_array($choice['fields'])) {
              foreach ($choice['fields'] as $field) {
              ?>
              <tr>
                <td><?= $field['title'] ?></td>
                <td><?= $field['field'] ?></td>
              </tr>
              <?php
              }
            }
          }
          ?>
        </table>

        <?php
        if (count($selection) == 1) {
      //    echo '<p class="m-2 font-weight-lighter">' . TEXT_ENTER_PAYMENT_INFORMATION . "</p>\n";
        }
        ?>
      </div>
    </div>
    <div class="col-sm-7">
      <h5 class="mt-2 list-group-item active mb-0">
        <?=
        TABLE_HEADING_BILLING_ADDRESS,
        sprintf(LINK_TEXT_EDIT, 'text-white ml-3', $Linker->build('checkout_payment_address.php'))
        ?>
      </h5>
      <div class="border">
        <ul class="list-group list-group-flush">
          <li class="list-group-item"><?= PAYMENT_FA_ICON . $customer->make_address_label($_SESSION['billto'], true, ' ', '<br>') ?>
          </li>
        </ul>
      </div>
    </div>
  </div>

  <hr>

 [b] <div class="form-group row">
    <label for="inputComments" class="col-form-label col-sm-2 text-sm-right"><?= ENTRY_COMMENTS ?></label>
    <div class="col-sm-5"><?= $comments_textarea ?></div>
  </div>
  <script src="https://code.jquery.com/jquery-latest.js"></script>
             <script type="text/javascript">
                 $(document).ready(function () {


               $('input[name="inputComments"]').on('click', function() {
    if ($(this).val() === 'true') {
                $('#YOUR_NEW_BOX').removeAttr('disabled');
    }
    else {
        $('#YOUR_NEW_BOX').prop("disabled", "disabled").hide();
    }
});
   $(function () {
        $("#item_shipping_true").click(function () {
            if ($(this).is(":checked")) {
                $("#YOUR_NEW_BOX").show();
            } else {
                $("#YOUR_NEW_BOX").hide();
            }
        });
    });

               });


</script>
  <div class="contentText">
 <div class="alert alert-warning" style="padding:10px 8px 0px;width: 100%;">
<span>
<label class="btn btn-default"><input type="radio" value="false" name="inputComments" id="item_shipping_false" checked="checked" for="item_shipping_false">  Paragon</label>
</span>
 </div>
 <div class="alert alert-warning" style="padding:10px 8px 0px;width: 100%;">
<span>
<label class="btn btn-default"><input type="radio" value="true" name="inputComments" id="item_shipping_true" for="item_shipping_true">  FAKTURA VAT</label>
</span>
 </div>
 <div class="contentText">
<div class="pl-3 form-group row">
<input id="YOUR_NEW_BOX" class="faktura" type="text" placeholder="Wpisz NIP firmy do faktury-dane ściągniemy automatycznie z GUS /lub wpisz dane osoby prywatnej do faktury" name="YOUR_NEW_BOX"  SIZE="100%" disabled="disabled" maxlength="100%" style="display: none" required>
</th> </div></th>
</div>

 </div>[/b]

  <?= $hooks->cat('injectFormDisplay') ?>

  <div class="buttonSet">
    <div class="text-right"><?= new Button(BUTTON_CONTINUE_CHECKOUT_PROCEDURE, 'fas fa-angle-right', 'btn-success btn-lg btn-block') ?></div>
  </div>

  <div class="progressBarHook">

  <?php
  $parameters = ['style' => 'progress-bar progress-bar-striped progress-bar-animated bg-info', 'markers' => ['position' => 2, 'min' => 0, 'max' => 100, 'now' => 67]];
  echo $hooks->cat('progressBar', $parameters);
  ?>

  </div>

</form>

<?php
  require $Template->map('template_bottom.php', 'component');
?>
My checckout_confirmation:

Code: Select all

<?php
/*
  $Id$

  CE Phoenix, E-Commerce made Easy
  https://phoenixcart.org

  Copyright (c) 2021 Phoenix Cart

  Released under the GNU General Public License
*/

  $hooks->register_pipeline('progress');

  $breadcrumb->add(NAVBAR_TITLE_1, $Linker->build('checkout_shipping.php'));
  $breadcrumb->add(NAVBAR_TITLE_2);

  require $Template->map('template_top.php', 'component');
?>

<h1 class="display-4"><?= HEADING_TITLE ?></h1>

<?php
  if ($messageStack->size('checkout_confirmation') > 0) {
    echo $messageStack->output('checkout_confirmation');
  }

  $form_action_url = ${$_SESSION['payment']}->form_action_url ?? $Linker->build('checkout_process.php');

  echo new Form('checkout_confirmation', $form_action_url, 'post');
?>

  <div class="row">
    <div class="col-sm-7">
      <h5 class="mt-2 list-group-item mb-0"><?= LIST_PRODUCTS ?><small><a class="font-weight-lighter ml-2 float-right" href="<?= $Linker->build('shopping_cart.php') ?>"><?= TEXT_EDIT ?></a></small></h5>
      <div class="border">
        <ul class="list-group list-group-flush">
          <?php
  foreach ($order->products as $product) {
    echo '<li class="list-group-item">';
    echo '<span class="float-right">' . $currencies->display_price($product['final_price'], $product['tax'], $product['qty']) . '</span>';
    echo '<h5 class="mb-1">'. $product['qty'] . '<small> x </small>' . $product['name'] .  '</h5>';
    if ( (isset($product['attributes'])) && (count($product['attributes']) > 0) ) {
      echo '<p class="w-100 mb-1">';
      foreach ($product['attributes'] as $attribute) {
        echo '- ' . $attribute['option'] . ': ' . $attribute['value'] . '<br>';
      }
      echo '</p>';
    }

    echo '</li>';
  }
?>
        </ul>
        <table class="table mb-0">
          <?php
  if (MODULE_ORDER_TOTAL_INSTALLED) {
    echo $order_total_modules->output();
  }
?>
        </table>
      </div>
    </div>
    <div class="col-sm-5">
      <h5 class="mb-1"><?= ORDER_DETAILS ?></h5>
      <div class="border">
        <ul class="list-group list-group-flush">
          <?php
  $address = $customer_data->get_module('address');
  if ($_SESSION['sendto']) {
    echo '<li class="list-group-item">';
    echo '<i class="fas fa-shipping-fast fa-fw fa-3x float-right text-black-50"></i>';
    echo '<h5 class="mb-0">' . HEADING_DELIVERY_ADDRESS . '<small><a class="font-weight-lighter ml-2" href="' . $Linker->build('checkout_shipping_address.php') . '">' . TEXT_EDIT . '</a></small></h5>';
    echo '<p class="w-100 mb-1">' . $address->format($order->delivery, 1, ' ', '<br>') . '</p>';
    echo '</li>';
  }

  echo '<li class="list-group-item">';
  echo '<i class="fas fa-file-invoice-dollar fa-fw fa-3x float-right text-black-50"></i>';
  echo '<h5 class="mb-0">' . HEADING_BILLING_ADDRESS . '<small><a class="font-weight-lighter ml-2" href="' . $Linker->build('checkout_payment_address.php') . '">' . TEXT_EDIT . '</a></small></h5>';
  echo '<p class="w-100 mb-1">' . $address->format($order->billing, 1, ' ', '<br>') . '</p>';
  echo '</li>';

  if ($order->info['shipping_method']) {
    echo '<li class="list-group-item">';
    echo '<h5 class="mb-1">' . HEADING_SHIPPING_METHOD . '<small><a class="font-weight-lighter ml-2" href="' . $Linker->build('checkout_shipping.php') . '">' . TEXT_EDIT . '</a></small></h5>';
    echo '<p class="w-100 mb-1">' . $order->info['shipping_method'] . '</p>';
    echo '</li>';
  }

  echo '<li class="list-group-item">';
  echo '<h5 class="mb-1">' . HEADING_PAYMENT_METHOD . '<small><a class="font-weight-lighter ml-2" href="' . $Linker->build('checkout_payment.php') . '">' . TEXT_EDIT . '</a></small></h5>';
  echo '<p class="w-100 mb-1">' . $order->info['payment_method'] . '</p>';
  echo '</li>';
?>
        </ul>

      </div>
    </div>
  </div>

  <?php
//  if (!Text::is_empty($order->info['comments'])) {
 [b] //Do faktury - testowo
$YOUR_NEW_BOX = isset($_POST['YOUR_NEW_BOX']) ? $_POST['YOUR_NEW_BOX'] : '';
?>[/b]
  <h5 class="mb-1"><?= HEADING_ORDER_COMMENTS . '<small><a class="font-weight-lighter ml-2" href="' . $Linker->build('checkout_payment.php') . '">' .TEXT_EDIT . '</a></small>' ?></h5>

  <div class="border mb-3">
    <ul class="list-group list-group-flush">
      <li class="list-group-item">
        <i class="fas fa-comments fa-fw fa-3x float-right text-black-50"></i>
        <?= nl2br(htmlspecialchars($order->info['comments'])) . new Input('comments', ['value' => $order->info['comments']], 'hidden') ?>
      </li>
    </ul>
  </div>
    <div class="border mb-3">
    <ul class="list-group list-group-flush">
      <li class="list-group-item">
        <i class="fas fa-comments fa-fw fa-3x float-right text-black-50"></i>
        [b]<?= nl2br(htmlspecialchars($YOUR_NEW_BOX)) . new Input('YOUR_NEW_BOX', ['value' => $order->info['YOUR_NEW_BOX']], 'hidden') ?>[/b]
              </li>
    </ul>
  </div>
  <?php
 // }

  if (is_array($payment_modules->modules)) {
    if ($confirmation = $payment_modules->confirmation()) {
?>
  <hr>

  <h5 class="mb-1"><?= HEADING_PAYMENT_INFORMATION ?></h5>

  <div class="row">
    <?php
      if (!Text::is_empty($confirmation['title'])) {
        echo '<div class="col">';
        echo '<div class="bg-light border p-3">';
        echo $confirmation['title'];
        echo '</div>';
        echo '</div>';
      }

      if (isset($confirmation['fields'])) {
        echo '<div class="col">';
        echo '<div class="alert alert-info" role="alert">';
        $fields = '';
        foreach ($confirmation['fields'] as $field) {
          $fields .= $field['title'] . ' ' . $field['field'] . '<br>';
        }

        if (strlen($fields) > strlen('<br>')) {
          echo substr($fields, 0, -strlen('<br>'));
        }
        echo '</div>';
        echo '</div>';
      }
?>
  </div>

  <div class="w-100"></div>
  <?php
    }
  }

  echo $hooks->cat('injectFormDisplay');
?>

  <div class="buttonSet mt-3">
    <div class="text-right">
      <?php
  if (is_array($payment_modules->modules)) {
    echo $payment_modules->process_button();
  }

  echo new Button(sprintf(IMAGE_BUTTON_FINALISE_ORDER, $currencies->format($order->info['total'])), 'fas fa-check-circle', 'btn-success btn-block btn-lg');
?>
    </div>
  </div>

  <div class="progressBarHook">
    <?php
  $parameters = ['style' => 'progress-bar progress-bar-striped progress-bar-animated bg-info', 'markers' => ['position' => 3, 'min' => 0, 'max' => 100, 'now' => 100]];
  echo $hooks->cat('progressBar', $parameters);
?>
  </div>

</form>

<?php
  require $Template->map('template_bottom.php', 'component');
?>
In mariadb field YOUR_NEW_BOX is in Tabela: orders_status_history and in Tabela: orders.
Post Reply