Version 4.1.19
This commit is contained in:
1 parent
28bd025b35
commit
2bd5025018
2674 files changed
+233518
-77766
No files matched your search
@@ -2,9 +2,9 @@
|
||||
/**
|
||||
* @brief Gift Vouchers
|
||||
* @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 5 May 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
@@ -51,7 +51,7 @@ class _gifts extends \IPS\Dispatcher\Controller
|
||||
protected function manage()
|
||||
{
|
||||
/* Work out what our options are */
|
||||
$memberCurrency = ( isset( $_SESSION['currency'] ) ? $_SESSION['currency'] : \IPS\nexus\Customer::loggedIn()->defaultCurrency() );
|
||||
$memberCurrency = ( ( ( isset( $_SESSION['currency'] ) and in_array( $_SESSION['currency'], \IPS\nexus\Money::currencies() ) ) and in_array( $_SESSION['currency'], \IPS\nexus\Money::currencies() ) ) ? $_SESSION['currency'] : \IPS\nexus\Customer::loggedIn()->defaultCurrency() );
|
||||
$options = array();
|
||||
foreach ( json_decode( \IPS\Settings::i()->nexus_gift_vouchers, TRUE ) as $voucher )
|
||||
{
|
||||
@@ -84,32 +84,41 @@ class _gifts extends \IPS\Dispatcher\Controller
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'gift_voucher_recipient' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'gift_voucher_sender', \IPS\Member::loggedIn()->name ) );
|
||||
$form->add( new \IPS\Helpers\Form\TextArea( 'gift_voucher_message' ) );
|
||||
$formTemplate = $form->customTemplate( array( call_user_func_array( array( \IPS\Theme::i(), 'getTemplate' ), array( 'store', 'nexus' ) ), 'giftCardForm' ) );
|
||||
|
||||
/* Handle submissions */
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
$item = new \IPS\nexus\extensions\nexus\Item\GiftVoucher( \IPS\Member::loggedIn()->language()->get('gift_voucher'), new \IPS\nexus\Money( $values['gift_voucher_amount'], $memberCurrency ) );
|
||||
$item->paymentMethodIds = array_keys( \IPS\nexus\Gateway::roots( NULL, NULL, array( 'm_active=1 AND m_gateway<>?', 'TwoCheckout' ) ) ); // It is against 2CO terms to use them for buying gift vouchers
|
||||
$item->extra['method'] = $values['gift_voucher_method'];
|
||||
$item->extra['recipient_email'] = $values['gift_voucher_email'];
|
||||
$item->extra['recipient_name'] = $values['gift_voucher_recipient'];
|
||||
$item->extra['sender'] = $values['gift_voucher_sender'];
|
||||
$item->extra['message'] = $values['gift_voucher_message'];
|
||||
$item->extra['amount'] = $values['gift_voucher_amount'];
|
||||
$item->extra['color'] = $values['gift_voucher_color'];
|
||||
$item->extra['currency'] = $memberCurrency;
|
||||
if( ! abs( $values['gift_voucher_amount'] ) )
|
||||
{
|
||||
$form->error = \IPS\Member::loggedIn()->language()->addToStack( 'gift_voucher_invalid_amount' );
|
||||
}
|
||||
|
||||
$invoice = new \IPS\nexus\Invoice;
|
||||
$invoice->currency = $memberCurrency;
|
||||
$invoice->member = \IPS\Member::loggedIn();
|
||||
$invoice->addItem( $item );
|
||||
$invoice->save();
|
||||
|
||||
\IPS\Output::i()->redirect( $invoice->checkoutUrl() );
|
||||
if( !$form->error )
|
||||
{
|
||||
$item = new \IPS\nexus\extensions\nexus\Item\GiftVoucher( \IPS\Member::loggedIn()->language()->get( 'gift_voucher' ), new \IPS\nexus\Money( abs( $values[ 'gift_voucher_amount' ] ), $memberCurrency ) );
|
||||
$item->paymentMethodIds = array_keys( \IPS\nexus\Gateway::roots( NULL, NULL, array( 'm_active=1 AND m_gateway<>?', 'TwoCheckout' ) ) ); // It is against 2CO terms to use them for buying gift vouchers
|
||||
$item->extra[ 'method' ] = $values[ 'gift_voucher_method' ];
|
||||
$item->extra[ 'recipient_email' ] = $values[ 'gift_voucher_email' ];
|
||||
$item->extra[ 'recipient_name' ] = $values[ 'gift_voucher_recipient' ];
|
||||
$item->extra[ 'sender' ] = $values[ 'gift_voucher_sender' ];
|
||||
$item->extra[ 'message' ] = $values[ 'gift_voucher_message' ];
|
||||
$item->extra[ 'amount' ] = abs( $values[ 'gift_voucher_amount' ] );
|
||||
$item->extra[ 'color' ] = $values[ 'gift_voucher_color' ];
|
||||
$item->extra[ 'currency' ] = $memberCurrency;
|
||||
|
||||
$invoice = new \IPS\nexus\Invoice;
|
||||
$invoice->currency = $memberCurrency;
|
||||
$invoice->member = \IPS\Member::loggedIn();
|
||||
$invoice->addItem( $item );
|
||||
$invoice->save();
|
||||
|
||||
\IPS\Output::i()->redirect( $invoice->checkoutUrl() );
|
||||
}
|
||||
}
|
||||
|
||||
/* Display */
|
||||
$formTemplate = $form->customTemplate( array( call_user_func_array( array( \IPS\Theme::i(), 'getTemplate' ), array( 'store', 'nexus' ) ), 'giftCardForm' ) );
|
||||
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('store')->giftCard( $formTemplate );
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('buy_gift_voucher');
|
||||
\IPS\Output::i()->breadcrumb[] = array( NULL, \IPS\Member::loggedIn()->language()->addToStack('buy_gift_voucher') );
|
||||
@@ -122,7 +131,7 @@ class _gifts extends \IPS\Dispatcher\Controller
|
||||
*/
|
||||
protected function formatCurrency()
|
||||
{
|
||||
\IPS\Output::i()->json( (string) new \IPS\nexus\Money( \IPS\Request::i()->amount, ( isset( $_SESSION['currency'] ) ? $_SESSION['currency'] : \IPS\nexus\Customer::loggedIn()->defaultCurrency() ) ) );
|
||||
\IPS\Output::i()->json( (string) new \IPS\nexus\Money( \IPS\Request::i()->amount, ( ( isset( $_SESSION['currency'] ) and in_array( $_SESSION['currency'], \IPS\nexus\Money::currencies() ) ) ? $_SESSION['currency'] : \IPS\nexus\Customer::loggedIn()->defaultCurrency() ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -156,7 +165,7 @@ class _gifts extends \IPS\Dispatcher\Controller
|
||||
$currency = isset( $extra['currency'] ) ? $extra['currency'] : \IPS\nexus\Customer::loggedIn()->defaultCurrency();
|
||||
|
||||
$credits = \IPS\nexus\Customer::loggedIn()->cm_credits;
|
||||
$credits[ $currency ]->amount += $extra['amount'];
|
||||
$credits[ $currency ]->amount = $credits[ $currency ]->amount->add( new \IPS\Math\Number( number_format( $extra['amount'], \IPS\nexus\Money::numberOfDecimalsForCurrency( $currency ), '.', '' ) ) );
|
||||
\IPS\nexus\Customer::loggedIn()->cm_credits = $credits;
|
||||
\IPS\nexus\Customer::loggedIn()->save();
|
||||
|
||||
@@ -175,6 +184,7 @@ class _gifts extends \IPS\Dispatcher\Controller
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'redemption_code' );
|
||||
\IPS\Output::i()->output = $form;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user