Zen Cart Logo
Forums / Setting Up Categories, Products, Attributes / How to restrict payment method by category?

How to restrict payment method by category?

Locked

Views: 6,911

Results 1 to 18 of 18
This thread is locked. New replies are disabled.
4 Oct 2007, 6:41 PM
#1
glv avatar

glv

New Zenner

Join Date:
Oct 2007
Posts:
29
Plugin Contributions:
0

How to restrict payment method by category?

Hello,

Let me start off by making the typical statement that I swear I searched. Second of all, I have very limited php knowledge, moderate html knowledge, and have only been using zen-cart for about a week. :)

Here is my problem...

My company sells parts right now that are not very expensive. We are building this site to be able to take credit card orders and it works well.

The site has impressed my bosses so much that they now want to sell very expensive equipment on it as well. However they do not want people to be able to buy the equipment with a credit card (due to the huge hit we take based on the percentage fees).

I have all of the equipment we are offering for sale in a new category. How can I make it so that items from this specific category have to be purchased with a specific payment method (I have a "send invoice" payment method that I hacked in).

The only other catch I see with this is if they try to add "equipment" and "parts" to their cart. Would it then just restrict the whole order to the "send invoice" payment method? That would be acceptable, I just don't want them to get an error.

Thanks in advance for any help, I will be checking back like every 5 seconds :) (but not whining in a post each time).

Once again, I thank you very much for any help you can provide me.

Nick

4 Oct 2007, 7:09 PM
#2
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: How to restrict payment method by category?

Where'd you get the "send invoice" module?

5 Oct 2007, 2:13 PM
#3
glv avatar

glv

New Zenner

Join Date:
Oct 2007
Posts:
29
Plugin Contributions:
0

Re: How to restrict payment method by category?

DrByte:

Where'd you get the "send invoice" module?

I'm sorry it is called "Account Holder" ... I changed the language file to make it say "Send Invoice".

I take it that means you don't know the answer to my question though?

5 Oct 2007, 2:26 PM
#4
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: How to restrict payment method by category?

GLV:

I take it that means you don't know the answer to my question though?

Not without seeing the code for the module. Perhaps you could zip and attach it?

5 Oct 2007, 4:01 PM
#5
glv avatar

glv

New Zenner

Join Date:
Oct 2007
Posts:
29
Plugin Contributions:
0

Re: How to restrict payment method by category?

I will gladly do that later this afternoon, but how does the one specific module affect it? All that module does is add a payment type. It seems like I would need to make changes to the core to restrict the purchasing of items in a certain category to one particular payment type "ID".

I will edit this with the attachment shortly though.

5 Oct 2007, 4:52 PM
#7
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: How to restrict payment method by category?

