Post by noxtras » Thu Apr 15, 2021 3:48 pm

Hello,
I have to import some products into OC. I have a file named import.php. I can do the import if I make a file controller/catalog/import.php, but how do I have access to ->model_catalog_product->addProduct($productData); from a file that is not loaded as a controller (a totally new file).
At the moment I have this:

Code: Select all

include('./config.php');
require_once(DIR_SYSTEM . 'startup.php');
$registry = new Registry();
$productData = array(
    'name' => 'Product Name Here',
    'model' => 'ABC123',
);
// Attempt to pass the assoc array to the add Product method
$x = $registry->model_catalog_product->addProduct($productData);
Last edited by noxtras on Fri Apr 16, 2021 9:26 pm, edited 1 time in total.

Newbie

Posts

Joined
Thu Apr 15, 2021 3:42 pm

Post by paulfeakins » Thu Apr 15, 2021 6:21 pm

Don't do it that way.

Instead make your import script as a controller that you browse to through index.php?route=folder/controller-filename/method-name.

For quick, professional OpenCart support please email info@antropy.co.uk


User avatar
Guru Member
Online

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - Reigate, Surrey, United Kingdom

Post by noxtras » Thu Apr 15, 2021 6:57 pm

It works like that, i know, but I want it to work outside of admin.
Isn't there an easy way to start just some of the classes?

Newbie

Posts

Joined
Thu Apr 15, 2021 3:42 pm

Post by straightlight » Thu Apr 15, 2021 8:13 pm


The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

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

Post by noxtras » Thu Apr 15, 2021 8:49 pm

Thanks for the link, but I don't get what the solution is there...

Newbie

Posts

Joined
Thu Apr 15, 2021 3:42 pm

Post by noxtras » Thu Apr 15, 2021 8:50 pm

paulfeakins wrote:
Thu Apr 15, 2021 6:21 pm
Don't do it that way.

Instead make your import script as a controller that you browse to through index.php?route=folder/controller-filename/method-name.
Even with your method, I actually just get a blank white page.. I've added the rights for the user and I'm logged in... no errors in the log file, neither... Please help.

Newbie

Posts

Joined
Thu Apr 15, 2021 3:42 pm

Post by straightlight » Thu Apr 15, 2021 8:53 pm

noxtras wrote:
Thu Apr 15, 2021 8:49 pm
Thanks for the link, but I don't get what the solution is there...
It uses an API with GuzzleHttp as demonstrated in the link. Please take all the time that you need to read it.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

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

Post by noxtras » Thu Apr 15, 2021 9:56 pm

Found the blank page problem:
The class name has to be ControllerFolderFile extends Controller.

Newbie

Posts

Joined
Thu Apr 15, 2021 3:42 pm

Post by straightlight » Thu Apr 15, 2021 10:05 pm

noxtras wrote:
Thu Apr 15, 2021 9:56 pm
Found the blank page problem:
The class name has to be ControllerFolderFile extends Controller.
Now that the issue has been solved, please add [SOLVED] at the beginning of the subject line on your first post.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

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

Post by noxtras » Fri Apr 16, 2021 9:25 pm

Hi,
Well actually my main problem wasn't solved: to access OC function in a separate php file, outside of Controller class. But as @paulfeakins suggested, it was easy just copying the file inside controllers folder, adding user rights and login..
If anyone knows a way that doesn't require login and user rights to access a 'working' function inside models, or controllers. Is welcome to share:)

Newbie

Posts

Joined
Thu Apr 15, 2021 3:42 pm

Post by straightlight » Fri Apr 16, 2021 11:32 pm

noxtras wrote:
Fri Apr 16, 2021 9:25 pm
Hi,
Well actually my main problem wasn't solved: to access OC function in a separate php file, outside of Controller class. But as @paulfeakins suggested, it was easy just copying the file inside controllers folder, adding user rights and login..
If anyone knows a way that doesn't require login and user rights to access a 'working' function inside models, or controllers. Is welcome to share:)
I would not suggest this without a token string.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


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: before, paulfeakins and 42 guests