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

@@ -2,9 +2,9 @@
/**
* @brief View Cart
* @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
@@ -53,7 +53,7 @@ class _cart extends \IPS\Dispatcher\Controller
{
$_SESSION['cart'] = array();
}
$currency = isset( $_SESSION['currency'] ) ? $_SESSION['currency'] : \IPS\nexus\Customer::loggedIn()->defaultCurrency();
$currency = ( isset( $_SESSION['currency'] ) and in_array( $_SESSION['currency'], \IPS\nexus\Money::currencies() ) ) ? $_SESSION['currency'] : \IPS\nexus\Customer::loggedIn()->defaultCurrency();
/* Display */
\IPS\Output::i()->bodyClasses[] = 'ipsLayout_minimal';
@@ -89,6 +89,7 @@ class _cart extends \IPS\Dispatcher\Controller
{
$v += $_item->quantity;
unset( $_SESSION['cart'][ $_k ] );
\IPS\Db::i()->update( 'nexus_cart_uploads', array( 'item_id' => $k ), array( 'session_id=? AND item_id=?', \IPS\Session::i()->id, $_k ) );
}
}
}
@@ -126,6 +127,14 @@ class _cart extends \IPS\Dispatcher\Controller
if ( $_SESSION['cart'][ $k ]->quantity == 0 )
{
unset( $_SESSION['cart'][ $k ] );
$ids = array();
foreach ( \IPS\Db::i()->select( 'id', 'nexus_cart_uploads', array( 'session_id=? AND item_id=?', \IPS\Session::i()->id, $k ) ) as $id )
{
\IPS\File::unclaimAttachments( 'nexus_Purchases', $id, NULL, 'cart' );
$ids[] = $id;
}
\IPS\Db::i()->delete( 'nexus_cart_uploads', \IPS\Db::i()->in( 'id', $ids ) );
}
}
@@ -136,7 +145,7 @@ class _cart extends \IPS\Dispatcher\Controller
if ( \IPS\Request::i()->isAjax() )
{
$currency = isset( $_SESSION['currency'] ) ? $_SESSION['currency'] : \IPS\nexus\Customer::loggedIn()->defaultCurrency();
$currency = ( isset( $_SESSION['currency'] ) and in_array( $_SESSION['currency'], \IPS\nexus\Money::currencies() ) ) ? $_SESSION['currency'] : \IPS\nexus\Customer::loggedIn()->defaultCurrency();
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate('store')->cartContents( ( isset( $_SESSION['location'] ) and $_SESSION['location'] ) ? \IPS\GeoLocation::buildFromJson( $_SESSION['location'] ) : NULL, $currency ), 200, 'text/html' );
}
else
@@ -155,6 +164,13 @@ class _cart extends \IPS\Dispatcher\Controller
\IPS\Session::i()->csrfCheck();
$_SESSION['cart'] = array();
$ids = array();
foreach ( \IPS\Db::i()->select( 'id', 'nexus_cart_uploads', array( 'session_id=?', \IPS\Session::i()->id ) ) as $id )
{
\IPS\File::unclaimAttachments( 'nexus_Purchases', $id, NULL, 'cart' );
$ids[] = $id;
}
\IPS\Db::i()->delete( 'nexus_cart_uploads', \IPS\Db::i()->in( 'id', $ids ) );
if ( \IPS\CACHE_PAGE_TIMEOUT and !\IPS\Member::loggedIn()->member_id )
{
@@ -180,21 +196,31 @@ class _cart extends \IPS\Dispatcher\Controller
{
\IPS\Session::i()->csrfCheck();
$currency = isset( $_SESSION['currency'] ) ? $_SESSION['currency'] : \IPS\nexus\Customer::loggedIn()->defaultCurrency();
$currency = ( isset( $_SESSION['currency'] ) and in_array( $_SESSION['currency'], \IPS\nexus\Money::currencies() ) ) ? $_SESSION['currency'] : \IPS\nexus\Customer::loggedIn()->defaultCurrency();
$canRegister = ( !\IPS\Settings::i()->nexus_reg_force or \IPS\Member::loggedIn()->member_id );
$tempInvoiceKey = md5( uniqid() );
$invoice = new \IPS\nexus\Invoice;
$invoice->member = \IPS\nexus\Customer::loggedIn();
$invoice->currency = $currency;
foreach ( $_SESSION['cart'] as $item )
foreach ( $_SESSION['cart'] as $k => $item )
{
if ( !$canRegister and \IPS\nexus\Package::load( $item->id )->reg )
{
$canRegister = TRUE;
}
$invoice->addItem( $item );
$itemId = $invoice->addItem( $item );
$ids = array();
foreach ( \IPS\Db::i()->select( 'id', 'nexus_cart_uploads', array( 'session_id=? AND item_id=?', \IPS\Session::i()->id, $k ) ) as $id )
{
\IPS\Db::i()->update( 'core_attachments_map', array( 'id1' => $itemId, 'id3' => "invoice-{$tempInvoiceKey}" ), array( 'location_key=? AND id1=? AND id3=?', 'nexus_Purchases', $id, 'cart' ) );
$ids[] = $id;
}
\IPS\Db::i()->delete( 'nexus_cart_uploads', \IPS\Db::i()->in( 'id', $ids ) );
}
if ( !count( $invoice->items ) )
@@ -207,7 +233,7 @@ class _cart extends \IPS\Dispatcher\Controller
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=nexus&module=store&controller=store&do=register', 'front', 'store' ) );
}
if ( $minimumOrderAmounts = json_decode( \IPS\Settings::i()->nexus_minimum_order, TRUE ) and $minimumOrderAmounts[ $currency ]['amount'] > $invoice->total->amount )
if ( $minimumOrderAmounts = json_decode( \IPS\Settings::i()->nexus_minimum_order, TRUE ) and ( new \IPS\Math\Number( number_format( $minimumOrderAmounts[ $currency ]['amount'], 2, '.', '' ) ) )->compare( $invoice->total->amount ) === 1 )
{
\IPS\Output::i()->error( \IPS\Member::loggedIn()->language()->addToStack( 'err_minimum_order', FALSE, array( 'sprintf' => array( new \IPS\nexus\Money( $minimumOrderAmounts[ $currency ]['amount'], $currency ) ) ) ), '1X214/1', 403, '' );
}
@@ -217,6 +243,10 @@ class _cart extends \IPS\Dispatcher\Controller
{
\IPS\Request::i()->setCookie( 'noCache', 0, \IPS\DateTime::ts( time() - 86400 ) );
}
$invoice->save();
\IPS\Db::i()->update( 'core_attachments_map', array( 'id3' => "invoice-{$invoice->id}" ), array( 'location_key=? AND id3=?', 'nexus_Purchases', "invoice-{$tempInvoiceKey}" ) );
\IPS\Output::i()->redirect( $invoice->checkoutUrl() );
}
}
@@ -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;
}
}
@@ -2,9 +2,9 @@
/**
* @brief View product
* @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
@@ -59,7 +59,7 @@ class _product extends \IPS\Content\Controller
{
$_SESSION['cart'] = array();
}
$memberCurrency = ( isset( $_SESSION['currency'] ) ? $_SESSION['currency'] : \IPS\nexus\Customer::loggedIn()->defaultCurrency() );
$memberCurrency = ( ( isset( $_SESSION['currency'] ) and in_array( $_SESSION['currency'], \IPS\nexus\Money::currencies() ) ) ? $_SESSION['currency'] : \IPS\nexus\Customer::loggedIn()->defaultCurrency() );
/* Load Package */
$item = parent::manage();
@@ -68,21 +68,31 @@ class _product extends \IPS\Content\Controller
\IPS\Output::i()->error( 'node_error', '2X240/1', 404, '' );
}
$package = \IPS\nexus\Package::load( $item->id );
/* Do we have any in the cart already (this will affect stock level)? */
$inCart = 0;
$inCart = array();
foreach ( $_SESSION['cart'] as $itemInCart )
{
if ( $itemInCart->id === $package->id )
{
$inCart += $itemInCart->quantity;
$optionValues = array();
foreach( $package->optionIdKeys() as $id )
{
$optionValues[ $id ] = $itemInCart->details[$id];
}
$optionValues = json_encode( $optionValues );
if ( !isset( $inCart[ $optionValues ] ) )
{
$inCart[ $optionValues ] = 0;
}
$inCart[ $optionValues ] += $itemInCart->quantity;
}
}
/* Showing just the form to purchase, or full product page? */
if ( \IPS\Request::i()->purchase )
{
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('store')->purchaseForm( $package, $item, $this->_getForm( $package, $inCart, TRUE ), $inCart );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('store')->purchaseForm( $package, $item, $this->_getForm( $package, $inCart, TRUE ) );
}
/* No - show the full page */
@@ -140,7 +150,7 @@ class _product extends \IPS\Content\Controller
}
/* Easypost */
if ( \IPS\Settings::i()->easypost_api_key and \IPS\Settings::i()->easypost_show_rates and ( $package->shipping == '*' or in_array( 'easypost', explode( ',', $package->shipping ) ) ) )
if ( $shipAddress and \IPS\Settings::i()->easypost_api_key and \IPS\Settings::i()->easypost_show_rates and ( $package->shipping == '*' or in_array( 'easypost', explode( ',', $package->shipping ) ) ) )
{
try
{
@@ -176,12 +186,20 @@ class _product extends \IPS\Content\Controller
if ( count( $renewOptions ) === 1 )
{
$renewalTerm = array_pop( $renewOptions );
$renewalTerm = new \IPS\nexus\Purchase\RenewalTerm( new \IPS\nexus\Money( $renewalTerm['cost'][ $memberCurrency ]['amount'], $memberCurrency ), new \DateInterval( 'P' . $renewalTerm['term'] . mb_strtoupper( $renewalTerm['unit'] ) ), isset( $this->tax ) ? \IPS\nexus\Tax::load( $this->tax ) : NULL, $renewalTerm['add'] );
$renewalTerm = new \IPS\nexus\Purchase\RenewalTerm( new \IPS\nexus\Money( $renewalTerm['cost'][ $memberCurrency ]['amount'], $memberCurrency ), new \DateInterval( 'P' . $renewalTerm['term'] . mb_strtoupper( $renewalTerm['unit'] ) ), $package->tax ? \IPS\nexus\Tax::load( $package->tax ) : NULL, $renewalTerm['add'] );
}
}
/* Display */
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('store')->package( $package, $item, $this->_getForm( $package, $inCart, TRUE ), $inCart, $shippingMethods, $itemDataForShipping, $locationType, $renewalTerm );
$formKey = "package_{$package->id}_submitted";
if ( \IPS\Request::i()->isAjax() and isset( \IPS\Request::i()->$formKey ) )
{
\IPS\Output::i()->sendOutput( $this->_getForm( $package, $inCart, TRUE ), 500 );
}
else
{
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('store')->package( $package, $item, $this->_getForm( $package, $inCart, TRUE ), array_sum( $inCart ), $shippingMethods, $itemDataForShipping, $locationType, $renewalTerm );
}
}
}
@@ -189,13 +207,13 @@ class _product extends \IPS\Content\Controller
* Get form
*
* @param \IPS\nexus\Package $package The package
* @param int $inCart The number in the cart already
* @param array $inCart The number in the cart already for each of the field combinations
* @return string
*/
protected function _getForm( \IPS\nexus\Package $package, $inCart, $verticalForm = FALSE )
{
/* Get member's currency */
$memberCurrency = ( isset( $_SESSION['currency'] ) ? $_SESSION['currency'] : \IPS\nexus\Customer::loggedIn()->defaultCurrency() );
$memberCurrency = ( ( isset( $_SESSION['currency'] ) and in_array( $_SESSION['currency'], \IPS\nexus\Money::currencies() ) ) ? $_SESSION['currency'] : \IPS\nexus\Customer::loggedIn()->defaultCurrency() );
/* Init form */
$form = new \IPS\Helpers\Form( "package_{$package->id}", 'add_to_cart' );
@@ -209,7 +227,7 @@ class _product extends \IPS\Content\Controller
$package->storeForm( $form, $memberCurrency );
/* Are we in stock? */
if ( $package->stock != -1 and $package->stock != -2 and ( $package->stock - $inCart ) <= 0 )
if ( $package->stock != -1 and $package->stock != -2 and ( $package->stock - array_sum( $inCart ) ) <= 0 )
{
$form->actionButtons = array();
$form->addButton( 'out_of_stock', 'submit', NULL, 'ipsButton ipsButton_primary', array( 'disabled' => 'disabled' ) );
@@ -245,9 +263,9 @@ class _product extends \IPS\Content\Controller
{
$customFields = \IPS\nexus\Package\CustomField::roots();
$stickyFields = array();
foreach ( $item->details as $k => $v )
foreach ( $item->details as $j => $v )
{
if ( $v and isset( $customFields[ $k ] ) and $customFields[ $k ]->sticky )
if ( $v and isset( $customFields[ $j ] ) and $customFields[ $j ]->sticky )
{
$stickyFields[] = $v;
}
@@ -317,24 +335,50 @@ class _product extends \IPS\Content\Controller
$customFields = \IPS\nexus\Package\CustomField::roots( NULL, NULL, array( array( 'cf_purchase=1' ), array( \IPS\Db::i()->findInSet( 'cf_packages', array( $package->id ) ) ) ) );
foreach ( $customFields as $field )
{
if( \IPS\Request::i()->isAjax() && isset( \IPS\Request::i()->stockCheck ) )
{
$field->required = FALSE; // Otherwise a required text field (for example) can block the price changing when a different radio (for example) value is selected
}
$form->add( $field->buildHelper() );
}
/* Is this the validation for the additional page? */
if ( \IPS\Request::i()->isAjax() and isset( \IPS\Request::i()->additionalPageCheck ) )
{
if ( $additionalPage = $package->storeAdditionalPage( $_POST ) )
{
\IPS\Output::i()->httpHeaders['X-IPS-FormNoSubmit'] = "true";
\IPS\Output::i()->json( $additionalPage );
}
}
/* Handle submissions */
if ( $values = $form->values() )
{
/* Custom fields */
$details = array();
foreach ( $values as $k => $v )
$editorUploadIds = array();
foreach ( $customFields as $field )
{
if ( mb_substr( $k, 0, 13 ) == 'nexus_pfield_' )
if ( isset( $values[ 'nexus_pfield_' . $field->id ] ) )
{
$class = \IPS\nexus\Package\CustomField::load( mb_substr( $k, 13 ) )->buildHelper();
$details[ mb_substr( $k, 13 ) ] = $class::stringValue( $v );
$class = $field->buildHelper();
$details[ $field->id ] = $class::stringValue( $values[ 'nexus_pfield_' . $field->id ] );
if ( !isset( \IPS\Request::i()->stockCheck ) and $field->type === 'Editor' )
{
$uploadId = \IPS\Db::i()->insert( 'nexus_cart_uploads', array(
'session_id' => \IPS\Session::i()->id,
'time' => time()
) );
$field->claimAttachments( $uploadId, 'cart' );
$editorUploadIds[] = $uploadId;
}
}
}
$optionValues = $package->optionValues( $details );
/* Stock check */
$quantity = isset( $values['quantity'] ) ? $values['quantity'] : 1;
try
@@ -345,7 +389,8 @@ class _product extends \IPS\Content\Controller
{
\IPS\Output::i()->error( 'product_options_price_error', '3X240/2', 500, 'product_options_price_error_admin' );
}
$inCartForThisFieldCombination = isset( $inCart[ json_encode( $optionValues ) ] ) ? $inCart[ json_encode( $optionValues ) ] : 0;
if ( \IPS\Request::i()->isAjax() && isset( \IPS\Request::i()->stockCheck ) )
{
/* Stock */
@@ -357,10 +402,10 @@ class _product extends \IPS\Content\Controller
);
}
else
{
{
$return = array(
'stock' => \IPS\Member::loggedIn()->language()->addToStack( 'x_in_stock', FALSE, array( 'pluralize' => array( $data['stock'] - $inCart ) ) ),
'okay' => true
'stock' => \IPS\Member::loggedIn()->language()->addToStack( 'x_in_stock', FALSE, array( 'pluralize' => array( $data['stock'] - $inCartForThisFieldCombination ) ) ),
'okay' => ( $data['stock'] - $inCartForThisFieldCombination > 0 ) ? true : false,
);
}
@@ -376,11 +421,11 @@ class _product extends \IPS\Content\Controller
if ( $term['add'] )
{
$data['price']->amount += $term['cost'][ $memberCurrency ]['amount'];
$normalPrice->amount += $term['cost'][ $memberCurrency ]['amount'];
$data['price']->amount = $data['price']->amount->add( new \IPS\Math\Number( number_format( $term['cost'][ $memberCurrency ]['amount'], \IPS\nexus\Money::numberOfDecimalsForCurrency( $memberCurrency ), '.', '' ) ) );
$normalPrice->amount = $normalPrice->amount->add( new \IPS\Math\Number( number_format( $term['cost'][ $memberCurrency ]['amount'], \IPS\nexus\Money::numberOfDecimalsForCurrency( $memberCurrency ), '.', '' ) ) );
}
$return['renewal'] = \IPS\Member::loggedIn()->language()->addToStack( 'and_renewal', FALSE, array( 'sprintf' => array( new \IPS\nexus\Purchase\RenewalTerm( new \IPS\nexus\Money( $term['cost'][ $memberCurrency ]['amount'] + $_data['renewalAdjustment'], $memberCurrency ), new \DateInterval( 'P' . $term['term'] . mb_strtoupper( $term['unit'] ) ), isset( $this->tax ) ? \IPS\nexus\Tax::load( $this->tax ) : NULL, $term['add'] ) ) ) );
$return['renewal'] = \IPS\Member::loggedIn()->language()->addToStack( 'and_renewal', FALSE, array( 'sprintf' => array( new \IPS\nexus\Purchase\RenewalTerm( new \IPS\nexus\Money( ( new \IPS\Math\Number( number_format( $term['cost'][ $memberCurrency ]['amount'], \IPS\nexus\Money::numberOfDecimalsForCurrency( $memberCurrency ), '.', '' ) ) )->add( ( new \IPS\Math\Number( number_format( $_data['renewalAdjustment'], \IPS\nexus\Money::numberOfDecimalsForCurrency( $memberCurrency ), '.', '' ) ) ) ), $memberCurrency ), new \DateInterval( 'P' . $term['term'] . mb_strtoupper( $term['unit'] ) ), $package->tax ? \IPS\nexus\Tax::load( $package->tax ) : NULL, $term['add'] ) ) ) );
}
else
{
@@ -392,16 +437,16 @@ class _product extends \IPS\Content\Controller
{
try
{
$taxRate = \IPS\nexus\Tax::load( $package->tax )->rate( \IPS\nexus\Customer::loggedIn()->estimatedLocation() );
$taxRate = new \IPS\Math\Number( \IPS\nexus\Tax::load( $package->tax )->rate( \IPS\nexus\Customer::loggedIn()->estimatedLocation() ) );
$data['price']->amount += ( $data['price']->amount * $taxRate );
$normalPrice->amount += ( $normalPrice->amount * $taxRate );
$data['price']->amount = $data['price']->amount->add( $data['price']->amount->multiply( $taxRate ) );
$normalPrice->amount = $normalPrice->amount->add( $normalPrice->amount->multiply( $taxRate ) );
}
catch ( \OutOfRangeException $e ) { }
}
/* Format and return */
if ( $data['price']->amount != $normalPrice->amount )
if ( $data['price']->amount->compare( $normalPrice->amount ) !== 0 )
{
$return['price'] = \IPS\Theme::i()->getTemplate( 'store', 'nexus' )->priceDiscounted( $normalPrice, $data['price'], FALSE );
}
@@ -411,11 +456,23 @@ class _product extends \IPS\Content\Controller
}
\IPS\Output::i()->json( $return );
}
elseif ( $data['stock'] != -1 and ( $data['stock'] - $inCart ) < $quantity )
elseif ( $data['stock'] != -1 and ( $data['stock'] - $inCartForThisFieldCombination ) < $quantity )
{
$form->error = \IPS\Member::loggedIn()->language()->addToStack( 'not_enough_in_stock', FALSE, array( 'sprintf' => array( $data['stock'] - $inCart ) ) );
$form->error = \IPS\Member::loggedIn()->language()->addToStack( 'not_enough_in_stock', FALSE, array( 'sprintf' => array( $data['stock'] - $inCartForThisFieldCombination ) ) );
return (string) $form;
}
if ( ( !isset( \IPS\Request::i()->additionalPageCheck ) or !\IPS\Request::i()->isAjax() ) and $additionalPage = $package->storeAdditionalPage( $_POST ) )
{
if ( \IPS\Request::i()->isAjax() )
{
\IPS\Output::i()->json( $additionalPage );
}
else
{
return $additionalPage;
}
}
/* Work out renewal term */
$renewalTerm = NULL;
@@ -430,7 +487,7 @@ class _product extends \IPS\Content\Controller
$chosenRenewOption = $renewOptions[ $values['renewal_term'] ];
}
$renewalTerm = new \IPS\nexus\Purchase\RenewalTerm( new \IPS\nexus\Money( $chosenRenewOption['cost'][ $memberCurrency ]['amount'] + $data['renewalAdjustment'], $memberCurrency ), new \DateInterval( 'P' . $chosenRenewOption['term'] . mb_strtoupper( $chosenRenewOption['unit'] ) ), isset( $this->tax ) ? \IPS\nexus\Tax::load( $this->tax ) : NULL, $chosenRenewOption['add'], $package->grace_period ? new \DateInterval( 'P' . $package->grace_period . 'D' ) : NULL );
$renewalTerm = new \IPS\nexus\Purchase\RenewalTerm( new \IPS\nexus\Money( ( new \IPS\Math\Number( number_format( $chosenRenewOption['cost'][ $memberCurrency ]['amount'], 2, '.', '' ) ) )->add( new \IPS\Math\Number( number_format( $data['renewalAdjustment'], 2, '.', '' ) ) ), $memberCurrency ), new \DateInterval( 'P' . $chosenRenewOption['term'] . mb_strtoupper( $chosenRenewOption['unit'] ) ), $package->tax ? \IPS\nexus\Tax::load( $package->tax ) : NULL, $chosenRenewOption['add'], $package->grace_period ? new \DateInterval( 'P' . $package->grace_period . 'D' ) : NULL );
}
/* Associations */
@@ -448,8 +505,9 @@ class _product extends \IPS\Content\Controller
}
}
/* Blah */
$package->addItemsToCartData( $details, $quantity, $renewalTerm, $parent, $values );
/* Actually add to cart */
$cartId = $package->addItemsToCartData( $details, $quantity, $renewalTerm, $parent, $values );
\IPS\Db::i()->update( 'nexus_cart_uploads', array( 'item_id' => $cartId ), \IPS\Db::i()->in( 'id', $editorUploadIds ) );
/* Redirect or AJAX */
if ( \IPS\Request::i()->isAjax() )
@@ -458,7 +516,7 @@ class _product extends \IPS\Content\Controller
$upsell = \IPS\nexus\Package\Item::getItemsWithPermission( array( array( 'p_upsell=1' ), array( \IPS\Db::i()->findInSet( 'p_associable', array( $package->id ) ) ) ), 'p_position' );
/* Send */
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate('store')->cartReview( $package, $quantity, $upsell ), 200, 'text/html' );
\IPS\Output::i()->json( array( 'dialog' => \IPS\Theme::i()->getTemplate('store')->cartReview( $package, $quantity, $upsell ), 'cart' => \IPS\Theme::i()->getTemplate('store')->cartHeader() ) );
}
else
{
@@ -2,9 +2,9 @@
/**
* @brief Browse Store
* @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
@@ -53,7 +53,7 @@ class _store extends \IPS\Dispatcher\Controller
*/
protected function manage()
{
/* Work out currenty */
/* Work out currency */
if ( isset( \IPS\Request::i()->currency ) and in_array( \IPS\Request::i()->currency, \IPS\nexus\Money::currencies() ) )
{
if ( isset( \IPS\Request::i()->csrfKey ) and \IPS\Request::i()->csrfKey === \IPS\Session\Front::i()->csrfKey )
@@ -81,7 +81,7 @@ class _store extends \IPS\Dispatcher\Controller
\IPS\Request::i()->cookie['storeView'] = ( \IPS\Request::i()->view == 'list' ) ? 'list' : 'grid';
}
$subcategories = new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_package_groups', array( 'pg_parent=?', $category->id ) ), 'IPS\nexus\Package\Group' );
$subcategories = new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_package_groups', array( 'pg_parent=?', $category->id ), 'pg_position ASC' ), 'IPS\nexus\Package\Group' );
$joins = array();
switch ( \IPS\Request::i()->sortby )
@@ -124,6 +124,11 @@ class _store extends \IPS\Dispatcher\Controller
}
$packages = new \IPS\Patterns\ActiveRecordIterator( $select, 'IPS\nexus\Package' );
$totalCount = \IPS\Db::i()->select( 'count(*)', 'nexus_packages', array(
array( 'p_group=?', $category->id ),
array( 'p_store=1' ),
array( "( p_member_groups='*' OR " . \IPS\Db::i()->findInSet( 'p_member_groups', \IPS\Member::loggedIn()->groups ) . ' )' )
) )->first();
$totalPages = ceil( $packages->count( TRUE ) / static::$productsPerPage );
if ( $totalPages and $currentPage > $totalPages )
@@ -139,7 +144,7 @@ class _store extends \IPS\Dispatcher\Controller
}
\IPS\Output::i()->sidebar['contextual'] = \IPS\Theme::i()->getTemplate('store')->categorySidebar( $category, $subcategories );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('store')->category( $category, $subcategories, $packages, $pagination, $packagesWithCustomFields );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('store')->category( $category, $subcategories, $packages, $pagination, $packagesWithCustomFields, $totalCount );
foreach ( $category->parents() as $parent )
{
@@ -199,7 +204,7 @@ class _store extends \IPS\Dispatcher\Controller
{
\IPS\Output::i()->bodyClasses[] = 'ipsLayout_minimal';
\IPS\Output::i()->sidebar['enabled'] = FALSE;
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('store')->register( \IPS\nexus\Package\Item::getItemsWithPermission( array( array( 'p_reg=1' ) ), 'p_date_added DESC' ) );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('store')->register( \IPS\nexus\Package\Item::getItemsWithPermission( array( array( 'p_reg=1' ) ), 'pg_position, p_position', 10, 'read', \IPS\Content\Hideable::FILTER_AUTOMATIC, 0, NULL, TRUE ) );
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('sign_up');
}