News:

Support the VirtueMart project and become a member

Main Menu

Setting default payment and shipping method in VM2?

Started by Artanis, April 22, 2012, 03:49:48 AM

Previous topic - Next topic

Artanis

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 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.
Animus Project - Design Studio
Running Joomla 2.5.6, Virtuemart 2.0.6a, PHP 5.3.10

PRO

have you tried the "sort order"   in the methods?

drewby07

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"

d0ublezer0

I have the same question: how to set default shipping method?
If shipping methods more than one, "auto select shipping" option is not worked

d0ublezer0

#4
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;

woood77

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.

jtomlinson

Has anyone come up with a solution to this issue? I am having the same problem.

Joomla 2.5 VM 2.06

Thanks.

morla77

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....

Artanis

Thank You, d0ublezer0 - this hack solved one of the problems. Could You please recommend how to fix payment method in the same way?
Animus Project - Design Studio
Running Joomla 2.5.6, Virtuemart 2.0.6a, PHP 5.3.10

Javix

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

DaggaTora

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?
Joomla 2.5.17 | VM2.0.26d | PHP 5.3.28

DaggaTora

#11
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!!
Joomla 2.5.17 | VM2.0.26d | PHP 5.3.28

emel

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

Robert V.

#13
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...

scorp2000

#14
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