Post by goksel1961 » Fri Apr 29, 2022 2:06 pm

Hello,
version 3038
Wrote a modification for /system/library/cart/car.php as follows:

Code: Select all

 <operation>
      <search><![CDATA[
    	$price = $product_special_query->row['price'];
      ]]></search>
      <add position="after"><![CDATA[
     	$special_price = $product_special_query->row['price'];
     	$this->log->write($special_price);
      ]]></add>
    </operation>
and get "Fatal error: Uncaught Error: Call to a member function write() on null in /var/www/storage/modification/system/library/cart/cart.php:193"
line 193 is $this->log->write($special_price);
And in error log:
2022-04-29 5:31:35 - PHP Notice: Undefined property: Cart\Cart::$log in /var/www/storage/modification/system/library/cart/cart.php on line 193
I use this log write function often. I suspected if it cannot be used in library classes but there is one in library/squareup/exception.php line 32 like this
$this->log->write($message);
I miss something but couldn find yet.
Would you please help? Thank you.
Last edited by goksel1961 on Fri Apr 29, 2022 3:01 pm, edited 2 times in total.

New member

Posts

Joined
Wed Apr 10, 2019 10:30 pm

Post by goksel1961 » Fri Apr 29, 2022 3:00 pm

I added following code to the ocmod for same class.
And its fixed , no errors anymore. But no log as well :D .
This is another case , I need to dig it sometime.
Cheers.

Code: Select all

    <operation>
      <search><![CDATA[
    	private $data = array();
      ]]></search>
      <add position="after"><![CDATA[
      private $log;
      private $registry;
      ]]></add>
    </operation>
    <operation>
      <search><![CDATA[
    	$this->weight = $registry->get('weight');
      ]]></search>
      <add position="after"><![CDATA[
        $this->log = $registry->get('log');
        $this->registry = $registry;
      ]]></add>
    </operation>

New member

Posts

Joined
Wed Apr 10, 2019 10:30 pm

Post by kestas » Fri Apr 29, 2022 3:14 pm

read this:
viewtopic.php?t=222713
Hope you should find solution.

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 goksel1961 » Sat Apr 30, 2022 4:27 am

kestas wrote:
Fri Apr 29, 2022 3:14 pm
read this:
viewtopic.php?t=222713
Hope you should find solution.
Thank you for your advice , i checked it out but as i mentioned before , $this ->log ->write is already used in squareup.php class in library. My current problem is
that i cant handle logs in system/library/cart.php with $this->log->write . No error but no log as well. I dont face that problem in catalog classes. I miss something.

New member

Posts

Joined
Wed Apr 10, 2019 10:30 pm

Post by ADD Creative » Sat Apr 30, 2022 5:27 am

Have you tried? After.

Code: Select all

$this->weight = $registry->get('weight');
Adding.

Code: Select all

$this->log = $registry->get('log');

www.add-creative.co.uk


Guru Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by ADD Creative » Sat Apr 30, 2022 5:29 am

I should've added without declaring registry and log.

www.add-creative.co.uk


Guru Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by goksel1961 » Sat Apr 30, 2022 10:00 pm

ADD Creative wrote:
Sat Apr 30, 2022 5:29 am
I should've added without declaring registry and log.
Yes. No error but no log as well.

Code: Select all

 <file path="system/library/cart/cart.php">
    <operation>
      <search><![CDATA[
    	$this->weight = $registry->get('weight');
      ]]></search>
      <add position="after"><![CDATA[
        $this->log = $registry->get('log');

      ]]></add>
    </operation>
    
    
    <operation>
      <search><![CDATA[
      $price = $product_query->row['price'];
      ]]></search>
      <add position="after"><![CDATA[
      $main_price=$price;
      $this->log->write ("tytyt");
      ]]></add>
    </operation>

New member

Posts

Joined
Wed Apr 10, 2019 10:30 pm

Post by straightlight » Sat Apr 30, 2022 11:21 pm

goksel1961 wrote:
Sat Apr 30, 2022 10:00 pm
ADD Creative wrote:
Sat Apr 30, 2022 5:29 am
I should've added without declaring registry and log.
Yes. No error but no log as well.

Code: Select all

 <file path="system/library/cart/cart.php">
    <operation>
      <search><![CDATA[
    	$this->weight = $registry->get('weight');
      ]]></search>
      <add position="after"><![CDATA[
        $this->log = $registry->get('log');

      ]]></add>
    </operation>
    
    
    <operation>
      <search><![CDATA[
      $price = $product_query->row['price'];
      ]]></search>
      <add position="after"><![CDATA[
      $main_price=$price;
      $this->log->write ("tytyt");
      ]]></add>
    </operation>
