Jump to content

[4.7.15] Cloning a custom Commerce package throws an "Access to undeclared static property" error


Go to solution Solved by Marc Stridgen,

Recommended Posts

I created a new type of Commerce package for a client, and when trying to clone it an error is thrown.

Here's the stacktrace:

Error thrown with message "Access to undeclared static property IPS\premium\Package\Premium::$packageDatabaseColumns"

Stacktrace:
#6 Error in \applications\nexus\sources\Package\Package.php:264
#5 IPS\nexus\_Package:__clone in \system\Node\Controller.php:915
#4 IPS\Node\_Controller:copy in \system\Dispatcher\Controller.php:107
#3 IPS\Dispatcher\_Controller:execute in \system\Node\Controller.php:69
#2 IPS\Node\_Controller:execute in \applications\nexus\modules\admin\store\packages.php:46
#1 IPS\nexus\modules\admin\store\_packages:execute in \system\Dispatcher\Dispatcher.php:153
#0 IPS\_Dispatcher:run in \init.php:934

 

The issue is caused by the __clone() method in applications/nexus/sources/Package/Package.php which is missing the isset() check:

		foreach ( $this->_data as $k => $v )
		{
			if ( !\in_array( $k, array( 'id', 'reviews', 'unapproved_reviews', 'hidden_reviews' ) ) )
			{
				if ( \in_array( "p_{$k}", static::$packageDatabaseColumns ) )
				{
					$secondaryTable[ "p_{$k}" ] = $v;
				}
				else
				{
					$primaryTable[ "p_{$k}" ] = $v;
				}
			}
		}

Every other method properly checks if the variable is set before using it, but the __clone() method doesn't.

 

Here's an example from the save() method where the isset() check is properly implemented:

		foreach ( $this->changed as $k => $v )
		{
			if ( isset( static::$packageDatabaseColumns ) and \in_array( "p_{$k}", static::$packageDatabaseColumns ) )
			{
				$secondaryTable[ "p_{$k}" ] = $v;
				unset( $this->changed[ $k ] );
			}
			elseif ( !\in_array( "p_{$k}", array( [...] ) ) )
			{
				unset( $this->changed[ $k ] );
			}
		}
Edited by teraßyte
Link to comment
Share on other sites

  • teraßyte changed the title to [4.7.15] Cloning a custom Commerce package throws an "Access to undeclared static property" error
  • 4 weeks later...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...