Author Topic: A bit of php coding help with Cash on Delivery payment option.  (Read 1136 times)

MacAcer

  • Beginner
  • *
  • Posts: 34
A bit of php coding help with Cash on Delivery payment option.
« on: January 28, 2011, 22:19:16 pm »
Hello,

I found something that could be a solution for my earlier request to lock payment options with shippers in the "Bundle of Payment modules Sweden" on extensions.joomla.org. I am using the ps_codpf payment option.

I want to be able to add two shippers to work with the ps_codpf payment option. I think I managed to pinpoint where I do it, but lack of php knowledge limit me to actually fix it.

Code: [Select]
  function process_payment($order_number, $order_total, &$d) {
   /** Read current Configuration ***/
        require_once(CLASSPATH ."payment/".$this->classname.".cfg.php");
//echo "process_payment $order_number $order_total ";
 // echo $_REQUEST['shipping_rate_id'];
        if ((strpos($_REQUEST['shipping_rate_id'], CODPF_SHIPPER) > 0) OR (CODPF_CHECK_SHIPPER == 'False') ){
        // return true;
        } else {
         $d['order_status'] = CODPF_INVALID_STATUS;
            
    ?>
    
            <img src="<?php echo IMAGEURL ?>ps_image/cart.png" align="center" alt="Cancel" border="0" />
            <span class="message"><?php echo 'Fel Speditör, var god välj Posten för att använda Postens Postförskott genom att ändra fraksätt' ?></span>
        <?php
 return false;
}

I want to add another shipper (CODPF_SHIPPER_2) to be recognised as an acceptable shipper with this payment option. Thanks to the help of a developer team, I managed to make some alterations in the list_payment_methods.tpl.php file which now enable me to select Cash on Delivery payment method with the two assigned shippers, as shown in the code below.


Code: [Select]
 <?php 
//echo CLASSPATH;
//echo "---<br/>";
require_once(CLASSPATH ."payment/ps_codpf.cfg.php");
//echo "-------here ---------".CODPF_SHIPPER;
//echo "---<br/>";
//echo "<pre>";
//print_r($_REQUEST['shipping_rate_id']);
//print_r($_REQUEST);
//echo "<br/>";
//echo $payment_method_id;
//echo "</pre>";
//if(preg_match('/DHL/i',$_REQUEST['shipping_rate_id']))
if(CODPF_SHIPPER_2=='DHL' && preg_match('/DHL/i',$_REQUEST['shipping_rate_id']) && CODPF_CHECK_SHIPPER_2 =='True')
{
?>

                    <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
                     $(document).ready(function(){
$('.jqeeery input:first-child').attr('checked','checked');
$('.nodispquery').hide();
});
                    
                    </script>

<?php
}else if(CODPF_SHIPPER=='Posten' && preg_match('/Posten/i',$_REQUEST['shipping_rate_id']) && CODPF_CHECK_SHIPPER =='True')
{
?>

                    <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
                     $(document).ready(function(){
$('.jqeeery input:first-child').attr('checked','checked');
$('.nodispquery').hide();
});
                    
                    </script>

<?php
}
else{

?>

                    <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
                     $(document).ready(function(){
$('.jqeeery').hide();
});
                    
                    </script>

<?php
}

            ?>
Unfortunately I am not sure how to add that second shipper to be accepted at the final stage of the checkout. I understand that my "CODPF_SHIPPER_2" need to be somewhere in this piece of code, so it won't just come out INVALID.

Code: [Select]
if ((strpos($_REQUEST['shipping_rate_id'], CODPF_SHIPPER) > 0) OR (CODPF_CHECK_SHIPPER == 'False') ){
        // return true;
        } else {
         $d['order_status'] = CODPF_INVALID_STATUS;
            
    ?>

I have attached a zip file with the files involved in this payment option.
The files of interest (as far as I'm concerned) seem to be the following three.

  • root/administrator/components/com_virtuemart/classes/payment/ps_codpf.php
  • root/administrator/components/com_virtuemart/classes/payment/ps_codpf.cfg.php
  • root/components/com_virtuemart/themes/yourtheme/templates/checkout/list_payment_methods.tpl.php

I would really appreciate it if someone could take time and see if they can't get this Payment option for Cash on Delivery to work with two shippers. I am sure that only a tad bit of php coding knowledge, and this be easy as pie... eating one, not making  :D



[attachment cleanup by admin]