Version 4.7.0
This commit is contained in:
1 parent
517a5e1f70
commit
8ba7d43898
1933 files changed
+65613
-11332
No files matched your search
@@ -27,6 +27,12 @@ class _Package extends \IPS\Node\Model
|
||||
* @brief [ActiveRecord] Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Caches
|
||||
* @note Defined cache keys will be cleared automatically as needed
|
||||
*/
|
||||
protected $caches = array( 'nexus_reg_product_count' );
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Table
|
||||
@@ -720,7 +726,16 @@ class _Package extends \IPS\Node\Model
|
||||
$priceMayChange = FALSE;
|
||||
$priceNotIncludingDiscounts = NULL;
|
||||
$relevantRenewalTerm = NULL;
|
||||
$price = static::lowestPriceFromData( $customer, $currency, $packageId, $prices, $discounts, $renewOptions, $stock, $tax, $priceMayChange, $priceNotIncludingDiscounts, $relevantRenewalTerm );
|
||||
|
||||
try
|
||||
{
|
||||
$price = static::lowestPriceFromData( $customer, $currency, $packageId, $prices, $discounts, $renewOptions, $stock, $tax, $priceMayChange, $priceNotIncludingDiscounts, $relevantRenewalTerm );
|
||||
}
|
||||
catch ( \OutOfBoundsException $e )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$primaryPrice = new \IPS\nexus\Money( $price, $currency );
|
||||
|
||||
/* Renewals */
|
||||
@@ -1108,7 +1123,7 @@ class _Package extends \IPS\Node\Model
|
||||
$form->addHeader('package_registration');
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'p_reg', $this->reg, FALSE, array(), function( $val )
|
||||
{
|
||||
if ( $val and ( !\IPS\Request::i()->p_store_checkbox or ( \IPS\Request::i()->p_member_groups and ( !\in_array( \IPS\Settings::i()->guest_group, \IPS\Request::i()->p_member_groups ) and \IPS\Request::i()->p_member_groups_unlimited != "*" ) ) ) )
|
||||
if ( $val and ( !\IPS\Request::i()->p_store_checkbox or ( \IPS\Request::i()->p_member_groups and !\in_array( \IPS\Settings::i()->guest_group, array_keys( \IPS\Request::i()->p_member_groups ) ) ) ) )
|
||||
{
|
||||
throw new \DomainException( \IPS\Member::loggedIn()->language()->addToStack( 'p_reg_err', FALSE, array( 'sprintf' => array( \IPS\Member\Group::load( \IPS\Settings::i()->guest_group )->name ) ) ) );
|
||||
}
|
||||
@@ -2076,6 +2091,11 @@ class _Package extends \IPS\Node\Model
|
||||
}
|
||||
return $optionValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Temporarily store stock data based on query.
|
||||
*/
|
||||
protected $_stockQueryCache = [];
|
||||
|
||||
/**
|
||||
* Stock level
|
||||
@@ -2089,14 +2109,19 @@ class _Package extends \IPS\Node\Model
|
||||
case -1: // Unlimited
|
||||
return NULL;
|
||||
case -2: // Variable
|
||||
if ( \IPS\Db::i()->select( 'COUNT(*)', 'nexus_product_options', array( 'opt_package=? AND opt_stock<>0', $this->id ) )->first() )
|
||||
if( !array_key_exists( $this->id, $this->_stockQueryCache ) )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
if ( \IPS\Db::i()->select( 'COUNT(*)', 'nexus_product_options', array( 'opt_package=? AND opt_stock<>0', $this->id ) )->first() )
|
||||
{
|
||||
$this->_stockQueryCache[ $this->id ] = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->_stockQueryCache[ $this->id ] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_stockQueryCache[ $this->id ];
|
||||
default:
|
||||
return (int) $this->stock;
|
||||
}
|
||||
@@ -2995,7 +3020,7 @@ class _Package extends \IPS\Node\Model
|
||||
{
|
||||
if ( $this->$typeKey == 'wysiwyg' )
|
||||
{
|
||||
$email = \IPS\Email::buildFromContent( $purchase->member->language()->get( "nexus_package_{$this->id}_email_{$type}_subject" ), \IPS\Text\Parser::removeLazyLoad( $this->$valueKey ), NULL, \IPS\Email::TYPE_TRANSACTIONAL, TRUE, 'package_customemail' );
|
||||
$email = \IPS\Email::buildFromContent( $purchase->member->language()->get( "nexus_package_{$this->id}_email_{$type}_subject" ), \IPS\Text\Parser::removeLazyLoad( $this->$valueKey ), NULL, \IPS\Email::TYPE_TRANSACTIONAL, \IPS\Email::WRAPPER_USE, 'package_customemail' );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -3003,7 +3028,7 @@ class _Package extends \IPS\Node\Model
|
||||
\IPS\Theme::makeProcessFunction( $this->$valueKey, $functionName, '$purchase' );
|
||||
|
||||
$themeFunction = 'IPS\\Theme\\'.$functionName;
|
||||
$email = \IPS\Email::buildFromContent( $purchase->member->language()->get( "nexus_package_{$this->id}_email_{$type}_subject" ), $themeFunction( $purchase ), NULL, \IPS\Email::TYPE_TRANSACTIONAL, $this->$typeKey == 'html_template', 'package_customemail' );
|
||||
$email = \IPS\Email::buildFromContent( $purchase->member->language()->get( "nexus_package_{$this->id}_email_{$type}_subject" ), $themeFunction( $purchase ), NULL, \IPS\Email::TYPE_TRANSACTIONAL, ( $this->$typeKey == 'html_template' ? \IPS\Email::WRAPPER_USE : \IPS\Email::WRAPPER_NONE ), 'package_customemail' );
|
||||
}
|
||||
$email->send( $purchase->member );
|
||||
|
||||
@@ -3101,6 +3126,12 @@ class _Package extends \IPS\Node\Model
|
||||
/* Upgrade */
|
||||
if ( $price >= $thisPrice and ( $this->allow_upgrading or $overrideRestrictions ) )
|
||||
{
|
||||
/* We want to pro-rata renewals for upgrades, but we do not have any renewals here, so no */
|
||||
if ( $package->upgrade_charge == 2 and ! $purchase->renewals )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$return[] = $package;
|
||||
$includesUpgrades = TRUE;
|
||||
}
|
||||
@@ -3420,11 +3451,11 @@ class _Package extends \IPS\Node\Model
|
||||
$renewalOptions = json_decode( $newPackage->renew_options, TRUE );
|
||||
if ( $chosenRenewalOption === NULL )
|
||||
{
|
||||
if ( \count( $renewalOptions ) === 1 )
|
||||
if ( $renewalOptions AND \count( $renewalOptions ) === 1 )
|
||||
{
|
||||
$term = array_pop( $renewalOptions );
|
||||
}
|
||||
elseif ( \count( $renewalOptions ) !== 0 )
|
||||
elseif ( $renewalOptions AND \count( $renewalOptions ) !== 0 )
|
||||
{
|
||||
throw new \InvalidArgumentException;
|
||||
}
|
||||
@@ -3489,6 +3520,19 @@ class _Package extends \IPS\Node\Model
|
||||
{
|
||||
$purchase->expire = NULL;
|
||||
}
|
||||
|
||||
/* 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 );
|
||||
}
|
||||
}
|
||||
|
||||
/* Update Purchase */
|
||||
$purchase->name = \IPS\Member::loggedIn()->language()->get( "nexus_package_{$newPackage->id}" );
|
||||
@@ -3813,4 +3857,23 @@ class _Package extends \IPS\Node\Model
|
||||
{
|
||||
return \IPS\Db::i()->select( 'COUNT(*)', 'nexus_packages', 'p_reg=1 AND p_store=1' )->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Does the currently logged in user have permission to delete this node?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function canDelete()
|
||||
{
|
||||
foreach ( \IPS\Db::i()->select( 'data', 'core_queue', array( 'app=? AND `key`=?', 'nexus', 'MassChangePurchases' ) ) as $row )
|
||||
{
|
||||
$data = json_decode( $row, TRUE );
|
||||
if ( $data['id'] == $this->_id OR $data['mass_change_purchases_to'] == $this->_id )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return parent::canDelete();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user