Version 4.3.6
This commit is contained in:
1 parent
fe1acf984a
commit
1a0c7fd3c2
609 files changed
+14707
-5726
No files matched your search
@@ -699,7 +699,7 @@ class _Package extends \IPS\Node\Model
|
||||
{
|
||||
if ( $v and isset( $customFields[ $k ] ) and $customFields[ $k ]->sticky )
|
||||
{
|
||||
$stickyFields[] = $v;
|
||||
$stickyFields[] = strip_tags( \IPS\nexus\Package\CustomField::load( $k )->displayValue( $v, TRUE ) ); // We need to call displayValue so things like dates and select boxes show the right value, but we *also* need to call strip_tags as Url fields will return full links and we need text only. Note that fields which would show something other than a simple text output are prevented from being used in this context
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1327,90 +1327,100 @@ class _Package extends \IPS\Node\Model
|
||||
unset( $values['p_stock_price_type'] );
|
||||
unset( $values['custom_fields'] );
|
||||
}
|
||||
|
||||
/* Discounts */
|
||||
if( isset( $values['p_usergroup_discounts'] ) OR isset( $values['p_loyalty_discounts'] ) OR isset( $values['p_bulk_discounts'] ) )
|
||||
/* Reset the discounts ? */
|
||||
if ( isset( $values['p_set_discounts'] ) AND !$values['p_set_discounts'] )
|
||||
{
|
||||
$discounts = array();
|
||||
}
|
||||
|
||||
if( isset( $values['p_usergroup_discounts'] ) )
|
||||
{
|
||||
foreach ( $values['p_usergroup_discounts'] as $k => $data )
|
||||
{
|
||||
if ( isset( $data['group'] ) and $data['group'] and isset( $data['price'] ) )
|
||||
{
|
||||
foreach( $data['price'] as $price )
|
||||
{
|
||||
if ( !$price )
|
||||
{
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
|
||||
$discounts['usergroup'][] = array(
|
||||
'group' => $data['group'],
|
||||
'price' => $data['price'],
|
||||
'secondary' => (int) isset( $data['secondary'] ),
|
||||
);
|
||||
}
|
||||
}
|
||||
unset( $values['p_usergroup_discounts'] );
|
||||
}
|
||||
|
||||
if( isset( $values['p_loyalty_discounts'] ) )
|
||||
{
|
||||
foreach ( $values['p_loyalty_discounts'] as $k => $data )
|
||||
{
|
||||
if ( $data['owns'] )
|
||||
{
|
||||
foreach( $data['price'] as $price )
|
||||
{
|
||||
if ( !$price )
|
||||
{
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
|
||||
$packageId = $data['package'] ? mb_substr( $data['package'], 0, mb_strpos( $data['package'], '.' ) ) : 0;
|
||||
|
||||
$discounts['loyalty'][] = array(
|
||||
'owns' => $data['owns'],
|
||||
'package' => ( $data['this'] or ( $this->id and $this->id == $packageId ) ) ? '0' : $packageId,
|
||||
'price' => $data['price'],
|
||||
'active' => (int) isset( $data['active'] ),
|
||||
);
|
||||
}
|
||||
}
|
||||
unset( $values['p_loyalty_discounts'] );
|
||||
}
|
||||
|
||||
if( isset( $values['p_bulk_discounts'] ) )
|
||||
{
|
||||
foreach ( $values['p_bulk_discounts'] as $k => $data )
|
||||
{
|
||||
if ( $data['buying'] )
|
||||
{
|
||||
foreach( $data['price'] as $price )
|
||||
{
|
||||
if ( !$price )
|
||||
{
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
|
||||
$packageId = $data['package'] ? mb_substr( $data['package'], 0, mb_strpos( $data['package'], '.' ) ) : 0;
|
||||
|
||||
$discounts['bulk'][] = array(
|
||||
'buying' => $data['buying'],
|
||||
'package' => ( $data['this'] or ( $this->id and $this->id == $packageId ) ) ? '0' : $packageId,
|
||||
'price' => $data['price'],
|
||||
);
|
||||
}
|
||||
}
|
||||
unset( $values['p_bulk_discounts'] );
|
||||
$values['discounts'] = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Discounts */
|
||||
if (isset($values['p_usergroup_discounts']) OR isset($values['p_loyalty_discounts']) OR isset($values['p_bulk_discounts']))
|
||||
{
|
||||
$discounts = array();
|
||||
}
|
||||
|
||||
if (isset($values['p_usergroup_discounts']))
|
||||
{
|
||||
foreach ($values['p_usergroup_discounts'] as $k => $data)
|
||||
{
|
||||
if (isset($data['group']) and $data['group'] and isset($data['price']))
|
||||
{
|
||||
foreach ($data['price'] as $price)
|
||||
{
|
||||
if (!$price)
|
||||
{
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
|
||||
$discounts['usergroup'][] = array(
|
||||
'group' => $data['group'],
|
||||
'price' => $data['price'],
|
||||
'secondary' => (int)isset($data['secondary']),
|
||||
);
|
||||
}
|
||||
}
|
||||
unset($values['p_usergroup_discounts']);
|
||||
}
|
||||
|
||||
if (isset($values['p_loyalty_discounts']))
|
||||
{
|
||||
foreach ($values['p_loyalty_discounts'] as $k => $data)
|
||||
{
|
||||
if ($data['owns'])
|
||||
{
|
||||
foreach ($data['price'] as $price)
|
||||
{
|
||||
if (!$price)
|
||||
{
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
|
||||
$packageId = $data['package'] ? mb_substr($data['package'], 0, mb_strpos($data['package'], '.')) : 0;
|
||||
|
||||
$discounts['loyalty'][] = array(
|
||||
'owns' => $data['owns'],
|
||||
'package' => ($data['this'] or ($this->id and $this->id == $packageId)) ? '0' : $packageId,
|
||||
'price' => $data['price'],
|
||||
'active' => (int)isset($data['active']),
|
||||
);
|
||||
}
|
||||
}
|
||||
unset($values['p_loyalty_discounts']);
|
||||
}
|
||||
|
||||
if (isset($values['p_bulk_discounts']))
|
||||
{
|
||||
foreach ($values['p_bulk_discounts'] as $k => $data)
|
||||
{
|
||||
if ($data['buying'])
|
||||
{
|
||||
foreach ($data['price'] as $price)
|
||||
{
|
||||
if (!$price)
|
||||
{
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
|
||||
$packageId = $data['package'] ? mb_substr($data['package'], 0, mb_strpos($data['package'], '.')) : 0;
|
||||
|
||||
$discounts['bulk'][] = array(
|
||||
'buying' => $data['buying'],
|
||||
'package' => ($data['this'] or ($this->id and $this->id == $packageId)) ? '0' : $packageId,
|
||||
'price' => $data['price'],
|
||||
);
|
||||
}
|
||||
}
|
||||
unset($values['p_bulk_discounts']);
|
||||
}
|
||||
}
|
||||
|
||||
if( isset( $discounts ) )
|
||||
{
|
||||
$values['discounts'] = json_encode( $discounts );
|
||||
@@ -1821,6 +1831,18 @@ class _Package extends \IPS\Node\Model
|
||||
{
|
||||
$optionValues = $this->optionValues( $details );
|
||||
$return = array();
|
||||
|
||||
/* If we do not have a currency in our session data, set it now so that if the language is changed, it is not confused about
|
||||
what currency the store should be in */
|
||||
if ( ( isset( $_SESSION['currency'] ) and in_array( $_SESSION['currency'], \IPS\nexus\Money::currencies() ) ) )
|
||||
{
|
||||
$memberCurrency = $_SESSION['currency'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$memberCurrency = \IPS\nexus\Customer::loggedIn()->defaultCurrency();
|
||||
$_SESSION['currency'] = $memberCurrency;
|
||||
}
|
||||
|
||||
/* Work out how we're splitting these */
|
||||
$items = array();
|
||||
@@ -1828,8 +1850,11 @@ class _Package extends \IPS\Node\Model
|
||||
$inThisBatch = 0;
|
||||
for ( $i=0; $i<$quantity;$i++ )
|
||||
{
|
||||
$price = $this->price( NULL, TRUE, TRUE, TRUE, $i );
|
||||
$memberCurrency = $price->currency;
|
||||
$price = $this->price( NULL, TRUE, TRUE, TRUE, $i );
|
||||
if ( $price->currency !== $memberCurrency )
|
||||
{
|
||||
throw new \RuntimeException('CURRENCY_MISMATCH');
|
||||
}
|
||||
$price = $price->amount;
|
||||
|
||||
if ( $previousPrice !== NULL and $previousPrice != $price )
|
||||
@@ -1886,7 +1911,7 @@ class _Package extends \IPS\Node\Model
|
||||
$item->parent = $parent;
|
||||
}
|
||||
|
||||
/* Do any package-sepcific modifications */
|
||||
/* Do any package-specific modifications */
|
||||
$extraItems = ( $values === NULL ) ? array() : $this->addToCart( $item, $values, $memberCurrency );
|
||||
|
||||
/* Hang on, is that the same as anything else in the cart? */
|
||||
@@ -1914,7 +1939,7 @@ class _Package extends \IPS\Node\Model
|
||||
}
|
||||
|
||||
/* Associate extras */
|
||||
if ( count( $extraItems ) )
|
||||
if ( is_array( $extraItems ) and count( $extraItems ) )
|
||||
{
|
||||
foreach ( $extraItems as $item )
|
||||
{
|
||||
@@ -1983,7 +2008,7 @@ class _Package extends \IPS\Node\Model
|
||||
|
||||
foreach ( $customFields as $field )
|
||||
{
|
||||
if( array_key_exists( $field->type, \IPS\nexus\Package\CustomField::$additionalFieldTypes ) )
|
||||
if( array_key_exists( $field->type, \IPS\nexus\Package\CustomField::$additionalFieldTypes ) and !class_exists( 'IPS\Helpers\Form\\' . $field->type ) )
|
||||
{
|
||||
$class = 'IPS\nexus\Form\\' . $field->type;
|
||||
}
|
||||
@@ -2113,7 +2138,18 @@ class _Package extends \IPS\Node\Model
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
$term = array_pop( $renewalOptions );
|
||||
$purchase->renewals = new \IPS\nexus\Purchase\RenewalTerm( new \IPS\nexus\Money( $term['cost'][$currency]['amount'], $currency ), new \DateInterval( 'P' . $term['term'] . mb_strtoupper( $term['unit'] ) ) );
|
||||
|
||||
$tax = NULL;
|
||||
if ( $this->_data['tax'] )
|
||||
{
|
||||
try
|
||||
{
|
||||
$tax = \IPS\nexus\Tax::load( $purchase->tax );
|
||||
}
|
||||
catch ( \Exception $e ) { }
|
||||
}
|
||||
|
||||
$purchase->renewals = new \IPS\nexus\Purchase\RenewalTerm( new \IPS\nexus\Money( $term['cost'][$currency]['amount'], $currency ), new \DateInterval( 'P' . $term['term'] . mb_strtoupper( $term['unit'] ) ), $tax );
|
||||
$purchase->cancelled = FALSE;
|
||||
$purchase->save();
|
||||
|
||||
@@ -2611,7 +2647,6 @@ class _Package extends \IPS\Node\Model
|
||||
return array();
|
||||
}
|
||||
|
||||
|
||||
/* Cannot upgrade/downgrade without permission unless $overrideRestrictions is set */
|
||||
if ( ( !$this->allow_upgrading AND !$this->allow_downgrading ) AND !$overrideRestrictions )
|
||||
{
|
||||
@@ -2624,8 +2659,7 @@ class _Package extends \IPS\Node\Model
|
||||
return array();
|
||||
}
|
||||
|
||||
/* Loop through our siblings */
|
||||
$return = array();
|
||||
/* Work out how much this package costs, including considering if the renewal term adds to the base price */
|
||||
try
|
||||
{
|
||||
$currency = $purchase->original_invoice->currency;
|
||||
@@ -2633,9 +2667,24 @@ class _Package extends \IPS\Node\Model
|
||||
catch ( \Exception $e )
|
||||
{
|
||||
$currency = $purchase->member->defaultCurrency();
|
||||
}
|
||||
}
|
||||
$prices = json_decode( $this->base_price, TRUE );
|
||||
$thisPrice = $prices[ $currency ]['amount'];
|
||||
if ( $this->renew_options )
|
||||
{
|
||||
$renewalOptions = json_decode( $this->renew_options, TRUE );
|
||||
if ( !empty( $renewalOptions ) )
|
||||
{
|
||||
$option = array_shift( $renewalOptions );
|
||||
if ( $option['add'] )
|
||||
{
|
||||
$thisPrice += ( $option['cost'][ $currency ]['amount'] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Loop through our siblings */
|
||||
$return = array();
|
||||
foreach ( $this->parent()->children() as $package )
|
||||
{
|
||||
if ( $package->id === $this->id )
|
||||
@@ -2679,6 +2728,7 @@ class _Package extends \IPS\Node\Model
|
||||
}
|
||||
}
|
||||
|
||||
/* Return */
|
||||
return $return;
|
||||
}
|
||||
|
||||
@@ -3247,7 +3297,7 @@ class _Package extends \IPS\Node\Model
|
||||
/* Have we made other purchases that have changed their primary group? */
|
||||
try
|
||||
{
|
||||
$next = \IPS\Db::i()->select( array( 'ps_id', 'ps_name', 'p_primary_group' ), 'nexus_purchases', array( 'ps_member=? AND ps_app=? AND ps_type=? AND ps_active=1 AND p_primary_group<>0 AND ps_id<>?', $purchase->member->member_id, 'nexus', 'package', $purchase->id ) )
|
||||
$next = \IPS\Db::i()->select( array( 'ps_id', 'ps_name', 'p_primary_group' ), 'nexus_purchases', array( "ps_member=? AND ps_app=? AND ps_type IN('package','subscription') AND ps_active=1 AND p_primary_group<>0 AND ps_id<>?", $purchase->member->member_id, 'nexus', $purchase->id ) )
|
||||
->join( 'nexus_packages', 'p_id=ps_item_id' )
|
||||
->first();
|
||||
|
||||
@@ -3299,7 +3349,7 @@ class _Package extends \IPS\Node\Model
|
||||
|
||||
/* Have we made other purchases that have added secondary groups? */
|
||||
$secondaryGroupsAwardedByOtherPurchases = array();
|
||||
foreach ( \IPS\Db::i()->select( 'p_secondary_group', 'nexus_purchases', array( 'ps_member=? AND ps_app=? AND ps_type=? AND ps_active=1 AND p_secondary_group IS NOT NULL AND p_secondary_group<>? AND ps_id<>?', $purchase->member->member_id, 'nexus', 'package', '', $purchase->id ) )->join( 'nexus_packages', 'p_id=ps_item_id' ) as $secondaryGroups )
|
||||
foreach ( \IPS\Db::i()->select( 'p_secondary_group', 'nexus_purchases', array( "ps_member=? AND ps_app=? AND ps_type IN('package','subscription') AND ps_active=1 AND p_secondary_group IS NOT NULL AND p_secondary_group<>? AND ps_id<>?", $purchase->member->member_id, 'nexus', '', $purchase->id ) )->join( 'nexus_packages', 'p_id=ps_item_id' ) as $secondaryGroups )
|
||||
{
|
||||
$secondaryGroupsAwardedByOtherPurchases = array_merge( $secondaryGroupsAwardedByOtherPurchases, array_filter( explode( ',', $secondaryGroups ) ) );
|
||||
}
|
||||
@@ -3338,9 +3388,12 @@ class _Package extends \IPS\Node\Model
|
||||
});
|
||||
|
||||
/* Save */
|
||||
$purchase->member->mgroup_others = implode( ',', $membersSecondaryGroups );
|
||||
$purchase->member->save();
|
||||
$purchase->member->logHistory( 'core', 'group', array( 'type' => 'secondary', 'by' => 'purchase', 'action' => 'remove', 'id' => $purchase->id, 'name' => $purchase->name, 'old' => $currentSecondaryGroups, 'new' => $membersSecondaryGroups ) );
|
||||
if( $currentSecondaryGroups != $membersSecondaryGroups )
|
||||
{
|
||||
$purchase->member->mgroup_others = implode( ',', $membersSecondaryGroups );
|
||||
$purchase->member->save();
|
||||
$purchase->member->logHistory( 'core', 'group', array( 'type' => 'secondary', 'by' => 'purchase', 'action' => 'remove', 'id' => $purchase->id, 'name' => $purchase->name, 'old' => $currentSecondaryGroups, 'new' => $membersSecondaryGroups ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user