Version 4.2.0

This commit is contained in:
Neo committed 2025-12-19 05:44:59 -08:00
1 parent 0dc2aee5ed
commit 96997ddd8e
2074 files changed
+125454 -55780

No files matched your search

+133 -109
View File
@@ -1,13 +1,12 @@
<?php
/**
* @brief Invoice Model
* @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 10 Feb 2014
* @version SVN_VERSION_NUMBER
*/
namespace IPS\nexus;
@@ -202,7 +201,7 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
/**
* Get member
*
* @return \IPS\Member
* @return \IPS\nexus\Customer
*/
public function get_member()
{
@@ -598,9 +597,10 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
* Add item
*
* @param \IPS\nexus\Invoice\Item $item The item
* @array int|NULL $cartKey Our cart key for this item, or NULL. Used to make sure items are properly associated with their parents if not bought yet.
* @return int
*/
public function addItem( \IPS\nexus\Invoice\Item $item )
public function addItem( \IPS\nexus\Invoice\Item $item, $cartKey = NULL )
{
/* Set basic data */
$data = array(
@@ -680,7 +680,14 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
/* Add it */
$items = json_decode( $this->_data['items'], TRUE );
$items[] = $data;
if ( $cartKey !== NULL )
{
$items[ $cartKey ] = $data;
}
else
{
$items[] = $data;
}
/* Get the ID */
$ids = array_keys( $items );
@@ -1522,6 +1529,123 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
}
/* !Actions */
/**
* Create account from guest checkout
*
* @return \IPS\nexus\Customer
*/
public function createAccountForGuest()
{
$profileFields = $this->guest_data['profileFields'];
$securityAnswers = isset( $this->guest_data['securityAnswers'] ) ? $this->guest_data['securityAnswers'] : array();
/* If the member has already been created (the user made two separate purchases with the same data), use that, otherwise create one */
try
{
$memberToSave = \IPS\nexus\Customer::load( $this->guest_data['member']['email'], 'email' );
}
catch ( \OutOfRangeException $e )
{
$memberToSave = new \IPS\nexus\Customer;
foreach ( $this->guest_data['member'] as $k => $v )
{
$memberToSave->_data[ $k ] = $v;
$memberToSave->changed[ $k ] = $v;
}
$memberToSave->save();
}
$this->member = $memberToSave;
$this->guest_data = NULL;
$this->save();
/* If we provided answers to security questions in check out, save those */
if ( \IPS\Settings::i()->security_questions_enabled and in_array( \IPS\Settings::i()->security_questions_prompt, array( 'register', 'optional' ) ) )
{
if ( $securityAnswers )
{
foreach ( $securityAnswers as $k => $v )
{
\IPS\Db::i()->insert( 'core_security_answers', array(
'answer_question_id' => $k,
'answer_member_id' => $this->member->member_id,
'answer_answer' => $v
) );
}
$this->member->members_bitoptions['has_security_answers'] = TRUE;
/* Log MFA Enable */
$this->member->logHistory( 'core', 'mfa', array( 'handler' => 'questions', 'enable' => TRUE ) );
}
else
{
$this->member->members_bitoptions['security_questions_opt_out'] = TRUE;
/* Log MFA Optout */
$this->member->logHistory( 'core', 'mfa', array( 'handler' => 'questions', 'enable' => FALSE, 'optout' => TRUE ) );
}
$this->member->save();
}
/* If we've entered an address during checkout, save it */
if ( $this->billaddress !== NULL )
{
$billing = new \IPS\nexus\Customer\Address;
$billing->member = $this->member;
$billing->address = $this->billaddress;
$billing->primary_billing = 1;
$billing->save();
}
if ( $this->shipaddress !== NULL )
{
$shipping = new \IPS\nexus\Customer\Address;
$shipping->member = $this->member;
$shipping->address = $this->shipaddress;
$shipping->primary_shipping = 1;
$shipping->save();
}
$profileFields['member_id'] = $memberToSave->member_id;
\IPS\Db::i()->replace( 'core_pfields_content', $profileFields );
/* Validation */
if ( \IPS\Settings::i()->nexus_checkreg_validate or !$this->total->amount->isGreaterThanZero() )
{
$this->member->postRegistration( FALSE, TRUE );
}
else if( \IPS\Settings::i()->new_reg_notify )
{
\IPS\Email::buildFromTemplate( 'core', 'registration_notify', array( $memberToSave, $profileFields ), \IPS\Email::TYPE_LIST )->send( \IPS\Settings::i()->email_in );
}
/* Update associated transactions */
\IPS\Db::i()->update( 'nexus_billing_agreements', array( 'ba_member' => $this->member->member_id ), array( 'ba_id IN(?)', \IPS\Db::i()->select( 't_billing_agreement', 'nexus_transactions', array( 't_billing_agreement>0 AND t_invoice=? AND t_member=0', $this->id ) ) ) );
\IPS\Db::i()->update( 'nexus_transactions', array( 't_member' => $this->member->member_id ), array( 't_invoice=? AND t_member=0', $this->id ) );
/* Did we use any coupons? */
foreach ( $this->items as $item )
{
if ( $item instanceof \IPS\nexus\extensions\nexus\Item\CouponDiscount )
{
$coupon = \IPS\nexus\Coupon::load( $item->id );
$uses = $coupon->used_by ? json_decode( $coupon->used_by, TRUE ) : array();
if ( isset( $uses[ $this->member->email ] ) )
{
$uses[ $this->member->member_id ] = $uses[ $this->member->email ];
unset( $uses[ $this->member->email ] );
}
else
{
$uses[ $this->member->member_id ] = 1;
}
$coupon->used_by = json_encode( $uses );
$coupon->save();
}
}
return $memberToSave;
}
/**
* Mark as paid
@@ -1539,107 +1663,7 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
/* Create the member account if this was a guest */
if ( !$this->member->member_id and $this->guest_data and $this->requiresLogin() )
{
$profileFields = $this->guest_data['profileFields'];
$securityAnswers = isset( $this->guest_data['securityAnswers'] ) ? $this->guest_data['securityAnswers'] : array();
/* If the member has already been created (the user made two separate purchases with the same data), use that, otherwise create one */
try
{
$memberToSave = \IPS\nexus\Customer::load( $this->guest_data['member']['email'], 'email' );
}
catch ( \OutOfRangeException $e )
{
$memberToSave = new \IPS\nexus\Customer;
foreach ( $this->guest_data['member'] as $k => $v )
{
$memberToSave->_data[ $k ] = $v;
$memberToSave->changed[ $k ] = $v;
}
$memberToSave->save();
$return = $memberToSave;
}
$this->member = $memberToSave;
$this->guest_data = NULL;
$this->save();
/* If we provided answers to security questions in check out, save those */
if ( \IPS\Settings::i()->security_questions_enabled and in_array( \IPS\Settings::i()->security_questions_prompt, array( 'register', 'optional' ) ) )
{
if ( $securityAnswers )
{
foreach ( $securityAnswers as $k => $v )
{
\IPS\Db::i()->insert( 'core_security_answers', array(
'answer_question_id' => $k,
'answer_member_id' => $this->member->member_id,
'answer_answer' => $v
) );
}
$this->member->members_bitoptions['has_security_answers'] = TRUE;
}
else
{
$this->member->members_bitoptions['security_questions_opt_out'] = TRUE;
}
$this->member->save();
}
/* If we've entered an address during checkout, save it */
if ( $this->billaddress !== NULL )
{
$billing = new \IPS\nexus\Customer\Address;
$billing->member = $this->member;
$billing->address = $this->billaddress;
$billing->primary_billing = 1;
$billing->save();
}
if ( $this->shipaddress !== NULL )
{
$shipping = new \IPS\nexus\Customer\Address;
$shipping->member = $this->member;
$shipping->address = $this->shipaddress;
$shipping->primary_shipping = 1;
$shipping->save();
}
$profileFields['member_id'] = $memberToSave->member_id;
\IPS\Db::i()->replace( 'core_pfields_content', $profileFields );
/* Validation */
if ( \IPS\Settings::i()->nexus_checkreg_validate or !$this->total->amount->isGreaterThanZero() )
{
$this->member->postRegistration( FALSE, TRUE );
}
else if( \IPS\Settings::i()->new_reg_notify )
{
\IPS\Email::buildFromTemplate( 'core', 'registration_notify', array( $memberToSave, $profileFields ), \IPS\Email::TYPE_LIST )->send( \IPS\Settings::i()->email_in );
}
/* Update associated transactions */
\IPS\Db::i()->update( 'nexus_billing_agreements', array( 'ba_member' => $this->member->member_id ), array( 'ba_id IN(?)', \IPS\Db::i()->select( 't_billing_agreement', 'nexus_transactions', array( 't_billing_agreement>0 AND t_invoice=? AND t_member=0', $this->id ) ) ) );
\IPS\Db::i()->update( 'nexus_transactions', array( 't_member' => $this->member->member_id ), array( 't_invoice=? AND t_member=0', $this->id ) );
/* Did we use any coupons? */
foreach ( $this->items as $item )
{
if ( $item instanceof \IPS\nexus\extensions\nexus\Item\CouponDiscount )
{
$coupon = \IPS\nexus\Coupon::load( $item->id );
$uses = $coupon->used_by ? json_decode( $coupon->used_by, TRUE ) : array();
if ( isset( $uses[ $this->member->email ] ) )
{
$uses[ $this->member->member_id ] = $uses[ $this->member->email ];
unset( $uses[ $this->member->email ] );
}
else
{
$uses[ $this->member->member_id ] = 1;
}
$coupon->used_by = json_encode( $uses );
$coupon->save();
}
}
$return = $this->createAccountForGuest();
}
/* Init */