Zencart MOD: Limit Paypal to specific categories

From DP

Jump to: navigation , search

Contents

Goal

This is how we limit Paypal to the "buy now" PCB category in Zencart.

Changes

Add category check function

    /**
   * Is anything in card where $check_what!=$check_value
   * We use to check if any products are from outside a caregory
   *  if ($_SESSION['cart']->cat_cart_check('master_categories_id','4') > 0)
   *
   * $check_what is the fieldname example: 'products_is_free'
   * $check_value is the value being tested for - default is 1
   * Syntax: $_SESSION['cart']->in_cart_check('product_is_free','1');
   *
   * @param string product field to check
   * @param mixed value to check for
   * @return integer number of items matching restraint
   */
  function cat_cart_check($check_what, $check_value='1') {
    global $db;
    // if nothing is in cart return 0
    if (!is_array($this->contents)) return 0;
 
    // compute total quantity for field
    $in_cart_check_qty=0;
 
    reset($this->contents);
    while (list($products_id, ) = each($this->contents)) {
      $testing_id = zen_get_prid($products_id);
      // check if field it true
      $product_check = $db->Execute("select " . $check_what . " as check_it from " . TABLE_PRODUCTS . " where products_id='" . $testing_id . "' and ".$check_what."!='".$check_value."' limit 1");
      if ($product_check->RecordCount() >0) {
        return 1; //$in_cart_check_qty += $this->contents[$products_id]['qty'];
      }
    }
    return 0; //$in_cart_check_qty;
  }

Add to /includes/classes/chopping_cart.php at line 1490:

  • Checks if any products in the cart do NOT have the specified property value

Disable payment method

// disable for categories in cart
    if (IS_ADMIN_FLAG == false) {
      if ($_SESSION['cart']->cat_cart_check('master_categories_id','4') > 0){
          $this->enabled = false;
      }
    }

Add to \includes\modules\payment\paypalwpp.php at line 192:

  • Disables paypal if any products are outside category 4
  • Replace 4 in ('master_categories_id','4') with the cPath number of the category

Disable payment button

  // disable paypal for all but 'buy now' category
        if (IS_ADMIN_FLAG == false) {
          if ($_SESSION['cart']->cat_cart_check('master_categories_id','4') > 0){
            $paypalec_enabled = false;
          }
        }

Add to includes\modules\payment\paypal\tpl_ec_button.php at line 46:

  • Disables the shopping cart view PayPal checkout button if any products are outside category 4
  • Replace 4 in ('master_categories_id','4') with the cPath number of the category

Add payment warning

define('TEXT_NO_PAYMENT_OPTIONS_AVAILABLE','<span class="alert">Most PCB are only available with a free coupon code.</span><br />Only <u>Buy Now</u> PCBs can be purchased with Paypal.<br/>It is not possible to mix free and Buy Now PCBs in the same order.');

Change in /includes/languages/english/checkout_payment.php line 26:

  • Message when there are no payment options available

Update cart notice

define('TEXT_INFORMATION', 'Most PCBs are only available with a free coupon. <br/><u>Buy Now</u> PCBs can be purchased with Paypal for $3.95 each, plus $2.00 shipping per 2 PCBs.<br/>It is not possible to mix free and Buy Now PCBs in the same order.');

Change in includes/languages/english/shopping_cart.php line

  • Message when viewing the cart