Where is your logs folder located?

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 goksel1961 » Mon May 02, 2022 5:35 pm

straightlight wrote:
Sat Apr 30, 2022 11:21 pm
goksel1961 wrote:
Sat Apr 30, 2022 10:00 pm
ADD Creative wrote:
Sat Apr 30, 2022 5:29 am
I should've added without declaring registry and log.
Yes. No error but no log as well.

Code: Select all

 <file path="system/library/cart/cart.php">
    <operation>
      <search><![CDATA[
    	$this->weight = $registry->get('weight');
      ]]></search>
      <add position="after"><![CDATA[
        $this->log = $registry->get('log');

      ]]></add>
    </operation>
    
    
    <operation>
      <search><![CDATA[
      $price = $product_query->row['price'];
      ]]></search>
      <add position="after"><![CDATA[
      $main_price=$price;
      $this->log->write ("tytyt");
      ]]></add>
    </operation>
Where is your logs folder located?
/var/www/storage/logs

New member

Posts

Joined
Wed Apr 10, 2019 10:30 pm

Post by ADD Creative » Mon May 02, 2022 7:02 pm

goksel1961 wrote:
Mon May 02, 2022 5:35 pm
/var/www/storage/logs
The location doesn't look correct. The storage folder should be at the same level as the web root or under system. But that shouldn't stop the log being written.

Do you see any log file at all? Is it empty or just your messages not appearing? Have you tested you can log from a controller?

www.add-creative.co.uk


Guru Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by straightlight » Mon May 02, 2022 9:55 pm

goksel1961 wrote:
Mon May 02, 2022 5:35 pm
straightlight wrote:
Sat Apr 30, 2022 11:21 pm
goksel1961 wrote:
Sat Apr 30, 2022 10:00 pm

Yes. No error but no log as well.

Code: Select all

 <file path="system/library/cart/cart.php">
    <operation>
      <search><![CDATA[
    	$this->weight = $registry->get('weight');
      ]]></search>
      <add position="after"><![CDATA[
        $this->log = $registry->get('log');

      ]]></add>
    </operation>
    
    
    <operation>
      <search><![CDATA[
      $price = $product_query->row['price'];
      ]]></search>
      <add position="after"><![CDATA[
      $main_price=$price;
      $this->log->write ("tytyt");
      ]]></add>
    </operation>
Where is your logs folder located?
/var/www/storage/logs
Ensure to move your storage folder along with the sub-folders outside of your www folder and edit both config.php files (DIR_STORAGE) accordingly. Then, ensure that recursive folder permissions (CHMOD) has been set (not on files) to 0755. File permissions should be set by default to: 0644 recursively.

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 goksel1961 » Thu May 05, 2022 3:34 am

ADD Creative wrote:
Mon May 02, 2022 7:02 pm
goksel1961 wrote:
Mon May 02, 2022 5:35 pm
/var/www/storage/logs
The location doesn't look correct. The storage folder should be at the same level as the web root or under system. But that shouldn't stop the log being written.

Do you see any log file at all? Is it empty or just your messages not appearing? Have you tested you can log from a controller?
Exactly. As I mentioned before, i can write log from anywhere in controller. Works perfectly. I cant write log only from library (cart.php) .

New member

Posts

Joined
Wed Apr 10, 2019 10:30 pm

Post by straightlight » Thu May 05, 2022 3:51 am

goksel1961 wrote:
Thu May 05, 2022 3:34 am
ADD Creative wrote:
Mon May 02, 2022 7:02 pm
goksel1961 wrote:
Mon May 02, 2022 5:35 pm
/var/www/storage/logs
The location doesn't look correct. The storage folder should be at the same level as the web root or under system. But that shouldn't stop the log being written.

Do you see any log file at all? Is it empty or just your messages not appearing? Have you tested you can log from a controller?
Exactly. As I mentioned before, i can write log from anywhere in controller. Works perfectly. I cant write log only from library (cart.php) .
From which software editor are you editing PHP files? ...

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 ADD Creative » Thu May 05, 2022 7:13 am

goksel1961 wrote:
Thu May 05, 2022 3:34 am
Exactly. As I mentioned before, i can write log from anywhere in controller. Works perfectly. I cant write log only from library (cart.php) .
Just tested and I could log from system/library/cart/cart.php without any problems. Have you check the file in the modification folder to check it's correct? Are you using any other extensions that are modifying system/library/cart/cart.php or the calling of the cart functions?

www.add-creative.co.uk


