News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Weight condition for paypal payment

Started by anthony, March 17, 2016, 03:48:48 AM

Previous topic - Next topic

anthony

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
The greater our mastery over language, the sharper the tools with which to dissect reality.

GJC Web Design

looks fine

are u putting in the logic correctly?

say just b4 $this->convert_condition_amount($activeMethod);
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

anthony

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.



The greater our mastery over language, the sharper the tools with which to dissect reality.