Version 4.2.0
This commit is contained in:
1 parent
0dc2aee5ed
commit
96997ddd8e
2074 files changed
+125454
-55780
No files matched your search
@@ -1,13 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Package Node
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Community Suite
|
||||
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) Invision Power Services, Inc.
|
||||
* @license https://www.invisioncommunity.com/legal/standards/
|
||||
* @package Invision Community
|
||||
* @subpackage Nexus
|
||||
* @since 29 Apr 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus;
|
||||
@@ -376,7 +375,8 @@ class _Package extends \IPS\Node\Model
|
||||
{
|
||||
foreach ( $discounts['loyalty'] as $discount )
|
||||
{
|
||||
$count = ( ( $discount['package'] ?: $this->id ) == $this->id ) ? $initialCount : 0;
|
||||
$comparingPackageId = ( $discount['package'] ?: $this->id );
|
||||
$count = ( $comparingPackageId == $this->id ) ? $initialCount : 0;
|
||||
if ( $discount['price'][ $currency ] < $price )
|
||||
{
|
||||
$count += $customer->member_id ? $customer->previousPurchasesCount( $discount['package'] ?: $this->id, $discount['active'] ) : 0;
|
||||
@@ -385,7 +385,7 @@ class _Package extends \IPS\Node\Model
|
||||
{
|
||||
foreach ( $_SESSION['cart'] as $item )
|
||||
{
|
||||
if ( $item->id == $this->id )
|
||||
if ( $item->id == $comparingPackageId )
|
||||
{
|
||||
$count += $item->quantity;
|
||||
}
|
||||
@@ -954,7 +954,7 @@ class _Package extends \IPS\Node\Model
|
||||
'autoSaveKey' => ( $this->id ? "nexus-pkg-{$this->id}-pg" : "nexus-new-pkg-pg" ),
|
||||
'attachIds' => $this->id ? array( $this->id, NULL, 'pkg-pg' ) : NULL, 'minimize' => 'p_page_placeholder'
|
||||
)
|
||||
), NULL, NULL, NULL, 'p_desc_editor' ) );
|
||||
), NULL, NULL, NULL, 'p_page' ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'p_support', $this->support, FALSE, array( 'togglesOn' => array( 'p_support_department' ) ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'p_support_department', $this->support ? $this->support_department : 0, FALSE, array( 'class' => 'IPS\nexus\Support\Department', 'zeroVal' => 'none' ), NULL, NULL, NULL, 'p_support_department' ) );
|
||||
$form->addHeader('package_client_area_renewals');
|
||||
@@ -2238,6 +2238,11 @@ class _Package extends \IPS\Node\Model
|
||||
*/
|
||||
public function canRenewUntil( \IPS\nexus\Purchase $purchase, $admin )
|
||||
{
|
||||
if ( !$purchase->expire )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ( $admin )
|
||||
{
|
||||
return TRUE;
|
||||
@@ -2418,7 +2423,14 @@ class _Package extends \IPS\Node\Model
|
||||
|
||||
/* Loop through our siblings */
|
||||
$return = array();
|
||||
$currency = $purchase->original_invoice->currency;
|
||||
try
|
||||
{
|
||||
$currency = $purchase->original_invoice->currency;
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
{
|
||||
$currency = $purchase->member->defaultCurrency();
|
||||
}
|
||||
$prices = json_decode( $this->base_price, TRUE );
|
||||
$thisPrice = $prices[ $currency ]['amount'];
|
||||
foreach ( $this->parent()->children() as $package )
|
||||
@@ -2614,12 +2626,15 @@ class _Package extends \IPS\Node\Model
|
||||
$renewalOptionsOnNewPackage = json_decode( $this->renew_options, TRUE );
|
||||
if ( $purchase->renewals )
|
||||
{
|
||||
foreach ( $renewalOptionsOnNewPackage as $renewalOption )
|
||||
if ( $renewalOptionsOnNewPackage )
|
||||
{
|
||||
$term = $purchase->renewals->getTerm();
|
||||
if ( $renewalOption['add'] and $term['term'] == $renewalOption['term'] and $term['unit'] == $renewalOption['unit'] )
|
||||
foreach ( $renewalOptionsOnNewPackage as $renewalOption )
|
||||
{
|
||||
$priceOfThisPackage += $renewalOption['cost'][ $currency ]['amount'];
|
||||
$term = $purchase->renewals->getTerm();
|
||||
if ( $renewalOption['add'] and $term['term'] == $renewalOption['term'] and $term['unit'] == $renewalOption['unit'] )
|
||||
{
|
||||
$priceOfThisPackage += $renewalOption['cost'][ $currency ]['amount'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2651,11 +2666,8 @@ class _Package extends \IPS\Node\Model
|
||||
{
|
||||
throw new \InvalidArgumentException;
|
||||
}
|
||||
|
||||
$oldCostPerDay = $purchase->renewals->costPerDay()->amount;
|
||||
$numberOfDaysInCurrentRenewalTerm = $purchase->renewals->days();
|
||||
$daysLeftUntilExpiry = new \IPS\Math\Number( (string) \IPS\DateTime::create()->diff( $purchase->expire )->days );
|
||||
|
||||
/* What is the closest renewal option on the new package? We'll use that one */
|
||||
$renewalOptionsInDays = array();
|
||||
foreach ( $renewalOptionsOnNewPackage as $optionId => $renewalTerm )
|
||||
{
|
||||
@@ -2672,9 +2684,20 @@ class _Package extends \IPS\Node\Model
|
||||
}
|
||||
$renewalTermToUse = $renewalOptionsInDays[ $closestRenewalOption ];
|
||||
|
||||
$newCostPerDay = $renewalTermToUse->costPerDay()->amount;
|
||||
return new \IPS\nexus\Money( $newCostPerDay->multiply( $daysLeftUntilExpiry )->subtract( $oldCostPerDay->multiply( $daysLeftUntilExpiry ) ), $currency );
|
||||
|
||||
/* What is the difference between our current renewal term and the renewal term we're moving to? */
|
||||
$diff = $purchase->renewals->diff( $renewalTermToUse );
|
||||
|
||||
/* Multiply that by how many days are left */
|
||||
$numberOfDaysInCurrentRenewalTerm = new \IPS\Math\Number( $purchase->renewals->days() );
|
||||
$daysLeftUntilExpiry = new \IPS\Math\Number( (string) ceil( ( $purchase->expire->getTimestamp() - time() ) / 86400 ) );
|
||||
if ( $numberOfDaysInCurrentRenewalTerm->compare( $daysLeftUntilExpiry ) === 0 )
|
||||
{
|
||||
return $diff;
|
||||
}
|
||||
else
|
||||
{
|
||||
return new \IPS\nexus\Money( $diff->amount->divide( $numberOfDaysInCurrentRenewalTerm )->multiply( $daysLeftUntilExpiry ), $currency );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2947,7 +2970,7 @@ class _Package extends \IPS\Node\Model
|
||||
if ( $this->primary_group and $this->primary_group != $purchase->member->member_group_id and !in_array( $purchase->member->member_group_id, explode( ',', \IPS\Settings::i()->cm_protected ) ) )
|
||||
{
|
||||
/* Hang on, are we about to boot someone out the ACP? */
|
||||
if ( ! ( \IPS\Member\Group::load( $purchase->member->member_group_id )->g_access_cp and !\IPS\Member\Group::load( $this->primary_group )->g_access_cp ) )
|
||||
if ( ! ( $purchase->member->isAdmin() and !in_array( $this->primary_group, array_keys( \IPS\Member::administrators()['g'] ) ) ) )
|
||||
{
|
||||
/* Save the current group */
|
||||
$extra['old_primary_group'] = $purchase->member->member_group_id;
|
||||
@@ -2960,6 +2983,7 @@ class _Package extends \IPS\Node\Model
|
||||
|
||||
/* And update to the new group */
|
||||
$purchase->member->member_group_id = $this->primary_group;
|
||||
$purchase->member->members_bitoptions['ignore_promotions'] = true;
|
||||
$purchase->member->save();
|
||||
}
|
||||
}
|
||||
@@ -3032,6 +3056,7 @@ class _Package extends \IPS\Node\Model
|
||||
|
||||
/* Save */
|
||||
$purchase->member->cm_return_group = 0;
|
||||
$purchase->member->members_bitoptions['ignore_promotions'] = false;
|
||||
$purchase->member->save();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user