Jump to content

[Bug] Can't upgrade Commerce package / PHP 8 TypeError


Go to solution Solved by Marc Stridgen,

Recommended Posts

Marc Stridgen
This post was recognized by Marc Stridgen!

"Thank you"

IPCommerceFan was awarded the badge 'Helpful'

4.6.7 - All 3rd party apps/plugins disabled:

It looks like there is a  ( PHP 8 ) TypeError in applications\nexus\sources\Package\Package.php, in the upgradeDowngrade function, lines 3427 and 3433.

TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given (0)
#0 /home/user/public_html/applications/nexus/extensions/nexus/Item/UpgradeCharge.php(59): IPS\nexus\_Package->upgradeDowngrade(Object(IPS\nexus\Purchase), Object(IPS\nexus\Package\Product), NULL, true)
#1 /home/user/public_html/applications/nexus/sources/Invoice/Invoice.php(1747): IPS\nexus\extensions\nexus\Item\_UpgradeCharge->onPaid(Object(IPS\nexus\Invoice))
#2 /home/user/public_html/applications/nexus/modules/front/checkout/checkout.php(1514): IPS\nexus\_Invoice->markPaid()
#3 /home/user/public_html/system/Helpers/Wizard/Wizard.php(181): IPS\nexus\modules\front\checkout\_checkout->_pay(Array)
#4 /home/user/public_html/applications/nexus/modules/front/checkout/checkout.php(170): IPS\Helpers\_Wizard->__toString()
#5 /home/user/public_html/system/Dispatcher/Controller.php(101): IPS\nexus\modules\front\checkout\_checkout->manage()
#6 /home/user/public_html/applications/nexus/modules/front/checkout/checkout.php(57): IPS\Dispatcher\_Controller->execute()
#7 /home/user/public_html/system/Dispatcher/Dispatcher.php(153): IPS\nexus\modules\front\checkout\_checkout->execute()
#8 /home/user/public_html/index.php(13): IPS\_Dispatcher->run()
#9 {main}

If the package you are upgrading does not have any Renewal Options, there is nothing to count(), so a TypeError is thrown due to NULL not being countable.

Suggest changing this:

				if ( \count( $renewalOptions ) === 1 )
				{
					$term = array_pop( $renewalOptions );
				}
				elseif ( \count( $renewalOptions ) !== 0 )
				{
					throw new \InvalidArgumentException;
				}

to:

				if ( \is_countable( $renewalOptions) && \count( $renewalOptions ) === 1 )
				{
					$term = array_pop( $renewalOptions );
				}
				elseif ( \is_countable( $renewalOptions) && \count( $renewalOptions ) !== 0 )
				{
					throw new \InvalidArgumentException;
				}

Confirmed the fix first by adding some renewal options.  This worked. 

Then confirmed by whipping up a plugin that redeclares the whole function with the fix included.  It works as it should now. 👍

Link to comment
Share on other sites

  • 4 weeks later...
  • Recently Browsing   0 members

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