Jump to content

Commerce: bug when upgrading/downgrading a Package

Go to solution Solved by Marc Stridgen,

Recommended Posts

Hi Team,

I think there is a bug in the Commerce app for the Package->upgradeDowngrade() method.

When upgrading or downgrading, you check if the new Package has a longer initial term, and then modify the current $purchase->expire date accordingly.

In \IPS\nexus\Package, in upgradeDowngrade(), at line 3533:

		/* Initial Term, apply the difference if the new package has a longer initial term */
		if( $term and $newPackage->initial_term )
			$initial = new \DateInterval( "P{$newPackage->initial_term}" );

			/* If we're still in the initial period of the new package */
			$diff = \IPS\DateTime::create()->diff( $purchase->start->add( $initial ) );
			if( $diff->days > 0 )
				$purchase->expire = $purchase->start->add( $diff );


You calculate the difference between now and (the purchase start date + the initial term):

$diff = \IPS\DateTime::create()->diff( $purchase->start->add( $initial ) );


Then you check if this difference has days:

if( $diff->days > 0 )


The issue is the following: the $diff->days will always be positive, as you forget to check if the difference is negative.

As a result, the $purchase->expire date could be set in the past, which is really problematic.

The correct test, at line 3540, should be:

if( !$diff->invert && $diff->days > 0 )


Thank you!

Link to comment
Share on other sites

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

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