Forums / All Other Contributions/Addons / Applies to FEC and PP Express Checkout - Checkout with insufficient stock

Applies to FEC and PP Express Checkout - Checkout with insufficient stock

Locked

Started by kiddo on 10 Jul 2009, 4:32 AM · Views: 1,664

Results 1 to 3 of 3
This thread is locked. New replies are disabled.
10 Jul 2009, 4:32 AM
#1
kiddo avatar

kiddo

Totally Zenned

Join Date:
Jul 2006
Location:
SF Bay Area
Posts:
837
Plugin Contributions:
1

Applies to FEC and PP Express Checkout - Checkout with insufficient stock

I'm loosing some hair today with sites using either or both PP Express checkout button and FEC module.

Applies to version 1.3.8

Other installed mods: Stock by Attribute 4.7 (not Multi or Ajax)

Symptom: Checkout is allowed with insufficient stock even with proper settings in admin--Stock ie: don't allow checkout.

To fix the PP Express problem: edit ipn_main_handler.php

Near the top, find the line that says:

/**
 * handle Express Checkout processing:
 */
if (isset($_GET['type']) && $_GET['type'] == 'ec') {
  // this is an EC handler request
  require('includes/application_top.php');

and just BELOW that, add the stock check code:

  // Stock Check
  if ( (STOCK_CHECK == 'true') && (STOCK_ALLOW_CHECKOUT != 'true') ) {
	  $products = $_SESSION['cart']->get_products();
	  for ($i=0, $n=sizeof($products); $i<$n; $i++) {
  	  if (zen_check_stock($products[$i]['id'], $products[$i]['quantity'])) {
    	  zen_redirect(zen_href_link(FILENAME_SHOPPING_CART));
    	  break;
      }
    }
  }

Now for FEC fix...

in includes/modules/pages/no_account/header_php.php find:

// redirect to homepage if no products in cart
if (!$_SESSION['cart']->count_contents() >= 1) {
  zen_redirect(zen_href_link(FILENAME_DEFAULT, '', 'NONSSL'));
}

and just BELOW that, add the stock check code:

  // Stock Check
  if ( (STOCK_CHECK == 'true') && (STOCK_ALLOW_CHECKOUT != 'true') ) {
	  $products = $_SESSION['cart']->get_products();
	  for ($i=0, $n=sizeof($products); $i<$n; $i++) {
  	  if (zen_check_stock($products[$i]['id'], $products[$i]['quantity'])) {
    	  zen_redirect(zen_href_link(FILENAME_SHOPPING_CART));
    	  break;
      }
    }
  }

Now at least in these two places, no more checking out with not enough stock.

Note: These changes work and make sense to me to solve a problem. I looked all over forum for similar fix and see nothing. But then search here isn't so good.

Be careful and happy hacking.

Kiddo

10 Jul 2009, 4:54 AM
#2
kiddo avatar

kiddo

Totally Zenned

Join Date:
Jul 2006
Location:
SF Bay Area
Posts:
837
Plugin Contributions:
1

Re: Applies to FEC and PP Express Checkout - Checkout with insufficient stock

One quick note for FEC users.

I think you can put the same inventory check code into:

includes/modules/pages/login/header_php.php

On site I am working on, this is bypassed (no option to create account at all)

So I think for more standard FEC, the file I mention above would be the proper place.

probably right AFTER:

// redirect the customer to a friendly cookie-must-be-enabled page if cookies are disabled (or the session has not started)
if ($session_started == false) {
  zen_redirect(zen_href_link(FILENAME_COOKIE_USAGE));
}
18 Jul 2009, 9:27 PM
#3
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,511
Plugin Contributions:
176

Re: Applies to FEC and PP Express Checkout - Checkout with insufficient stock

Insomuch as the PayPal code is affected, the code for v1.3.9 will be updated to have Express Checkout do a stock check before commencing checkout.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.