Post by michael14 » Fri Sep 20, 2013 11:56 pm

Is it possible to add a payment method that only an OpenCart administrator can use when creating an order manually?

I want customers to have a PayPal option only, but allow administrators to have PayPal and Checks (for example).

Help is very much appreciated! Thanks ;D

Newbie

Posts

Joined
Mon Mar 05, 2012 10:46 am

Post by Qphoria » Sat Sep 21, 2013 12:15 am

1. EDIT:
catalog/model/payment/<any-payment>.php

2. FIND:

Code: Select all

if ($status) { 
3. REPLACE:

Code: Select all

// Show only if logged in as admin
$this->load->library('user');
$this->user = new User($this->registry);
if (!$this->user->isLogged()) {
    $status = false;
}

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by michael14 » Sat Sep 21, 2013 12:17 am

Wow, great! :) Thanks Qphoria

Newbie

Posts

Joined
Mon Mar 05, 2012 10:46 am

Post by jglidewell » Fri May 06, 2016 5:06 am

This doesn't work with v2.0, can you update the code for 2.0?

Newbie

Posts

Joined
Fri May 06, 2016 3:51 am

Post by Johnathan » Fri May 06, 2016 10:11 pm

2.x versions use an API to get the data from the front, so you should be able to do it by checking for the api_id in the session data:

Code: Select all

IN:
/catalog/model/payment/FILENAME.php

AFTER:
public function getMethod($address, $total) {

ADD:
if (empty($this->session->data['api_id'])) return; 

Image Image Image Image Image


User avatar
Administrator

Posts

Joined
Fri Dec 18, 2009 3:08 am


Post by jglidewell » Fri May 06, 2016 11:06 pm

perfect! thank you.

Newbie

Posts

Joined
Fri May 06, 2016 3:51 am

Post by Benville » Thu Nov 23, 2017 4:13 pm

Sorry for resurrecting an old thread but I'm looking to do this also and I'm struggling a little with the 2.x instructions, can I get a little more detail on how to do this please?

I run a market stall alongside website sales, and would need to add two hidden methods, call them admin-card and admin-cash, for when I manually enter things.

New member

Posts

Joined
Fri Mar 04, 2016 7:01 pm

Post by Johnathan » Thu Nov 23, 2017 11:26 pm

Are you using OpenCart 2.3? The edit is exactly the same in OpenCart 2.3, but filepaths are different. The new filepath would be:

/catalog/model/extension/payment/FILENAME.php

If you actually need to install *new* payment methods, you'll probably need to find new ones in the marketplace, or hire someone to duplicate the extensions for you. It's something you need to have some coding knowledge for.

Image Image Image Image Image


User avatar
Administrator

Posts

Joined
Fri Dec 18, 2009 3:08 am


Post by Benville » Fri Nov 24, 2017 12:12 am

Couldn't I just edit/rename two existing payments that don't do anything, like say cash on collection and cheque or something like that.

I mean you say "just get the api id from session data", that just goes over my head, can you explain that?

And do we add your code to qphorias code or is qphorias edit not relevant?

New member

Posts

Joined
Fri Mar 04, 2016 7:01 pm

Post by straightlight » Fri Nov 24, 2017 12:19 am

Benville wrote:
Fri Nov 24, 2017 12:12 am
Couldn't I just edit/rename two existing payments that don't do anything, like say cash on collection and cheque or something like that.

I mean you say "just get the api id from session data", that just goes over my head, can you explain that?

And do we add your code to qphorias code or is qphorias edit not relevant?
Editing and / or renaming any extensions provided from the core could impact the store upon each upgrades rather than duplicating those modules.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by Johnathan » Sun Nov 26, 2017 12:19 am

1. Yes, you can rename the titles of the payment methods if you want. Just don't edit the actual code of the payment method.

2. Qphoria's code is for OpenCart 1.5. Mine is for OpenCart 2 and 3.

3. You don't need to understand how my code works, if it's over your head. Just add it and that payment method should only appear for admin users.

Image Image Image Image Image


User avatar
Administrator

Posts

Joined
Fri Dec 18, 2009 3:08 am


Post by Benville » Sun Nov 26, 2017 1:18 am

Where do I get the api id from though? I don't understand what you mean by just getting it the session data, please

New member

Posts

Joined
Fri Mar 04, 2016 7:01 pm

Post by straightlight » Sun Nov 26, 2017 1:22 am

The API ID can only be obtained starting from Opencart v2.x releases and above originally from the core.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by Johnathan » Sun Nov 26, 2017 11:47 pm

Benville wrote:
Sun Nov 26, 2017 1:18 am
Where do I get the api id from though? I don't understand what you mean by just getting it the session data, please
You don't need to get the api_id. That's just the variable you're checking for in the code I suggested. Again, you don't need to know how it works, just make the edit exactly as I've described.

Image Image Image Image Image


User avatar
Administrator

Posts

Joined
Fri Dec 18, 2009 3:08 am


Post by Benville » Mon Nov 27, 2017 12:43 am

Oh so I just write the code as api_id, I thought from your comment that I had to specifically write it in. Okay thank you for explaining

New member

Posts

Joined
Fri Mar 04, 2016 7:01 pm

Post by davecook80 » Sat Mar 30, 2019 10:31 am

Hi Guys,

I'm tiring to hide one payment method from being selectable in admin orders entry "credit card online"(so only selectable from online store checkout)

Is there a similer way to do this on admin side?

Thanks heaps for reading my post and for any advice ;D

User avatar
New member

Posts

Joined
Fri Nov 01, 2013 3:25 am
Location - Australia

Post by straightlight » Sat Mar 30, 2019 7:23 pm

Is there a similer way to do this on admin side?
With v2.x releases and above, that is not necessary since it already requires an API access to apply those requests from the admin via the catalog. Restricting the api_id such as demonstrated by Johnathan above should do it for credit cards as needed.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: No registered users and 123 guests