Three edits to /includes/modules/payment/accountholder.php:

  1. Line 115 changes from this:```
    return array('MODULE_PAYMENT_ACCOUNTHOLDER_STATUS', 'MODULE_PAYMENT_ACCOUNTHOLDER_ZONE', 'MODULE_PAYMENT_ACCOUNTHOLDER_ORDER_STATUS_ID', 'MODULE_PAYMENT_ACCOUNTHOLDER_SORT_ORDER', 'MODULE_PAYMENT_ACCOUNTHOLDER_PAYTO');

to:```
      return array('MODULE_PAYMENT_ACCOUNTHOLDER_STATUS', 'MODULE_PAYMENT_ACCOUNTHOLDER_ZONE', 'MODULE_PAYMENT_ACCOUNTHOLDER_ORDER_STATUS_ID', 'MODULE_PAYMENT_ACCOUNTHOLDER_SORT_ORDER', 'MODULE_PAYMENT_ACCOUNTHOLDER_PAYTO'[B], 'MODULE_PAYMENT_ACCOUNTHOLDER_CATEGORIES'[/B]);
  1. At Line 107, insert new row:
      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Restriction Categories', 'MODULE_PAYMENT_ACCOUNTHOLDER_CATEGORIES', '', 'Which categories is this module restricted to? (separated by commas)', '6', '0', now())");
  1. At line 56, insert new lines as shown highlighted here:```
    if ($check_flag == false) {
    $this->enabled = false;
    }
    }
    //Check to be sure that this module is allowed to apply -- restricted to certain categories, based on master_categories_id
    if ($this->enabled == true) {
    $check_flag = false;
    $allowed_cats = explode(',',preg_replace('/[^0-9],/', '',MODULE_PAYMENT_ACCOUNTHOLDER_CATEGORIES));
    reset($_SESSION['cart']->contents);
    while (list($key,) = each($_SESSION['cart']->contents)) {
    foreach($allowed_cats as $cat) {
    if (zen_product_in_category($key, $cat)) $check_flag = true;
    }
    }
    if ($check_flag == false) $this->enabled = false;
    }

    }

    function javascript_validation() {


After uploading the changes, remove and re-install the module. Then edit its settings to list the categories to which this module applies.

This module will thus show up if products from the specified categories are in the cart ... whether or not there are other products from other categories.
5 Oct 2007, 4:58 PM
#8
glv avatar

glv

New Zenner

Join Date:
Oct 2007
Posts:
29
Plugin Contributions:
0

Re: How to restrict payment method by category?

Holy cow ... I never expected that kind of help, I will do this right now and post back the results!

THANK YOU !!!!!!!!!!!!

5 Oct 2007, 5:13 PM
#9
glv avatar

glv

New Zenner

Join Date:
Oct 2007
Posts:
29
Plugin Contributions:
0

Re: How to restrict payment method by category?

DrByte ... we have a small problem :(

I think you might have misunderstood what I wanted to do.

I have a bunch of categories that I want people to be able to use any of the payment methods for ...

Now I have one new category that I want this to be the ONLY form of payment that we take if an item from this category is present, even if its a mixed cart.

So right now this is what happens...
Normal items ... can use all payment methods EXCEPT this one (should be all methods)
Items from this category ... can use all payment methods (should be ONLY this method)
Items from this category AND others ... can use all payment methods (should be ONLY this method)

So does this mean I would have to make edits like this to the other payment types we take instead?

5 Oct 2007, 5:15 PM
#10
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: How to restrict payment method by category?

GLV:

So does this mean I would have to make edits like this to the other payment types we take instead?

Yes, I suppose that's what you'll need to do. The coding concept is the same for almost any payment module.

5 Oct 2007, 5:30 PM
#11
glv avatar

glv

New Zenner

Join Date:
Oct 2007
Posts:
29
Plugin Contributions:
0

Re: How to restrict payment method by category?

Alright I will revert back that one and try the edits on the payment method I need to restrict. Thanks though, this hopefully should still work.

Can I ask you a slightly off topic question? I downloaded the layout box called "category_listing_box" but it won't install ... I think I did it wrong the first time and deleted it from my layout boxes, it had a "missing missing" over it and the option to delete it. I did that, is it now somehow ignoring it even though I put the files back?

5 Oct 2007, 5:34 PM
#12
glv avatar

glv

New Zenner

Join Date:
Oct 2007
Posts:
29
Plugin Contributions:
0

Re: How to restrict payment method by category?

I can't figure out how to make the edits to the other payment types. I need to edit paypal.php and moneyorder.php but the line numbers for where i need to put this stuff are obviously different and I can't even search for what I am replacing as its totally different :-/ ?

5 Oct 2007, 5:46 PM
#13
glv avatar

glv

New Zenner

Join Date:
Oct 2007
Posts:
29
Plugin Contributions:
0

Re: How to restrict payment method by category?

And is there an easy edit to make it restricted FROM rather than TO ? I think I have it working for the moneyorder payment method, just paypal seems different...

And now the setting doesn't work right for mixed carts, it allows the option to come through, when I need it blocked :(

5 Oct 2007, 5:59 PM
#14
glv avatar

glv

New Zenner

Join Date:
Oct 2007
Posts:
29
Plugin Contributions:
0

Re: How to restrict payment method by category?

Ok I changed it to this and it now works PERFECTLY for the money order payment type, and I even reversed the mixed categories part, and it works :) Thank you! Halfway there! So now basically it is checking my input to restrict FROM (and I changed the wording to match)

  1. At line 56, insert new lines as shown highlighted here:```
    if ($check_flag == false) {
    $this->enabled = false;
    }
    }
    //Check to be sure that this module is allowed to apply -- restricted to certain categories, based on master_categories_id
    if ($this->enabled == true) {
    $check_flag = true;
    $allowed_cats = explode(',',preg_replace('/[^0-9],/', '',MODULE_PAYMENT_MONEYORDER_CATEGORIES));
    reset($_SESSION['cart']->contents);
    while (list($key,) = each($_SESSION['cart']->contents)) {
    foreach($allowed_cats as $cat) {
    if (zen_product_in_category($key, $cat)) $check_flag = false;
    }
    }
    if ($check_flag == false) $this->enabled = false;
    }

    }

    function javascript_validation() {


Now just gotta figure out how to fight through paypal.php!
5 Oct 2007, 6:14 PM
#15
glv avatar

glv

New Zenner

Join Date:
Oct 2007
Posts:
29
Plugin Contributions:
0

Re: How to restrict payment method by category?

Ok my last post I swear!

Thank you so much, I finally figured out what was wrong with paypal and got it working. This helps so much!

Nick

14 Jan 2008, 2:42 PM
#17
glv avatar

glv

New Zenner

Join Date:
Oct 2007
Posts:
29
Plugin Contributions:
0

Re: How to restrict payment method by category?

DrByte...

I have another similar question.

I need to add a new shipping "method" that is basically just that we will contact them with a shipping quote. What is the best way to do this?

I imagine I would customize some already existing method...

The reason I am asking this here is I need to restrict 2 of my categories to this shipping method (the same 2 categories that I restricted the payment method with you on this thread).

Thank you for suggestions.

14 Jan 2008, 6:21 PM
#18
glv avatar

glv

New Zenner

Join Date:
Oct 2007
Posts:
29
Plugin Contributions:
0

Re: How to restrict payment method by category?

I got it working with adapting the stuff we did for the payment modules and using that on my table shipping module, so now the table rates are not available if any items are included from the 2 categories that require freight shipping.

So that is great, but I have an error on line 86 and 87 of that table.php and I think it is making my store run REALLY SLOW ... but it is working...

The error is:

Warning: reset() [function.reset]: Passed variable is not an array or object in /modifiedurlforprivacy.com/includes/modules/shipping/table.php on line 86

Warning: Variable passed to each() is not an array or object in /modifiedurlforprivacy.com/includes/modules/shipping/table.php on line 87