VirtueMart Forum

VirtueMart 2 + 3 + 4 => Plugins: Payment, Shipment and others => Topic started by: Artanis on April 22, 2012, 03:49:48 AM

Title: Setting default payment and shipping method in VM2?
Post by: Artanis on April 22, 2012, 03:49:48 AM
Hi!

As I mentioned few topics earlier - I'm building small internet shop (Joomla 2.5 + VM2). Most of clients will use courier delivery and will pay through internet bank upon receiving an PDF invoice, which is most popular payment methode in my country. So - to make less unnecessary steps for clients, I would like to make these two options (payment and delivery) default (already checked radio buttons and showing up in cart as already selected).

After 20 minutes of searching I found couple (http://forum.virtuemart.net/index.php?topic=73315.0) instructions for setting default payment for VM1.x, but those are not compatible with VM2.
So, if I may ask, please update those instructions to work with VM2 - so how to set default payment and delivery method...?  :-\

Looking forward to your answers,
best regards.
Title: Re: Setting default payment and shipping method in VM2?
Post by: PRO on April 22, 2012, 12:55:07 PM
have you tried the "sort order"   in the methods?
Title: Re: Setting default payment and shipping method in VM2?
Post by: drewby07 on April 30, 2012, 14:56:25 PM
I have the same issue.  I've tried every sort order imaginable, and cannot get the "Paypal" payment method to be selected by default.  No matter what I do, when I go to my cart I see "Select Payment"
Title: Re: Setting default payment and shipping method in VM2?
Post by: d0ublezer0 on May 04, 2012, 16:46:59 PM
I have the same question: how to set default shipping method?
If shipping methods more than one, "auto select shipping" option is not worked
Title: Re: Setting default payment and shipping method in VM2?
Post by: d0ublezer0 on May 04, 2012, 20:48:39 PM
The logic of Virtuemart is that the method of delivery is automatically selected only if it is just one.
If you set up multiple shipping methods, none of them will be selected automatically.
This means that the "delivery method by default" is not provided.
In order to remedy this situation, I have developed such a hack.

You need to change the file components\com_virtuemart\helpers\cart.php
Find function CheckAutomaticSelectedShipment and in the end of this function make changes:
      /* Comment or delete this next three lines
                $this->automaticSelectedShipment=false;
                $this->setCartIntoSession();
                return false;*/

                // <START> add these lines <START>
                $preferred_shipment=0; // change to any shipment ID, that you need to use as default

                if ($preferred_shipment==0){ // not used if you already define "default shipment ID" in the line above
                    if (!class_exists('VirtueMartModelShipmentmethod'))
                        require(JPATH_VM_ADMINISTRATOR.DS.'models'.DS.'shipmentmethod.php');
                    $myship= new VirtueMartModelShipmentmethod;
                    $shipments=$myship->getShipments();
                    if ($shipments){
                        $preferred_shipment = intval($shipments[0]->virtuemart_shipmentmethod_id);   
                    }
                }
                if ($this->virtuemart_shipmentmethod_id==0) {
                    $this->virtuemart_shipmentmethod_id=$preferred_shipment;
                    $virtuemart_shipmentmethod_id=$preferred_shipment;}
                $this->automaticSelectedShipment=false;
                $this->setCartIntoSession();
                return false;
                // <END> add these lines <END>


And, also you need to change
administrator\components\com_virtuemart\helpers\calculationh.php
~on line 968
if ($automaticSelectedShipment) $ship_id=$cart->virtuemart_shipmentmethod_id;

Change to:
$ship_id=$cart->virtuemart_shipmentmethod_id;
Title: Re: Setting default payment and shipping method in VM2?
Post by: woood77 on May 07, 2012, 18:14:34 PM
I've noticed that when I have 1 shipping method than that shipping method is automatically selected, which works correctly.  However when I have 1 payment method that payment method is NOT automatically selected.  This has turned out to be somewhat confusing to my users.

I've verified in the Configuration that "Enable Automatic Selected Payment?" is checked.

I'm using version 2.0.6 of VM.
Title: Re: Setting default payment and shipping method in VM2?
Post by: jtomlinson on May 26, 2012, 20:57:14 PM
Has anyone come up with a solution to this issue? I am having the same problem.

Joomla 2.5 VM 2.06

Thanks.
Title: Re: Setting default payment and shipping method in VM2?
Post by: morla77 on June 13, 2012, 11:57:55 AM
I have made what d0ublezer0 tells on his answer and for the moment it works for me in shipping method, now I have to fix payment method....
Title: Re: Setting default payment and shipping method in VM2?
Post by: Artanis on June 19, 2012, 15:41:40 PM
Thank You, d0ublezer0 - this hack solved one of the problems. Could You please recommend how to fix payment method in the same way?
Title: Re: Setting default payment and shipping method in VM2?
Post by: Javix on July 11, 2012, 00:16:41 AM
Hi,

just in case anybody is still interested in the same hack for payment, it looks like this:
File: /components/com_virtuemart/helpers/cart.php
Find function:CheckAutomaticSelectedPayment()

Replace this at the end of the function:


                $this->automaticSelectedPayment=false;
$this->setCartIntoSession();
                return false;


with this:


/*$this->automaticSelectedPayment=false; // comment or erase this lines
$this->setCartIntoSession();
                return false;*/
$preferred_payment=1; // change to any payment ID, that you need to use as default
                if ($preferred_payment==0){ // not used if you already define "default payment ID" in the line above
                    if (!class_exists('VirtueMartModelPaymentmethod'))
                        require(JPATH_VM_ADMINISTRATOR.DS.'models'.DS.'paymentmethod.php');
                    $mypayment= new VirtueMartModelPaymentmethod;
                    $payments=$mypayment->getPayments();
                    if ($payments){
                        $preferred_payment = intval($payments[0]->virtuemart_paymentmethod_id);   
                    }
                }
                if ($this->virtuemart_paymentmethod_id==0) {
                    $this->virtuemart_paymentmethod_id=$preferred_payment;
                    $virtuemart_paymentmethod_id=$preferred_payment;
                  }
                $this->automaticSelectedPayment=false;
                $this->setCartIntoSession();
                return false;


You  have to modify this file, too: /administrator/components/com_virtuemart/helpers/calculationh.php
Look for function calculatePaymentPrice (around line 1008)

Replace this:


if ($cart->automaticSelectedPayment) $payment_id=$cart->virtuemart_paymentmethod_id;


with this:

//if ($cart->automaticSelectedPayment) - you can also delete this line.
$payment_id=$cart->virtuemart_paymentmethod_id;


This is the exact same hack applied to payment. Nevertheless, I haved looked the first bit of code and it could be simplified to


                /*$this->automaticSelectedPayment=false;// comment or erase this lines
  $this->setCartIntoSession();
   return false;*/
$preferred_payment=1; // change to any payment ID, that you need to use as default
                $this->virtuemart_paymentmethod_id=$preferred_payment;
                $virtuemart_paymentmethod_id=$preferred_payment;
                $this->automaticSelectedPayment=false;
                $this->setCartIntoSession();
                return false;


instead of the first code above.

Hope it works for you, too.

Cheers
Title: Re: Setting default payment and shipping method in VM2?
Post by: DaggaTora on July 16, 2012, 10:23:36 AM
Thanks Javix!

This worked like a charm in 2.0.8c but now in version d, no matter what user selects that cart only redirects to the preferred payment system.

any idea?
Title: Re: Setting default payment and shipping method in VM2?
Post by: DaggaTora on July 17, 2012, 10:35:03 AM
Ok,

if you use the simplified version it doesn't let you to change between payments methods and only preferred works.. BUT

if you use non-simplified, it works again in 2.0.8d!!
Title: Re: Setting default payment and shipping method in VM2?
Post by: emel on July 19, 2012, 14:30:37 PM
how about version 2.08E, i also have issues, that is, users must select the method, even though there's only a single method implemented.

help appreciated
Title: Re: Setting default payment and shipping method in VM2?
Post by: Robert V. on July 21, 2012, 15:23:43 PM
found out that the code in 2.0.6. is a little bit different.... (maybe the code in 2.0.8 is still the same)

/components/com_virtuemart/helpers/cart.php
Leave the original code for the CheckAutomaticSelectedShipment function as it is and modify it according below...

function CheckAutomaticSelectedShipment($cart_prices, $checkAutomaticSelected ) {

$nbShipment = 1; // -> 0 = hide shipping methods options/ link - 1 = show shipping methods options/ link
$virtuemart_shipmentmethod_id=1; // or whatever id your preferred shipping method is. - If this is 0 the $nbShipment
                                                                          // is always shown even if it is set to 0


Maybe this helps...
Title: Re: Setting default payment and shipping method in VM2?
Post by: scorp2000 on September 22, 2012, 00:51:38 AM
Quote from: woood77 on May 07, 2012, 18:14:34 PM
I've noticed that when I have 1 shipping method than that shipping method is automatically selected, which works correctly.  However when I have 1 payment method that payment method is NOT automatically selected.  This has turned out to be somewhat confusing to my users.

I've verified in the Configuration that "Enable Automatic Selected Payment?" is checked.

I'm using version 2.0.6 of VM.

i am using vm 2.0.10
your hack work grt for shipment method..  using same hack code i try to implement for payment but its not working... also try Javix hack but not working
plz i need this ...
Regards
Title: Re: Setting default payment and shipping method in VM2?
Post by: BCD on November 11, 2012, 01:45:56 AM
No moderators on this thread ???
Title: Re: Setting default payment and shipping method in VM2?
Post by: toad78 on November 16, 2012, 00:45:47 AM
It seems this is an ongoing problem with VM. I'm now using 2.0.14 and I still cannot get 'Select Shipping' and 'Select Payment' method to disappear on checkout. I only have one shipping method and one payment method.

Title: Re: Setting default payment and shipping method in VM2?
Post by: PRO on November 19, 2012, 19:10:16 PM
Quote from: toad78 on November 16, 2012, 00:45:47 AM
It seems this is an ongoing problem with VM. I'm now using 2.0.14 and I still cannot get 'Select Shipping' and 'Select Payment' method to disappear on checkout. I only have one shipping method and one payment method.




is auto select shipping enabled?

ALSO:
what payment method do you have?
If it's authorize.net. You do not want auto select
Title: Re: Setting default payment and shipping method in VM2?
Post by: PRO on November 19, 2012, 19:17:33 PM
to remove  "select shipment"

change
cart/default_pricelist.php

<?php /*   <td colspan="2" align="right"><?php echo JText::_('COM_VIRTUEMART_ORDER_PRINT_SHIPPING'); ?> </td> */ ?>
            <td colspan="4" align="left">
            <?php echo $this->cart->cartData['shipmentName']; ?>
   <br/>
   <?php
   if (!empty($this->layoutName) && $this->layoutName == 'default' && !$this->cart->automaticSelectedShipment) {
      echo JHTML::_ ('link', JRoute::_ ('index.php?view=cart&task=edit_shipment', $this->useXHTML, $this->useSSL), $this->select_shipment_text, 'class=""');
   } else {
      JText::_ ('COM_VIRTUEMART_CART_SHIPPING');
   }
} else {
   ?>
   <td colspan="4" align="left">
      <?php echo $this->cart->cartData['shipmentName']; ?>
   </td>
   <?php } ?>



to this

<?php /*   <td colspan="2" align="right"><?php echo JText::_('COM_VIRTUEMART_ORDER_PRINT_SHIPPING'); ?> </td> */ ?>
            <td colspan="4" align="left">
            <?php echo $this->cart->cartData['shipmentName']; ?></td>

Title: Re: Setting default payment and shipping method in VM2?
Post by: toad78 on November 22, 2012, 02:55:00 AM
Quote from: PRO on November 19, 2012, 19:10:16 PM


is auto select shipping enabled?

ALSO:
what payment method do you have?
If it's authorize.net. You do not want auto select

Yes, to the first question.
Secondly, why wouldn't you want auto select if it's Authorize.net?
Title: Re: Setting default payment and shipping method in VM2?
Post by: toad78 on November 23, 2012, 06:53:50 AM
Thank you for the recommendation, but I kept receiving an error.

What I did was just hide the label by commenting the following line:

<td colspan="4" align="left">

            <?php echo $this->cart->cartData['shipmentName']; ?>

This removed the label that I wanted to remove. After testing, the shipping price does pop up as it should without the label to 'Select Shipment'. If, in the future, if I need to use more than one shipping option, then I know I can uncomment that line to bring it back.

Thank you for your time, PRO!
Title: Re: Setting default payment and shipping method in VM2?
Post by: PRO on November 23, 2012, 13:55:38 PM
Quote from: toad78 on November 22, 2012, 02:55:00 AM
Quote from: PRO on November 19, 2012, 19:10:16 PM


is auto select shipping enabled?

ALSO:
what payment method do you have?
If it's authorize.net. You do not want auto select

Yes, to the first question.
Secondly, why wouldn't you want auto select if it's Authorize.net?

because it tries to go forward with order, and the user receives an error their credit card info is wrong
Title: Re: Setting default payment and shipping method in VM2?
Post by: raunhar on December 04, 2012, 08:55:51 AM
Is the default_pricelist.php under views/cart/temp

If yes, i tried making the changes but no effect. I have only one Payment option i.e. paypal, but am unable to select it as default.
Title: Re: Setting default payment and shipping method in VM2?
Post by: DrZero on December 19, 2012, 06:10:05 AM
I have Joomla 2.5.8 with VM 2.0.14 and I use authorize.net and I have also unselected the auto select payment, but if I choose "select payment" before I input the billing/shipping information, I still get no options.  It only shows up when I modify the billing / ship to info.  This is quite the bug.  If the end user "HAS" to enter the billing/shipping information first no matter what, then it should not show up on the first screen....only the one part first.....then on the next screen have it auto select shipping, and auto select payment method if applicable since it has the information needed for that.  This could have been designed a bit better in that regard.  Hopefully you can make this change in the next version?
Title: Re: Setting default payment and shipping method in VM2?
Post by: DrZero on December 19, 2012, 06:26:18 AM
Also neither of those methods for payment hack work on VM 2.0.14. .... No love!!
Title: Re: Setting default payment and shipping method in VM2?
Post by: Renata on August 28, 2013, 16:03:07 PM
Just use language override of Joomla and leave tekst empty

(was searching for a solution for this myself and came myself with this solution. It works fine for me.

Kind regards
Renata
Title: Re: Setting default payment and shipping method in VM2?
Post by: Ragdata on November 04, 2013, 02:30:49 AM
Hi Guys,

Just thought I'd share a very quick solution for this problem which works for me using version 2.0.24.  Unfortunately it's a hack rather than an override - but it's a minor one so I can forgive myself.

/components/com_virtuemart/views/cart/view.html.php

Around line 56 or so (just after $cart is instantiated in the display() function), insert the following code:


if( $cart->virtuemart_shipmentmethod_id == 0 ){ $cart->setShipment( 3 ); } //<< Use the ID of whichever method suits you best
if( $cart->virtuemart_paymentmethod_id == 0 ){ $cart->setPaymentMethod( 1 ); } //<< Use the ID of whichever method suits you best


No problem selecting a different method, and everything seems to be getting applied from the point-of-view of shipping fees and the like.
Title: Re: Setting default payment and shipping method in VM2?
Post by: mbrando on November 21, 2013, 23:04:18 PM
Hello,

I came up with a NON-hack way to do this.

Create an HTML override file in your template folder:
/templates/rt_quantive/html/com_virtuemart/cart/select_payment.php

Look for this around line 44 ish.


<?php
     
if ($this->found_payment_method) {


    echo 
"<fieldset>";
foreach ($this->paymentplugins_payments as $paymentplugin_payments) {
    if (is_array($paymentplugin_payments)) {
foreach ($paymentplugin_payments as $paymentplugin_payment) {
    echo $paymentplugin_payment.'<br />';
}
    }
}
    echo 
"</fieldset>";

    } else {
 echo "<h1>".$this->payment_not_found_text."</h1>";
    }


    
?>




After the closing PHP tag for the echo field set add this:


        <script type="text/javascript">
<!--
radiobtn = document.getElementById("payment_id_3");
radiobtn.checked = true;
-->
</script>


So it looks like this:


<?php
     
if ($this->found_payment_method) {


    echo 
"<fieldset>";
foreach ($this->paymentplugins_payments as $paymentplugin_payments) {
    if (is_array($paymentplugin_payments)) {
foreach ($paymentplugin_payments as $paymentplugin_payment) {
    echo $paymentplugin_payment.'<br />';
}
    }
}
    echo 
"</fieldset>";

    } else {
 echo "<h1>".$this->payment_not_found_text."</h1>";
    }


    
?>

        <script type="text/javascript">
<!--
radiobtn = document.getElementById("payment_id_3");
radiobtn.checked = true;
-->
</script>


Where 'payment_id_3' in the document.getElementById("payment_id_3") is the ID the radio button you want checked. Note the 3 in 'payment_id_3' is the payment ID you'd see in the payment method list on the far right in the VM admin panel.

- Mike
Title: Re: Setting default payment and shipping method in VM2?
Post by: favdes on January 08, 2014, 13:14:12 PM
Quote from: woood77 on May 07, 2012, 18:14:34 PM
I've noticed that when I have 1 shipping method than that shipping method is automatically selected, which works correctly.  However when I have 1 payment method that payment method is NOT automatically selected.  This has turned out to be somewhat confusing to my users.

I've verified in the Configuration that "Enable Automatic Selected Payment?" is checked.

I'm using version 2.0.6 of VM.

Hi,

Not sure if you fixed this or not but I've just had a similar problem. I only have one shipping method but it was not automatically being selected at checkout. To fix it, I changed the 'List Order' in the shipping method configuration from '0' to '1' and that did it.
Title: Re: Setting default payment and shipping method in VM2?
Post by: vitaly-zdanevich on February 25, 2014, 15:48:12 PM
mbrando, you say: "Create an HTML override file in your template folder" - you mean - just create HTML-file? I do file select_payment.php in /templates/shaper_istore/html/com_virtuemart/cart2 and clear cache but I not have default value for radiobutton.
Title: Re: Setting default payment and shipping method in VM2?
Post by: changlee on April 03, 2015, 18:01:44 PM
I have a very simple question.  :)

When a customer makes his first cart checkout, why he has each time to choose payment - shipping method? How can that be default stored to his profile? Esp. after his first checkout...

He only needs just to confirm the order. The most of the orders are at same shipping and same payment way.