Post by nongetjie » Fri Oct 30, 2020 3:37 pm

Hi

I'm developing a script for shop maintenance to delete the oldest 500 disabled products. I want to use the 'deleteProduct' function of the admin Product model, but I can't get the model to load. Below is what I have. What am I doing wrong?

Code: Select all

include '/public/admin/config.php';
include '/public/system/startup.php';

// Registry
$registry = new Registry();

// Config
$config = new Config();
$config->load('default');
$registry->set('config', $config);

// Loader
$loader = new Loader($registry);
$registry->set('load', $loader);

// Database
$db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE, DB_PORT);
$registry->set('db', $db);

$query = $db->query("select p.product_id, pd.name, p.date_modified from product p inner join product_description pd on pd.product_id = p.product_id where p.status = 0 and pd.language_id = 1 order by p.date_modified asc limit 2");
foreach ($query->rows as $product)
{
    //do the delete here as soon as I get the model function
}

// Model
$loader->model('catalog/product');
$model = $registry->get('model_catalog_product');
$result = $model->getProduct(1); //want to test using the getProduct() function for obvious reasons
var_dump($result);
this results in error message
PHP Fatal error: Uncaught Error: Call to a member function trigger() on null in /vagrant/public/storage/modification/system/engine/loader.php:240
Stack trace:
#0 /vagrant/public/system/engine/proxy.php(47): Loader->{closure}(Array, Array)
#1 /vagrant/scripts/delete-products.php(37): Proxy->__call('getProduct', Array)
#2 {main}
thrown in /vagrant/public/storage/modification/system/engine/loader.php on line 240
Who knows the way to load the model and use the functions?

New member

Posts

Joined
Wed Nov 07, 2012 8:28 pm

Post by straightlight » Fri Oct 30, 2020 7:20 pm


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 nongetjie » Fri Oct 30, 2020 8:33 pm

straightlight wrote:
Fri Oct 30, 2020 7:20 pm
They can be used this way: https://github.com/straightlight/openca ... upload/api .
Tnx, do you maybe have any documentation on how to use?

New member

Posts

Joined
Wed Nov 07, 2012 8:28 pm

Post by straightlight » Fri Oct 30, 2020 9:40 pm

nongetjie wrote:
Fri Oct 30, 2020 8:33 pm
straightlight wrote:
Fri Oct 30, 2020 7:20 pm
They can be used this way: https://github.com/straightlight/openca ... upload/api .
Tnx, do you maybe have any documentation on how to use?
Of course. Once hooked with the index.php file, all you need to do is to look at the controllers and models the way the API objects are being used with the core objects. :)

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 22 guests