Zen Cart Logo
Forums / PayPal Express Checkout support / Paypal Express Minimum amount [HELP]

Paypal Express Minimum amount [HELP]

Views: 18,188

Results 1 to 10 of 10
3 Jun 2016, 3:52 PM
#1
thymine avatar

thymine

New Zenner

Join Date:
Jun 2016
Posts:
20
Plugin Contributions:
0

Paypal Express Minimum amount [HELP]

Dear all,

I had spent tremendous amount of time searching for similar threads, found it but new problem arised. Would appreciate if someone could help me understand.

I inserted an if else condition to paypal express module to prevent palpal option from appearing less than 20 amount. It worked well until the final stage. After clicking confirm order, it wont connect to paypal page (the circle paypal loading page) and show the page isnt working.

Below is my code if someone could help. Additions are bolded in the middle of the text wall.

function paypalwpp() {
    include_once(zen_get_file_directory(DIR_FS_CATALOG . DIR_WS_LANGUAGES . $_SESSION['language'] . '/modules/payment/', 'paypalwpp.php', 'false'));
    global $order;
    $this->code = 'paypalwpp';
    $this->codeTitle = MODULE_PAYMENT_PAYPALWPP_TEXT_ADMIN_TITLE_EC;
    $this->codeVersion = '1.5.1';
    $this->enableDirectPayment = FALSE;
    $this->enabled = (MODULE_PAYMENT_PAYPALWPP_STATUS == 'True');
    
  [B]if ($order->info['subtotal'] < 20.00){$this->enabled=false;}
    else {$this->enabled=true;}[/B]
    
    // Set the title & description text based on the mode we're in ... EC vs US/UK vs admin
    if (IS_ADMIN_FLAG === true) {
      $this->description = sprintf(MODULE_PAYMENT_PAYPALWPP_TEXT_ADMIN_DESCRIPTION, ' (rev' . $this->codeVersion . ')');
      switch (MODULE_PAYMENT_PAYPALWPP_MODULE_MODE) {
        case ('PayPal'):
          $this->title = MODULE_PAYMENT_PAYPALWPP_TEXT_ADMIN_TITLE_EC;
        break;
        case ('Payflow-UK'):
          $this->title = MODULE_PAYMENT_PAYPALWPP_TEXT_ADMIN_TITLE_PRO20;
        break;
        case ('Payflow-US'):
          if (defined('MODULE_PAYMENT_PAYPALWPP_PAYFLOW_EC') && MODULE_PAYMENT_PAYPALWPP_PAYFLOW_EC == 'Yes') {
            $this->title = MODULE_PAYMENT_PAYPALWPP_TEXT_ADMIN_TITLE_PF_EC;
          } else {
            $this->title = MODULE_PAYMENT_PAYPALWPP_TEXT_ADMIN_TITLE_PF_GATEWAY;
          }
        break;
        default:
          $this->title = MODULE_PAYMENT_PAYPALWPP_TEXT_ADMIN_TITLE_EC;
      }
3 Jun 2016, 7:30 PM
#2
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Paypal Express Minimum amount [HELP]

Two things.

  1. the code snippet above will enable the plugin even if it was turned off on the admin because of the else statement that sets enabled to true if the price is at or above 20.00.
  2. at the point of completing the order, the subtotal array value doesn't exist anymore because the $order->info is generated from other values which can be used to determine the subtotal, but the subtotal is not used.

Two solutions to the second "problem" come to mind.

  1. the "easiest" is to check if the subtotal key exists, if it doesn't then carry on with whatever enabled status was previously set. If it does exist, then compare to your chosen price.
  2. if the subtotal doesn't exist, then determine it from say taking the total (which does exist) and subtracting the shipping_cost or the shipping_cost and tax depending on whether DISPLAY_PRICE_WITH_TAX is true or not respectfully.

The function to check for existence of a key in an array would be like:

array_key_exists('subtotal', $orders->info)
``` and returns true if it does
Also understand that in a series of and statements: if (true && false && generates_an_error) that php stops processing the logic as soon as any value is false. So it doesn't matter in some regards how incorrect later tests are if an earlier test proved to be false.

As to the else part? I would leave it off so that previous control logic still applied.
3 Jun 2016, 10:28 PM
#3
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,100
Plugin Contributions:
56

Re: Paypal Express Minimum amount [HELP]

No need to be carving up core-files; I'm closing down for the day, but I'll post a teeny file update that will do the trick.

4 Jun 2016, 12:40 AM
#4
thymine avatar

thymine

New Zenner

Join Date:
Jun 2016
Posts:
20
Plugin Contributions:
0

Re: Paypal Express Minimum amount [HELP]

mc12345678:

Two things.

  1. the code snippet above will enable the plugin even if it was turned off on the admin because of the else statement that sets enabled to true if the price is at or above 20.00.
  2. at the point of completing the order, the subtotal array value doesn't exist anymore because the $order->info is generated from other values which can be used to determine the subtotal, but the subtotal is not used.

Two solutions to the second "problem" come to mind.

  1. the "easiest" is to check if the subtotal key exists, if it doesn't then carry on with whatever enabled status was previously set. If it does exist, then compare to your chosen price.
  2. if the subtotal doesn't exist, then determine it from say taking the total (which does exist) and subtracting the shipping_cost or the shipping_cost and tax depending on whether DISPLAY_PRICE_WITH_TAX is true or not respectfully.

The function to check for existence of a key in an array would be like:

array_key_exists('subtotal', $orders->info)

> Also understand that in a series of and statements: if (true && false && generates_an_error) that php stops processing the logic as soon as any value is false. So it doesn't matter in some regards how incorrect later tests are if an earlier test proved to be false.
> 
> As to the else part? I would leave it off so that previous control logic still applied.

Thank you all for your input, i am grateful for the effort.

I tried changing the subtotal to total - shipping cost, as coded below

if (($order->info['total']-=$order->info['shipping_cost']) < 20.00){$this->enabled=false;}
else {$this->enabled=true;}


It worked just like subtotal but still could not get past the final stage connect to paypal. :frusty: Did i overlooked something? Thank you!
4 Jun 2016, 10:49 AM
#5
thymine avatar

thymine

New Zenner

Join Date:
Jun 2016
Posts:
20
Plugin Contributions:
0

Re: Paypal Express Minimum amount [HELP]

Bump!~ Anyone enlighten me please! Thank you!

4 Jun 2016, 12:28 PM
#6
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Paypal Express Minimum amount [HELP]

thymine:

Thank you all for your input, i am grateful for the effort.

I tried changing the subtotal to total - shipping cost, as coded below

if (($order->info['total']-=$order->info['shipping_cost']) < 20.00){$this->enabled=false;}
else {$this->enabled=true;}

> 
> It worked just like subtotal but still could not get past the final stage connect to paypal. :frusty: Did i overlooked something? Thank you!

I was kind of waiting for lat9's input before continuing down the path of modifying the core file.
Also, personally the bump of this thread made it easier to which to return, but in the forum that is typically not an acceptable practice. Those offering assistance do so when they are able or willing. 

That said I will say this, the code provided above does a modification to the total and a comparison, so it too could be a cause to the issue. Are you getting any error logs when it gets to that last screen?

My untested suggestion for the code if going to modify the PayPal module is the following:

$min_pp_enabled = 20.00;
if (array_key_exists('subtotal', $order->info)) {
if($order->info['subtotal'] < $min_pp_enabled) {
$this->enabled=false;
}
} elseif (DISPLAY_PRICE_WITH_TAX == 'true') {
if(($order->info['total'] - $order->info['shipping_cost']) < $min_pp_enabled) {
$this->enabled=false;
}
} else {
if(($order->info['total'] - $order->info['shipping_cost'] - $order->info['tax']) < $min_pp_enabled) {
$this->enabled=false;
}
}

4 Jun 2016, 12:56 PM
#7
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,100
Plugin Contributions:
56

Re: Paypal Express Minimum amount [HELP]

As promised, just place this content into the file: /includes/modules/pages/checkout_payment/header_php_no_ppwpp_gt_20.php:

<?php
// -----
// Created by lat9; Copyright (C) 2016 Vinos de Frutas Tropicales
//
// If the order's subtotal is greater than 20 and the PayPal Express Checkout is enabled, disable it!
//
if ($order->info['subtotal'] > 20 && is_object ($paypalwpp)) {
    $paypalwpp->enabled = false;
}

Like I'd indicated before, no core file overwrites!

4 Jun 2016, 3:12 PM
#8
thymine avatar

thymine

New Zenner

Join Date:
Jun 2016
Posts:
20
Plugin Contributions:
0

Re: Paypal Express Minimum amount [HELP]

lat9:

As promised, just place this content into the file: /includes/modules/pages/checkout_payment/header_php_no_ppwpp_gt_20.php:

<?php // ----- // Created by lat9; Copyright (C) 2016 Vinos de Frutas Tropicales // // If the order's subtotal is greater than 20 and the PayPal Express Checkout is enabled, disable it! // if ($order->info['subtotal'] > 20 && is_object ($paypalwpp)) { $paypalwpp->enabled = false; } ``` > Like I'd indicated before, no core file overwrites! Thank you very much for your coding, just to clarify, 1. header_php_no_ppwpp_gt_20.php, do you mean header.php? I do not find a header_php_no_ppwpp_gt_20 folder there. 2. Do i just put it on the first line? Sorry for the newbie question, i should be ashamed :( Thank you!
4 Jun 2016, 3:21 PM
#9
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Paypal Express Minimum amount [HELP]

thymine:

Thank you very much for your coding, just to clarify,

  1. header_php_no_ppwpp_gt_20.php, do you mean header.php? I do not find a header_php_no_ppwpp_gt_20 folder there.
  2. Do i just put it on the first line? Sorry for the newbie question, i should be ashamed :(

Thank you!

A new file named as provided is what is recommended. Everything after header_php could be whatever desired, but something recognizable has been suggested. :)
So the file would have the name provided and the contents of what was pasted. Be sure not to have any spaces, blank lines etc before the first <?php.

Also, you may want to change the comparison logic as what has been provided is to deactivate PayPal instead of allow it to be active when greater than 20.00. Would then also change the portion of the filename from gt to lt

4 Jun 2016, 4:05 PM
#10
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,100
Plugin Contributions:
56

Re: Paypal Express Minimum amount [HELP]

Thanks for the catch, mc12345678, that's what I get putting that up pre-coffee.

@thymine, if you take the code below and create the new file /includes/modules/pages/checkout_payment/header_php_no_ppwpp_lt_20.php, you'll be good-to-go. As mc1-8 indicated, the portion of the filename that I've *highlighted *can be anything you want, but it must start with header_php_.

<?php
// -----
// Created by lat9; Copyright (C) 2016 Vinos de Frutas Tropicales
//
// If the order's subtotal is greater than 20 and the PayPal Express Checkout is enabled, disable it!
//
if ($order->info['subtotal'] [B]< [/B]20 && is_object ($paypalwpp)) {
    $paypalwpp->enabled = false;
}