Guru Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by goksel1961 » Thu May 05, 2022 9:25 am

straightlight wrote:
Thu May 05, 2022 3:51 am
goksel1961 wrote:
Thu May 05, 2022 3:34 am
ADD Creative wrote:
Mon May 02, 2022 7:02 pm


The location doesn't look correct. The storage folder should be at the same level as the web root or under system. But that shouldn't stop the log being written.

Do you see any log file at all? Is it empty or just your messages not appearing? Have you tested you can log from a controller?
Exactly. As I mentioned before, i can write log from anywhere in controller. Works perfectly. I cant write log only from library (cart.php) .
From which software editor are you editing PHP files? ...
Kate. Version 19.12.3

New member

Posts

Joined
Wed Apr 10, 2019 10:30 pm

Post by straightlight » Thu May 05, 2022 9:30 am

goksel1961 wrote:
Thu May 05, 2022 9:25 am
straightlight wrote:
Thu May 05, 2022 3:51 am
goksel1961 wrote:
Thu May 05, 2022 3:34 am


Exactly. As I mentioned before, i can write log from anywhere in controller. Works perfectly. I cant write log only from library (cart.php) .
From which software editor are you editing PHP files? ...
Kate. Version 19.12.3
Ensure that this editor uses UTF-8 without BOM encoding.

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 goksel1961 » Thu May 05, 2022 10:20 am

ADD Creative wrote:
Thu May 05, 2022 7:13 am
goksel1961 wrote:
Thu May 05, 2022 3:34 am
Exactly. As I mentioned before, i can write log from anywhere in controller. Works perfectly. I cant write log only from library (cart.php) .
Just tested and I could log from system/library/cart/cart.php without any problems. Have you check the file in the modification folder to check it's correct? Are you using any other extensions that are modifying system/library/cart/cart.php or the calling of the cart functions?
Did you test it with $this->log = $registry->get('log'); declaration? mine should work too then but no log no error still.
Have you check the file in the modification folder to check it's correct?
Yes as shown attached image.
Are you using any other extensions that are modifying system/library/cart/cart.php or the calling of the cart functions?
No. Just this one. And the other modifications i made in this file work perfectly. Just writing logs. No error no logs.
And yes i call a cart function from a model class (getProducts) . And the modification i made in that function.

Attachments

screen01.jpg

screen01.jpg (15.98 KiB) Viewed 5714 times


New member

Posts

Joined
Wed Apr 10, 2019 10:30 pm

Post by goksel1961 » Thu May 05, 2022 10:51 am

straightlight wrote:
Mon May 02, 2022 9:55 pm
goksel1961 wrote:
Mon May 02, 2022 5:35 pm
straightlight wrote:
Sat Apr 30, 2022 11:21 pm


Where is your logs folder located?
/var/www/storage/logs
Ensure to move your storage folder along with the sub-folders outside of your www folder and edit both config.php files (DIR_STORAGE) accordingly. Then, ensure that recursive folder permissions (CHMOD) has been set (not on files) to 0755. File permissions should be set by default to: 0644 recursively.
I moved the storage folder to var/ , Permissions set as you mentioned except cache folder. its 777. But no change . Still no error but no log.

New member

Posts

Joined
Wed Apr 10, 2019 10:30 pm

Post by sw!tch » Thu May 05, 2022 11:01 am

Are you sure you are not using in a conditional statement?

Quickly test it by writing from the __construct method.

In system/library/cart/cart.php or if you are using ocmod try editing the cache file direct via storage/modification/system/library/cart/cart.php

In the __construct method

Below

Code: Select all

$this->weight = $registry->get('weight');
Add

Code: Select all

$this->log = $registry->get('log');
$this->log->write('LOG TEST');
Browse the frontend a few times and check the error log.

If that still doesn’t work, then something isn’t right with your setup, or you are editing the wrong files.

-

Backup and learn how to recover before you make any changes!


Active Member

Posts

Joined
Sat Apr 28, 2012 2:32 pm

Post by goksel1961 » Thu May 05, 2022 11:04 am

straightlight wrote:
Thu May 05, 2022 9:30 am
goksel1961 wrote:
Thu May 05, 2022 9:25 am
straightlight wrote:
Thu May 05, 2022 3:51 am


From which software editor are you editing PHP files? ...
Kate. Version 19.12.3
Ensure that this editor uses UTF-8 without BOM encoding.
Checked. All UTF-8

New member

Posts

Joined
Wed Apr 10, 2019 10:30 pm
Who is online

Users browsing this forum: Majestic-12 [Bot] and 66 guests