VirtueMart Forum

VirtueMart 2 + 3 + 4 => Plugins: Payment, Shipment and others => Topic started by: anthony on March 17, 2016, 03:48:48 AM

Title: Weight condition for paypal payment
Post by: anthony on March 17, 2016, 03:48:48 AM
Hi. My delivery plugin cannot handle orders over 22kg, so for orders weighing > 22kg, I want to make sure payment cannot automatically be processed - they can place the order, but shipping calculated off-line & then added to an invoice.

So I wanted to make paypal go away for > 22kg weights. But it doesn't have a weight condition.

If I understand correctly, then all the action happens here:
/plugins/vmpayment/paypal/paypal.php

At around line 965:


/**
* Check if the payment conditions are fulfilled for this payment method
* @param VirtueMartCart $cart
* @param int $activeMethod
* @param array $cart_prices
* @return bool
*/
protected function checkConditions($cart, $activeMethod, $cart_prices) {

//Check method publication start
if ($activeMethod->publishup) {
$nowDate = JFactory::getDate();
$publish_up = JFactory::getDate($activeMethod->publishup);
if ($publish_up->toUnix() > $nowDate->toUnix()) {
return FALSE;
}
}
if ($activeMethod->publishdown) {
$nowDate = JFactory::getDate();
$publish_down = JFactory::getDate($activeMethod->publishdown);
if ($publish_down->toUnix() <= $nowDate->toUnix()) {
return FALSE;
}
}
$this->convert_condition_amount($activeMethod);

$address = $cart->getST();

$amount = $this->getCartAmount($cart_prices);
$amount_cond = ($amount >= $activeMethod->min_amount AND $amount <= $activeMethod->max_amount
OR
($activeMethod->min_amount <= $amount AND ($activeMethod->max_amount == 0)));

$countries = array();
if (!empty($activeMethod->countries)) {
if (!is_array($activeMethod->countries)) {
$countries[0] = $activeMethod->countries;
} else {
$countries = $activeMethod->countries;
}
}
// probably did not gave his BT:ST address
if (!is_array($address)) {
$address = array();
$address['virtuemart_country_id'] = 0;
}

if (!isset($address['virtuemart_country_id'])) {
$address['virtuemart_country_id'] = 0;
}


if (in_array($address['virtuemart_country_id'], $countries) || count($countries) == 0) {
if ($amount_cond) {
return TRUE;
}
}

return FALSE;

}




I thought inserting something like - just after the "return FALSE;" would be the type of thing required:



$orderWeight = $this->getOrderWeight ($cart, $method->weight_unit);
//$orderWeight = "22" ;
if ($orderWeight >= "22") ;
return FALSE;


... but clearly I'm not skilled enough to know what I'm doing. Even when I hard code the value for $orderWeight the cart still completely ignores my coding attempt ... which is probably wise lol.

Can anyone see my mistake, or have a suggestion about how to do this?

Thanks
anthony
vm 3.014 & jooms 3.4.8
Title: Re: Weight condition for paypal payment
Post by: GJC Web Design on March 17, 2016, 10:09:52 AM
looks fine

are u putting in the logic correctly?

say just b4 $this->convert_condition_amount($activeMethod);
Title: Re: Weight condition for paypal payment
Post by: anthony on March 22, 2016, 02:10:24 AM
Thanks GJC, you are always so full of solution!
I fiddled around a bit, studied the code for delivery plugins ... trial & error .. then got lucky with this code (from about line 972) :



protected function checkConditions($cart, $activeMethod, $cart_prices) {


/* weight condition */

if($cart) {
$weight = $this->getOrderWeight($cart);
}

if ($weight >= 22)  {
return FALSE;
}

...




It seems to work, which is a bit of a miracle.

So this might be useful if anyone wants to stop the paypal payment method from being available as an option for orders over a certain weight. This allows a delivery quote to be manually organised and added to order later, without disrupting the user's good buying intention.