Post by v77 » Wed Jun 07, 2017 8:28 am

I am new to Opencart modules development, I have created this very simple module to catch the event of adding a new product,
this module is for Opencart 2.3.0.2, and I can install/uninstall it, and the event is getting registered yet it does not get triggered when adding a new product, any ideas why?

Code: Select all

class ControllerExtensionModuleFselias extends Controller
{
    public function install()
    {
        $this->load->model('extension/event');
         $this->model_extension_event->addEvent('fselias', 'admin/model/catalog/product/addProduct/after', 'extension/module/fselias/add_product');
    }

    public function uninstall()
    {
        $this->load->model('extension/event');
        $this->model_extension_event->deleteEvent('fselias');
    }

    public function add_product($route, $product_id)
    {
        $this->load->model('sale/order');
        $this->load->model('catalog/product');

        $log = date("F j, Y, g:i a") . ': ' . $route . ': ' . $product_id . PHP_EOL;
        file_put_contents('./products_log_' . date("j.n.Y") . '.txt', $log, FILE_APPEND);
    }

}

v77
Newbie

Posts

Joined
Tue Jan 31, 2012 3:46 am

Post by chrisranjana.com » Wed Jun 07, 2017 2:53 pm

Have you tried giving the full directory path for the file './products_log_' ? and of course the directory just about the file needs to be writable by the web server

Chris, Opencart Developers and Programmers,
www.chrisranjana.com


User avatar
Active Member

Posts

Joined
Thu Feb 26, 2009 2:23 am
Location - chennai, India

Post by v77 » Wed Jun 07, 2017 3:11 pm

Yes, I did and copied the same lines inside install and uninstall functions, and the log file is getting updated normally, so it seems that OC is not firing the event for some reason.

I put these lines inside the install function, and it is working fine when I click on Install button:

Code: Select all

        $log = date("F j, Y, g:i a") . ': ' . 'Installed' . PHP_EOL;
        file_put_contents('./products_log_' . date("j.n.Y") . '.txt', $log, FILE_APPEND);

the file "admin/products_log_5.6.2017.txt" showed up and has the line:
June 5, 2017, 11:35 am: Installed

v77
Newbie

Posts

Joined
Tue Jan 31, 2012 3:46 am

Post by chrisranjana.com » Wed Jun 07, 2017 3:22 pm

Are you using any other module/extension or is it the default installation of Version 2.3.0.2 ?

Chris, Opencart Developers and Programmers,
www.chrisranjana.com


User avatar
Active Member

Posts

Joined
Thu Feb 26, 2009 2:23 am
Location - chennai, India

Post by kestas » Wed Jun 07, 2017 4:22 pm

Hi,

try to add this string

Code: Select all

global $log;

before

Code: Select all

 $log = date("F j, Y, g:i a") . ': ' . $route . ': ' . $product_id . PHP_EOL;
        file_put_contents('./products_log_' . date("j.n.Y") . '.txt', $log, FILE_APPEND);

Custom OpenCart modules and solutions. You can write PM with additional questions... Extensions you can find here


Active Member

Posts

Joined
Tue Oct 12, 2010 2:23 am

Post by v77 » Wed Jun 07, 2017 4:34 pm

chrisranjana.com wrote:
Wed Jun 07, 2017 3:22 pm
Are you using any other module/extension or is it the default installation of Version 2.3.0.2 ?
Yes, I have this extension installed https://store.webkul.com/OpenCart-MarketPlace.html

v77
Newbie

Posts

Joined
Tue Jan 31, 2012 3:46 am

Post by v77 » Wed Jun 07, 2017 4:37 pm

kestas wrote:
Wed Jun 07, 2017 4:22 pm
Hi,

try to add this string

Code: Select all

global $log;

before

Code: Select all

 $log = date("F j, Y, g:i a") . ': ' . $route . ': ' . $product_id . PHP_EOL;
        file_put_contents('./products_log_' . date("j.n.Y") . '.txt', $log, FILE_APPEND);
The variable $log is assigned inside the function only, why do I need to call it global?

v77
Newbie

Posts

Joined
Tue Jan 31, 2012 3:46 am

Post by kestas » Wed Jun 07, 2017 5:26 pm

v77 wrote:
Wed Jun 07, 2017 4:37 pm
kestas wrote:
Wed Jun 07, 2017 4:22 pm
Hi,

try to add this string

Code: Select all

global $log;

before

Code: Select all

 $log = date("F j, Y, g:i a") . ': ' . $route . ': ' . $product_id . PHP_EOL;
        file_put_contents('./products_log_' . date("j.n.Y") . '.txt', $log, FILE_APPEND);
The variable $log is assigned inside the function only, why do I need to call it global?
Yes you are right. I not carefully looked at your code... sorry
I catching events like this code below...

Code: Select all

$log = new Log('paymentmodule.log');
            $log->write('Answer from Leasing... Order ID: ' . $data['order_id'] . '; Order Status: ' . $data['status_sb'] . '; ' . $data['text_result_deal'] . '; ' . 'Validated: ' . $data['testSignature']);
		} else { null; }
This piece of the code creating file if not exist and adding new line on the each event... Maybe this put you on the way...

Custom OpenCart modules and solutions. You can write PM with additional questions... Extensions you can find here


Active Member

Posts

Joined
Tue Oct 12, 2010 2:23 am
Who is online

Users browsing this forum: No registered users and 4 guests