Page 1 of 1

Change the order total MINIMUM required for PayPal to a MAXIMUM instead

Posted: Wed May 27, 2020 2:05 am
by ArtGallery
First off, unfortunately I have no funds to pay for the "Restrict Payment Methods" extension that appears to offer this function and more.

I have found some posts that describe how to do this in older versions of OpenCart, but I was not able to find where to do the same thing in OC 3.0.x as the paypal.php file contents in the closest looking subdirectory was not the same.

Any help on how and if this can be done with a simple php file edit would be appreciated.

Re: Change the order total MINIMUM required for PayPal to a MAXIMUM instead

Posted: Wed May 27, 2020 2:33 am
by xxvirusxx
ArtGallery wrote:
Wed May 27, 2020 2:05 am
I have found some posts that describe how to do this in older versions of OpenCart,
You should post..

Re: Change the order total MINIMUM required for PayPal to a MAXIMUM instead

Posted: Wed May 27, 2020 2:49 am
by ArtGallery
Here is one for OC version 1.5

viewtopic.php?t=123593

I looked at the paypal.php file in this directory catalog/model/extension/payment, but it wasn't at all like the one in the post and I couldn't figure out if it was perhaps a different paypal.php file somewhere else or if the OC 3.0.x version was just different now.

Re: Change the order total MINIMUM required for PayPal to a MAXIMUM instead

Posted: Wed May 27, 2020 10:55 am
by letxobnav
in pp standard minimum check is done via

Code: Select all

		if ($this->config->get('payment_pp_standard_total') > $total) {
			$status = false;
meaning: if minimum total in settings is greater than the total, disable this module.

in catalog/model/extension/payment/pp_standard.php

you could change it to

Code: Select all

		if ($total == 0 || $this->config->get('payment_pp_standard_total') < $total) {
			$status = false;
meaning: if total is zero or total in settings is less than the total, disable this module.

that would make that field max iso min.



you can also change this:

Code: Select all

		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "zone_to_geo_zone WHERE geo_zone_id = '" . (int)$this->config->get('payment_pp_standard_geo_zone_id') . "' AND country_id = '" . (int)$address['country_id'] . "' AND (zone_id = '" . (int)$address['zone_id'] . "' OR zone_id = '0')");

		if ($this->config->get('payment_pp_standard_total') > $total) {
			$status = false;
		} elseif (!$this->config->get('payment_pp_standard_geo_zone_id')) {
			$status = true;
		} elseif ($query->num_rows) {
			$status = true;
		} else {
			$status = false;
		}

to this:

Code: Select all

		if ($this->config->get('payment_pp_standard_total') > $total) {
			$status = false;
		} elseif (!$this->config->get('payment_pp_standard_geo_zone_id')) {
			$status = true;
		} else {
			$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "zone_to_geo_zone WHERE geo_zone_id = '" . (int)$this->config->get('payment_pp_standard_geo_zone_id') . "' AND country_id = '" . (int)$address['country_id'] . "' AND (zone_id = '" . (int)$address['zone_id'] . "' OR zone_id = '0')");
			if ($query->num_rows) {
				$status = true;
			} else {
				$status = false;
			}
		}

as it is silly to always execute a query on the zones if it is not needed.

in your case:

Code: Select all

		if ($total == 0 || $this->config->get('payment_pp_standard_total') < $total) {
			$status = false;
		} elseif (!$this->config->get('payment_pp_standard_geo_zone_id')) {
			$status = true;
		} else {
			$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "zone_to_geo_zone WHERE geo_zone_id = '" . (int)$this->config->get('payment_pp_standard_geo_zone_id') . "' AND country_id = '" . (int)$address['country_id'] . "' AND (zone_id = '" . (int)$address['zone_id'] . "' OR zone_id = '0')");
			if ($query->num_rows) {
				$status = true;
			} else {
				$status = false;
			}
		}

Re: Change the order total MINIMUM required for PayPal to a MAXIMUM instead

Posted: Wed May 27, 2020 1:41 pm
by letxobnav
If you want to change the minimum field into a range field like min-max you can change

Code: Select all

		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "zone_to_geo_zone WHERE geo_zone_id = '" . (int)$this->config->get('payment_pp_standard_geo_zone_id') . "' AND country_id = '" . (int)$address['country_id'] . "' AND (zone_id = '" . (int)$address['zone_id'] . "' OR zone_id = '0')");

		if ($this->config->get('payment_pp_standard_total') > $total) {
			$status = false;
		} elseif (!$this->config->get('payment_pp_standard_geo_zone_id')) {
			$status = true;
		} elseif ($query->num_rows) {
			$status = true;
		} else {
			$status = false;
		}

to

Code: Select all

		// defaults
		$status = true;
		$limit_min = 1;
		$limit_max = 1000000;
		
		// process total limits separated by dash
		if (strstr($this->config->get('payment_pp_standard_total'),'-')) {
			$min_max_totals = explode('-',$this->config->get('payment_pp_standard_total'));
			if (is_numeric($min_max_totals[0])) $limit_min = (float)$min_max_totals[0];
			if (is_numeric($min_max_totals[1])) $limit_max = (float)$min_max_totals[1];
		}
		
		// determine whether to disable
		if ($total < $limit_min || $total > $limit_max) {
			$status = false;
		} elseif ($this->config->get('payment_pp_standard_geo_zone_id')) {
			$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "zone_to_geo_zone WHERE geo_zone_id = '" . (int)$this->config->get('payment_pp_standard_geo_zone_id') . "' AND country_id = '" . (int)$address['country_id'] . "' AND (zone_id = '" . (int)$address['zone_id'] . "' OR zone_id = '0')");
			if (!$query->num_rows) {
				$status = false;
			}
		}

then you can input 1-500 in that field as in min-max total limits

Re: Change the order total MINIMUM required for PayPal to a MAXIMUM instead

Posted: Wed May 27, 2020 3:02 pm
by ArtGallery
Thanks for the suggestions. It will take me quite a while to figure all that out. Hopefully I can get it to work. The min/max is the most attractive. There are very few items that I want them to be able to use PayPal for the payment and they are within $10 of each other.

There is no file with that name in that directory. Only pp_braintree.php and paypal.php. I don't want to use the braintree version so I am assuming I should use the one named paypal.php

Re: Change the order total MINIMUM required for PayPal to a MAXIMUM instead

Posted: Wed May 27, 2020 4:12 pm
by letxobnav
then you are probably using 3.0.3.3 where they removed a lot of payment methods.
Use paypal.php, similar code.

just replace

Code: Select all

$this->config->get('payment_pp_standard_total')
with

Code: Select all

$this->config->get('payment_paypal_total')
and replace

Code: Select all

$this->config->get('payment_pp_standard_geo_zone_id')
with

Code: Select all

$this->config->get('payment_paypal_geo_zone_id')