Version 4.1.19

This commit is contained in:
Neo committed 2025-12-19 05:38:56 -08:00
1 parent 28bd025b35
commit 2bd5025018
2674 files changed
+233518 -77766

No files matched your search

+72 -9
View File
@@ -2,9 +2,9 @@
/**
* @brief Product Package
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Nexus
* @since 29 Apr 2014
* @version SVN_VERSION_NUMBER
@@ -107,7 +107,7 @@ class _Product extends \IPS\nexus\Package
}
}
$return['package_benefits']['lkey_identifier'] = new \IPS\Helpers\Form\Select( 'p_lkey_identifier', $package->type === 'product' ? $package->lkey_identifier : 0, FALSE, array( 'options' => $identifierOptions, 'unlimited' => 0, 'unlimitedLang' => 'lkey_identifier_none' ), NULL, NULL, NULL, 'p_lkey_identifier' );
$return['package_benefits']['lkey_identifier'] = new \IPS\Helpers\Form\Select( 'p_lkey_identifier', $package->type === 'product' ? $package->lkey_identifier : '0', FALSE, array( 'options' => $identifierOptions, 'unlimited' => '0', 'unlimitedLang' => 'lkey_identifier_none' ), NULL, NULL, NULL, 'p_lkey_identifier' );
return $return;
}
@@ -129,21 +129,37 @@ class _Product extends \IPS\nexus\Package
{
$values['p_weight'] = is_object( $values['p_weight'] ) ? $values['p_weight']->kilograms : 0;
}
else
{
$values['p_weight'] = 0;
}
if( isset( $values['p_length'] ) )
{
$values['p_length'] = is_object( $values['p_length'] ) ? $values['p_length']->metres : 0;
}
else
{
$values['p_length'] = 0;
}
if( isset( $values['p_width'] ) )
{
$values['p_width'] = is_object( $values['p_width'] ) ? $values['p_width']->metres : 0;
}
else
{
$values['p_width'] = 0;
}
if( isset( $values['p_height'] ) )
{
$values['p_height'] = is_object( $values['p_height'] ) ? $values['p_height']->metres : 0;
}
else
{
$values['p_height'] = 0;
}
if( isset( $values['p_shipping'] ) )
{
@@ -171,11 +187,12 @@ class _Product extends \IPS\nexus\Package
/**
* Update existing purchases
*
* @param \IPS\nexus\Purchase $purchase The purchase
* @param array $changes The old values
* @param \IPS\nexus\Purchase $purchase The purchase
* @param array $changes The old values
* @param bool $cancelBillingAgreementIfNecessary If making changes to renewal terms, TRUE will cancel associated billing agreements. FALSE will skip that change
* @return void
*/
public function updatePurchase( \IPS\nexus\Purchase $purchase, $changes )
public function updatePurchase( \IPS\nexus\Purchase $purchase, $changes, $cancelBillingAgreementIfNecessary=FALSE )
{
if ( array_key_exists( 'lkey', $changes ) )
{
@@ -211,7 +228,7 @@ class _Product extends \IPS\nexus\Package
$purchase->save();
}
return parent::updatePurchase( $purchase, $changes );
return parent::updatePurchase( $purchase, $changes, $cancelBillingAgreementIfNecessary );
}
/* !Actions */
@@ -233,8 +250,7 @@ class _Product extends \IPS\nexus\Package
\IPS\Output::i()->error( 'err_subscription_qty', '1X247/2', 403, '' );
}
$purchase = \IPS\Db::i()->select( '*', 'nexus_purchases', array( 'ps_app=? AND ps_type=? AND ps_item_id=? AND ps_cancelled=0 AND ps_member=?', 'nexus', 'package', $this->id, \IPS\Member::loggedIn()->member_id ) );
if ( count( $purchase ) )
if ( $this->_memberHasPurchasedSubscription( \IPS\Member::loggedIn() ) )
{
\IPS\Output::i()->error( 'err_subscription_bought', '1X247/1', 403, '' );
}
@@ -254,6 +270,39 @@ class _Product extends \IPS\nexus\Package
return parent::addToCart( $item, $values, $memberCurrency );
}
/**
* Check for member
* If a user initially checks out as a guest and then logs in during checkout, this method
* is ran to check the items they are purchasing can be bought.
* Is expected to throw a DomainException with an error message to display to the user if not valid
*
* @param \IPS\Member $member The new member
* @return void
* @throws \DomainException
*/
public function memberCanPurchase( \IPS\Member $member )
{
if ( $this->subscription and $this->_memberHasPurchasedSubscription( $member ) )
{
throw new \DomainException( $member->language()->addToStack( 'err_subscription_bought_login', FALSE, array( 'sprintf' => array( $member->language()->addToStack( "nexus_package_{$this->id}" ) ) ) ) );
}
if ( ! ( $this->member_groups == "*" or !empty( ( array_intersect( explode( ",", $this->member_groups ), $member->groups ) ) ) ) )
{
throw new \DomainException( $member->language()->addToStack( 'err_group_cant_purchase', FALSE, array( 'sprintf' => array( $member->language()->addToStack( "nexus_package_{$this->id}" ) ) ) ) );
}
}
/**
* Check if a member has purchased this subscription product
*
* @param \IPS\Member $member The new member
* @return bool
*/
protected function _memberHasPurchasedSubscription( \IPS\Member $member )
{
return (bool) \IPS\Db::i()->select( 'COUNT(*)', 'nexus_purchases', array( 'ps_app=? AND ps_type=? AND ps_item_id=? AND ps_cancelled=0 AND ps_member=?', 'nexus', 'package', $this->id, $member->member_id ) )->first();
}
/**
* Show Purchase Record?
*
@@ -308,6 +357,9 @@ class _Product extends \IPS\nexus\Package
}
catch ( \OutOfRangeException $e ) { }
/* Invalidate License Key Cache so old data is not loaded */
$purchase->licenseKey = NULL;
$class = 'IPS\nexus\Purchase\LicenseKey\\' . ucfirst( $this->lkey );
$licenseKey = new $class;
$licenseKey->identifier = $this->lkey_identifier;
@@ -344,4 +396,15 @@ class _Product extends \IPS\nexus\Package
parent::onPurchaseGenerated( $purchase, $invoice );
}
/**
* Warning to display to admin when cancelling a purchase
*
* @param \IPS\nexus\Purchase $purchase The purchase
* @return string
*/
public function onCancelWarning( \IPS\nexus\Purchase $purchase )
{
return NULL;
}
}