Version 4.0.13.1
This commit is contained in:
1 parent
f9e857d255
commit
c6a86f0d9b
7517 files changed
+597400
-668041
No files matched your search
@@ -0,0 +1,222 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief View Cart
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage Nexus
|
||||
* @since 29 Apr 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\front\store;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* View Cart
|
||||
*/
|
||||
class _cart extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'store.css', 'nexus' ) );
|
||||
|
||||
if ( \IPS\Theme::i()->settings['responsive'] )
|
||||
{
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'store_responsive.css', 'nexus', 'front' ) );
|
||||
}
|
||||
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* View Cart
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
/* Init */
|
||||
if ( !isset( $_SESSION['cart'] ) )
|
||||
{
|
||||
$_SESSION['cart'] = array();
|
||||
}
|
||||
$currency = isset( $_SESSION['currency'] ) ? $_SESSION['currency'] : \IPS\nexus\Customer::loggedIn()->defaultCurrency();
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->bodyClasses[] = 'ipsLayout_minimal';
|
||||
\IPS\Output::i()->sidebar['enabled'] = FALSE;
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('your_cart');
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('store')->cart( ( isset( $_SESSION['location'] ) and $_SESSION['location'] ) ? \IPS\GeoLocation::buildFromJson( $_SESSION['location'] ) : NULL, $currency );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update Quantities
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function quantities()
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
|
||||
foreach ( \IPS\Request::i()->item as $k => $v )
|
||||
{
|
||||
/* Get item */
|
||||
$item = $_SESSION['cart'][ $k ];
|
||||
$package = \IPS\nexus\Package::load( $item->id );
|
||||
|
||||
/* Are any others just a duplicate for discount purposes? If so, condense them into this one */
|
||||
foreach ( $_SESSION['cart'] as $_k => $_item )
|
||||
{
|
||||
if ( $_k != $k and $_item->id == $package->id )
|
||||
{
|
||||
$cloned = clone $_item;
|
||||
$cloned->quantity = $item->quantity;
|
||||
$cloned->price = $item->price;
|
||||
if ( $cloned == $item )
|
||||
{
|
||||
$v += $_item->quantity;
|
||||
unset( $_SESSION['cart'][ $_k ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Subscriptions can only have 1 */
|
||||
if ( $package->subscription and $v > 1 )
|
||||
{
|
||||
\IPS\Output::i()->error( 'err_subscription_qty', '1X214/4', 403, '' );
|
||||
}
|
||||
|
||||
/* Set the quantity back to 0 and "re-add" the item */
|
||||
$item->quantity = 0;
|
||||
if ( $v )
|
||||
{
|
||||
$data = $package->optionValuesStockAndPrice( $package->optionValues( $item->details ) );
|
||||
if ( $data['stock'] != -1 and ( $data['stock'] - $item->quantity ) < $v )
|
||||
{
|
||||
\IPS\Output::i()->error( \IPS\Member::loggedIn()->language()->addToStack( 'not_enough_in_stock', FALSE, array( 'sprintf' => array( $data['stock'] - $item->quantity ) ) ), '1X214/3', 403, '' );
|
||||
}
|
||||
|
||||
$package->addItemsToCartData( $item->details, $v, $item->renewalTerm, $item->parent );
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach ( $_SESSION['cart'] as $k2 => $_item )
|
||||
{
|
||||
if ( $_item->parent === $k )
|
||||
{
|
||||
unset( $_SESSION['cart'][ $k2 ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* And if the quantity is 0, remove it */
|
||||
if ( $_SESSION['cart'][ $k ]->quantity == 0 )
|
||||
{
|
||||
unset( $_SESSION['cart'][ $k ] );
|
||||
}
|
||||
}
|
||||
|
||||
if ( empty( $_SESSION['cart'] ) and \IPS\CACHE_PAGE_TIMEOUT and !\IPS\Member::loggedIn()->member_id )
|
||||
{
|
||||
\IPS\Request::i()->setCookie( 'noCache', 0, \IPS\DateTime::ts( time() - 86400 ) );
|
||||
}
|
||||
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
{
|
||||
$currency = isset( $_SESSION['currency'] ) ? $_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
|
||||
{
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=store&controller=cart', 'front', 'store_cart' ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty Cart
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function clear()
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
|
||||
$_SESSION['cart'] = array();
|
||||
|
||||
if ( \IPS\CACHE_PAGE_TIMEOUT and !\IPS\Member::loggedIn()->member_id )
|
||||
{
|
||||
\IPS\Request::i()->setCookie( 'noCache', 0, \IPS\DateTime::ts( time() - 86400 ) );
|
||||
}
|
||||
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->json( $_SESSION['cart'] );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=store&controller=cart', 'front', 'store_cart' ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checkout
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function checkout()
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
|
||||
$currency = isset( $_SESSION['currency'] ) ? $_SESSION['currency'] : \IPS\nexus\Customer::loggedIn()->defaultCurrency();
|
||||
|
||||
$canRegister = ( !\IPS\Settings::i()->nexus_reg_force or \IPS\Member::loggedIn()->member_id );
|
||||
|
||||
$invoice = new \IPS\nexus\Invoice;
|
||||
$invoice->member = \IPS\nexus\Customer::loggedIn();
|
||||
$invoice->currency = $currency;
|
||||
foreach ( $_SESSION['cart'] as $item )
|
||||
{
|
||||
if ( !$canRegister and \IPS\nexus\Package::load( $item->id )->reg )
|
||||
{
|
||||
$canRegister = TRUE;
|
||||
}
|
||||
|
||||
$invoice->addItem( $item );
|
||||
}
|
||||
|
||||
if ( !count( $invoice->items ) )
|
||||
{
|
||||
\IPS\Output::i()->error( 'your_cart_empty', '2X214/2', 403, '' );
|
||||
}
|
||||
|
||||
if ( !$canRegister )
|
||||
{
|
||||
\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 )
|
||||
{
|
||||
\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, '' );
|
||||
}
|
||||
|
||||
$_SESSION['cart'] = array();
|
||||
if ( \IPS\CACHE_PAGE_TIMEOUT and !\IPS\Member::loggedIn()->member_id )
|
||||
{
|
||||
\IPS\Request::i()->setCookie( 'noCache', 0, \IPS\DateTime::ts( time() - 86400 ) );
|
||||
}
|
||||
\IPS\Output::i()->redirect( $invoice->checkoutUrl() );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Gift Vouchers
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage Nexus
|
||||
* @since 5 May 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\front\store;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gift Vouchers
|
||||
*/
|
||||
class _gifts extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'front_store.js', 'nexus', 'front' ) );
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'store.css', 'nexus' ) );
|
||||
|
||||
if ( \IPS\Theme::i()->settings['responsive'] )
|
||||
{
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'store_responsive.css', 'nexus', 'front' ) );
|
||||
}
|
||||
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Buy
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
/* Work out what our options are */
|
||||
$memberCurrency = ( isset( $_SESSION['currency'] ) ? $_SESSION['currency'] : \IPS\nexus\Customer::loggedIn()->defaultCurrency() );
|
||||
$options = array();
|
||||
foreach ( json_decode( \IPS\Settings::i()->nexus_gift_vouchers, TRUE ) as $voucher )
|
||||
{
|
||||
if ( isset( $voucher[ $memberCurrency ] ) and $voucher[ $memberCurrency ] )
|
||||
{
|
||||
$options[ $voucher[ $memberCurrency ] ] = new \IPS\nexus\Money( $voucher[ $memberCurrency ], $memberCurrency );
|
||||
}
|
||||
}
|
||||
if ( \IPS\Settings::i()->nexus_gift_vouchers_free )
|
||||
{
|
||||
$options['x'] = \IPS\Member::loggedIn()->language()->addToStack('other');
|
||||
}
|
||||
if ( empty( $options ) )
|
||||
{
|
||||
\IPS\Output::i()->error( 'no_module_permission', '4X213/2', 403, '' );
|
||||
}
|
||||
|
||||
$form = new \IPS\Helpers\Form( 'form', 'buy_gift_voucher' );
|
||||
$form->class = 'ipsForm_vertical';
|
||||
$form->add( new \IPS\Helpers\Form\Color( 'gift_voucher_color', '3b3b3b', FALSE ) );
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'gift_voucher_amount', NULL, TRUE, array( 'options' => $options, 'parse' => 'none', 'userSuppliedInput' => 'x' ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'gift_voucher_method', NULL, TRUE, array( 'options' => array( 'email' => 'email', 'print' => 'gift_voucher_print' ), 'toggles' => array( 'email' => array( 'gift_voucher_email' ) ) ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Email( 'gift_voucher_email', NULL, NULL, array(), function( $val )
|
||||
{
|
||||
if ( !$val and \IPS\Request::i()->gift_voucher_method === 'email' )
|
||||
{
|
||||
throw new \DomainException('form_required');
|
||||
}
|
||||
}, NULL, NULL, 'gift_voucher_email' ) );
|
||||
$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;
|
||||
|
||||
$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 */
|
||||
\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') );
|
||||
}
|
||||
|
||||
/**
|
||||
* [AJAX] Format currency amount
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
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() ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Redeem
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function redeem()
|
||||
{
|
||||
if ( !\IPS\nexus\Customer::loggedIn()->member_id )
|
||||
{
|
||||
\IPS\Output::i()->error( 'redeem_must_be_logged_in', '1X213/1', 403, '' );
|
||||
}
|
||||
|
||||
$form = new \IPS\Helpers\Form( 'form', 'redeem_gift_voucher' );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'redemption_code', isset( \IPS\Request::i()->code ) ? \IPS\Request::i()->code : NULL, TRUE, array(), function( $val )
|
||||
{
|
||||
try
|
||||
{
|
||||
\IPS\nexus\extensions\nexus\Item\GiftVoucher::getPurchase( $val );
|
||||
}
|
||||
catch ( \InvalidArgumentException $e )
|
||||
{
|
||||
throw new \DomainException('redeem_gift_voucher_error');
|
||||
}
|
||||
} ) );
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
$purchase = \IPS\nexus\extensions\nexus\Item\GiftVoucher::getPurchase( $values['redemption_code'] );
|
||||
$extra = $purchase->extra;
|
||||
$currency = isset( $extra['currency'] ) ? $extra['currency'] : \IPS\nexus\Customer::loggedIn()->defaultCurrency();
|
||||
|
||||
$credits = \IPS\nexus\Customer::loggedIn()->cm_credits;
|
||||
$credits[ $currency ]->amount += $extra['amount'];
|
||||
\IPS\nexus\Customer::loggedIn()->cm_credits = $credits;
|
||||
\IPS\nexus\Customer::loggedIn()->save();
|
||||
|
||||
\IPS\nexus\Customer::loggedIn()->log( 'giftvoucher', array( 'type' => 'redeemed', 'code' => $values['redemption_code'], 'amount' => $extra['amount'], 'currency' => $extra['currency'], 'ps_member' => $purchase->member->member_id, 'newCreditAmount' => $credits[ $currency ]->amount ) );
|
||||
$purchase->member->log( 'giftvoucher', array( 'type' => 'used', 'code' => $values['redemption_code'], 'amount' => $extra['amount'], 'currency' => $extra['currency'], 'by' => \IPS\nexus\Customer::loggedIn()->member_id ) );
|
||||
|
||||
$purchase->delete();
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=nexus&module=store&controller=store¤cy={$currency}", 'front', 'store' ) );
|
||||
}
|
||||
|
||||
if( \IPS\Request::i()->isAjax() )
|
||||
{
|
||||
$form->class = 'ipsForm_vertical';
|
||||
\IPS\Output::i()->output = $form->customTemplate( array( call_user_func_array( array( \IPS\Theme::i(), 'getTemplate' ), array( 'forms', 'core', 'front' ) ), 'popupTemplate' ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->output = $form;
|
||||
}
|
||||
}
|
||||
}
|
||||
Whitespace-only changes.
@@ -0,0 +1,473 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief View product
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage Nexus
|
||||
* @since 29 Apr 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\front\store;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* View product
|
||||
*/
|
||||
class _product extends \IPS\Content\Controller
|
||||
{
|
||||
/**
|
||||
* [Content\Controller] Class
|
||||
*/
|
||||
protected static $contentModel = 'IPS\nexus\Package\Item';
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'front_store.js', 'nexus', 'front' ) );
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'store.css', 'nexus' ) );
|
||||
|
||||
if ( \IPS\Theme::i()->settings['responsive'] )
|
||||
{
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'store_responsive.css', 'nexus', 'front' ) );
|
||||
}
|
||||
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* View
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
/* Init */
|
||||
if ( !isset( $_SESSION['cart'] ) )
|
||||
{
|
||||
$_SESSION['cart'] = array();
|
||||
}
|
||||
$memberCurrency = ( isset( $_SESSION['currency'] ) ? $_SESSION['currency'] : \IPS\nexus\Customer::loggedIn()->defaultCurrency() );
|
||||
|
||||
/* Load Package */
|
||||
$item = parent::manage();
|
||||
if ( !$item )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X240/1', 404, '' );
|
||||
}
|
||||
$package = \IPS\nexus\Package::load( $item->id );
|
||||
$category = \IPS\nexus\Package\Group::load( $item->group );
|
||||
|
||||
/* Do we have any in the cart already (this will affect stock level)? */
|
||||
$inCart = 0;
|
||||
foreach ( $_SESSION['cart'] as $itemInCart )
|
||||
{
|
||||
if ( $itemInCart->id === $package->id )
|
||||
{
|
||||
$inCart += $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 );
|
||||
}
|
||||
|
||||
/* No - show the full page */
|
||||
else
|
||||
{
|
||||
/* If physical, get available shipping methods */
|
||||
$shippingMethods = array();
|
||||
$locationType = 'none';
|
||||
if ( $package->physical )
|
||||
{
|
||||
/* Where are we shipping to? */
|
||||
$shipAddress = NULL;
|
||||
if ( \IPS\Member::loggedIn()->member_id )
|
||||
{
|
||||
try
|
||||
{
|
||||
$shipAddress = \IPS\nexus\Customer\Address::constructFromData( \IPS\Db::i()->select( '*', 'nexus_customer_addresses', array( 'member=? AND primary_billing=1', \IPS\Member::loggedIn()->member_id ) )->first() )->address;
|
||||
$locationType = 'address';
|
||||
}
|
||||
catch ( \UnderflowException $e ) { }
|
||||
}
|
||||
if ( !$shipAddress )
|
||||
{
|
||||
try
|
||||
{
|
||||
$shipAddress = \IPS\GeoLocation::getByIp( \IPS\Request::i()->ipAddress() );
|
||||
$locationType = 'geo';
|
||||
}
|
||||
catch ( \Exception $e ) { }
|
||||
}
|
||||
|
||||
/* Standard */
|
||||
$where = NULL;
|
||||
if ( $package->shipping != '*' )
|
||||
{
|
||||
$where = \IPS\Db::i()->in( 's_id', explode( ',', $package->shipping ) );
|
||||
}
|
||||
foreach ( \IPS\nexus\Shipping\FlatRate::roots( NULL, NULL, $where ) as $rate )
|
||||
{
|
||||
if ( ( $shipAddress and $rate->isAvailable( $shipAddress ) ) or ( $rate->locations === '*' ) )
|
||||
{
|
||||
$shippingMethods[] = $rate;
|
||||
}
|
||||
}
|
||||
|
||||
/* 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 ) ) ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
$fromAddress = \IPS\GeoLocation::buildFromJson( \IPS\Settings::i()->site_address );
|
||||
|
||||
$length = new \IPS\nexus\Shipping\Length( $package->length );
|
||||
$width = new \IPS\nexus\Shipping\Length( $package->width );
|
||||
$height = new \IPS\nexus\Shipping\Length( $package->height );
|
||||
$weight = new \IPS\nexus\Shipping\Weight( $package->weight );
|
||||
|
||||
$easyPost = \IPS\nexus\Shipping\EasyPostRate::getRates( $length->float('in'), $width->float('in'), $height->float('in'), $weight->float('oz'), \IPS\nexus\Customer::loggedIn(), $shipAddress, $memberCurrency );
|
||||
if ( isset( $easyPost['rates'] ) )
|
||||
{
|
||||
foreach ( $easyPost['rates'] as $rate )
|
||||
{
|
||||
if ( $rate['currency'] === $memberCurrency )
|
||||
{
|
||||
$shippingMethods[] = new \IPS\nexus\Shipping\EasyPostRate( $rate );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( \IPS\Http\Request\Exception $e ) { }
|
||||
}
|
||||
}
|
||||
|
||||
/* We need to create a dummy item so we can work out ship times/prices */
|
||||
$itemDataForShipping = NULL;
|
||||
if ( count( $shippingMethods ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
$itemDataForShipping = $package->createItemForCart( $package->price() );
|
||||
}
|
||||
catch ( \OutOfBoundsException $e ) { }
|
||||
}
|
||||
|
||||
/* Do we have renewal terms? */
|
||||
$renewalTerm = NULL;
|
||||
$renewOptions = $package->renew_options ? json_decode( $package->renew_options, TRUE ) : array();
|
||||
if ( count( $renewOptions ) )
|
||||
{
|
||||
$renewalTerm = TRUE;
|
||||
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'] );
|
||||
}
|
||||
}
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('store')->package( $package, $item, $this->_getForm( $package, $inCart, TRUE ), $inCart, $shippingMethods, $itemDataForShipping, $locationType, $renewalTerm );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get form
|
||||
*
|
||||
* @param \IPS\nexus\Package $package The package
|
||||
* @param int $inCart The number in the cart already
|
||||
* @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() );
|
||||
|
||||
/* Init form */
|
||||
$form = new \IPS\Helpers\Form( "package_{$package->id}", 'add_to_cart' );
|
||||
|
||||
if ( $verticalForm )
|
||||
{
|
||||
$form->class = 'ipsForm_vertical';
|
||||
}
|
||||
|
||||
/* Package-dependant fields */
|
||||
$package->storeForm( $form, $memberCurrency );
|
||||
|
||||
/* Are we in stock? */
|
||||
if ( $package->stock != -1 and $package->stock != -2 and ( $package->stock - $inCart ) <= 0 )
|
||||
{
|
||||
$form->actionButtons = array();
|
||||
$form->addButton( 'out_of_stock', 'submit', NULL, 'ipsButton ipsButton_primary', array( 'disabled' => 'disabled' ) );
|
||||
}
|
||||
|
||||
/* And is it available for our currency */
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
$price = $package->price();
|
||||
}
|
||||
catch ( \OutOfBoundsException $e )
|
||||
{
|
||||
$form->actionButtons = array();
|
||||
$form->addButton( 'currently_unavailable', 'submit', NULL, 'ipsButton ipsButton_primary', array( 'disabled' => 'disabled' ) );
|
||||
}
|
||||
}
|
||||
|
||||
/* Associate */
|
||||
if ( count( $package->associablePackages() ) )
|
||||
{
|
||||
$associableIds = array_keys( $package->associablePackages() );
|
||||
$associableOptions = array();
|
||||
foreach ( $_SESSION['cart'] as $k => $item )
|
||||
{
|
||||
if ( in_array( $item->id, $associableIds ) )
|
||||
{
|
||||
for ( $i = 0; $i < $item->quantity; $i++ )
|
||||
{
|
||||
$name = $item->name;
|
||||
if ( count( $item->details ) )
|
||||
{
|
||||
$customFields = \IPS\nexus\Package\CustomField::roots();
|
||||
$stickyFields = array();
|
||||
foreach ( $item->details as $k => $v )
|
||||
{
|
||||
if ( $v and isset( $customFields[ $k ] ) and $customFields[ $k ]->sticky )
|
||||
{
|
||||
$stickyFields[] = $v;
|
||||
}
|
||||
}
|
||||
if ( count( $stickyFields ) )
|
||||
{
|
||||
$name .= ' (' . implode( ' · ', $stickyFields ) . ')';
|
||||
}
|
||||
}
|
||||
$associableOptions['in_cart']["0.{$k}"] = $name;
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_purchases', array( array( 'ps_member=? AND ps_app=? AND ps_type=?', \IPS\nexus\Customer::loggedIn()->member_id, 'nexus', 'package' ), \IPS\Db::i()->in( 'ps_item_id', $associableIds ) ) ), 'IPS\nexus\Purchase' ) as $purchase )
|
||||
{
|
||||
$associableOptions['existing_purchases']["1.{$purchase->id}"] = $purchase->name;
|
||||
}
|
||||
|
||||
if ( !empty( $associableOptions ) )
|
||||
{
|
||||
if ( !$package->force_assoc )
|
||||
{
|
||||
array_unshift( $associableOptions, 'do_not_associate' );
|
||||
}
|
||||
$form->add( new \IPS\Helpers\Form\Select( 'associate_with', NULL, $package->force_assoc, array( 'options' => $associableOptions ) ) );
|
||||
}
|
||||
elseif ( $package->force_assoc )
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack("nexus_package_{$package->id}_assoc");
|
||||
}
|
||||
}
|
||||
|
||||
/* Renewal options */
|
||||
$renewOptions = $package->renew_options ? json_decode( $package->renew_options, TRUE ) : array();
|
||||
if ( count( $renewOptions ) > 1 )
|
||||
{
|
||||
$options = array();
|
||||
foreach ( $renewOptions as $k => $option )
|
||||
{
|
||||
if ( isset( $option['cost'][ $memberCurrency ] ) )
|
||||
{
|
||||
switch ( $option['unit'] )
|
||||
{
|
||||
case 'd':
|
||||
$term = \IPS\Member::loggedIn()->language()->addToStack('renew_days', FALSE, array( 'pluralize' => array( $option['term'] ) ) );
|
||||
break;
|
||||
case 'm':
|
||||
$term = \IPS\Member::loggedIn()->language()->addToStack('renew_months', FALSE, array( 'pluralize' => array( $option['term'] ) ) );
|
||||
break;
|
||||
case 'y':
|
||||
$term = \IPS\Member::loggedIn()->language()->addToStack('renew_years', FALSE, array( 'pluralize' => array( $option['term'] ) ) );
|
||||
break;
|
||||
}
|
||||
|
||||
$options[ $k ] =
|
||||
\IPS\Member::loggedIn()->language()->addToStack( 'renew_option', FALSE, array( 'sprintf' => array(
|
||||
(string) new \IPS\nexus\Money( $option['cost'][ $memberCurrency ]['amount'], $memberCurrency ),
|
||||
$term
|
||||
) ) );
|
||||
}
|
||||
}
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'renewal_term', NULL, TRUE, array( 'options' => $options ) ) );
|
||||
}
|
||||
|
||||
/* Custom Fields */
|
||||
$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 )
|
||||
{
|
||||
$form->add( $field->buildHelper() );
|
||||
}
|
||||
|
||||
/* Handle submissions */
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
/* Custom fields */
|
||||
$details = array();
|
||||
foreach ( $values as $k => $v )
|
||||
{
|
||||
if ( mb_substr( $k, 0, 13 ) == 'nexus_pfield_' )
|
||||
{
|
||||
$class = \IPS\nexus\Package\CustomField::load( mb_substr( $k, 13 ) )->buildHelper();
|
||||
$details[ mb_substr( $k, 13 ) ] = $class::stringValue( $v );
|
||||
}
|
||||
}
|
||||
$optionValues = $package->optionValues( $details );
|
||||
|
||||
/* Stock check */
|
||||
$quantity = isset( $values['quantity'] ) ? $values['quantity'] : 1;
|
||||
try
|
||||
{
|
||||
$data = $package->optionValuesStockAndPrice( $optionValues, TRUE );
|
||||
}
|
||||
catch ( \UnderflowException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'product_options_price_error', '3X240/2', 500, 'product_options_price_error_admin' );
|
||||
}
|
||||
|
||||
if ( \IPS\Request::i()->isAjax() && isset( \IPS\Request::i()->stockCheck ) )
|
||||
{
|
||||
/* Stock */
|
||||
if ( $data['stock'] == -1 )
|
||||
{
|
||||
$return = array(
|
||||
'stock' => '',
|
||||
'okay' => true
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$return = array(
|
||||
'stock' => \IPS\Member::loggedIn()->language()->addToStack( 'x_in_stock', FALSE, array( 'pluralize' => array( $data['stock'] - $inCart ) ) ),
|
||||
'okay' => true
|
||||
);
|
||||
}
|
||||
|
||||
/* Price */
|
||||
$_data = $package->optionValuesStockAndPrice( $optionValues, FALSE );
|
||||
$normalPrice = $_data['price'];
|
||||
|
||||
/* Renewals */
|
||||
$renewOptions = $package->renew_options ? json_decode( $package->renew_options, TRUE ) : array();
|
||||
if ( !empty( $renewOptions ) )
|
||||
{
|
||||
$term = ( isset( \IPS\Request::i()->renewal_term ) and isset( $renewOptions[ \IPS\Request::i()->renewal_term ] ) ) ? $renewOptions[ \IPS\Request::i()->renewal_term ] : array_shift( $renewOptions );
|
||||
|
||||
if ( $term['add'] )
|
||||
{
|
||||
$data['price']->amount += $term['cost'][ $memberCurrency ]['amount'];
|
||||
$normalPrice->amount += $term['cost'][ $memberCurrency ]['amount'];
|
||||
}
|
||||
|
||||
$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'] ) ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
$return['renewal'] = '';
|
||||
}
|
||||
|
||||
/* Include tax? */
|
||||
if ( \IPS\Settings::i()->nexus_show_tax and $package->tax )
|
||||
{
|
||||
try
|
||||
{
|
||||
$taxRate = \IPS\nexus\Tax::load( $package->tax )->rate( \IPS\nexus\Customer::loggedIn()->estimatedLocation() );
|
||||
|
||||
$data['price']->amount += ( $data['price']->amount * $taxRate );
|
||||
$normalPrice->amount += ( $normalPrice->amount * $taxRate );
|
||||
}
|
||||
catch ( \OutOfRangeException $e ) { }
|
||||
}
|
||||
|
||||
/* Format and return */
|
||||
if ( $data['price']->amount != $normalPrice->amount )
|
||||
{
|
||||
$return['price'] = \IPS\Theme::i()->getTemplate( 'store', 'nexus' )->priceDiscounted( $normalPrice, $data['price'], FALSE );
|
||||
}
|
||||
else
|
||||
{
|
||||
$return['price'] = \IPS\Theme::i()->getTemplate( 'store', 'nexus' )->price( $data['price'], FALSE );
|
||||
}
|
||||
\IPS\Output::i()->json( $return );
|
||||
}
|
||||
elseif ( $data['stock'] != -1 and ( $data['stock'] - $inCart ) < $quantity )
|
||||
{
|
||||
$form->error = \IPS\Member::loggedIn()->language()->addToStack( 'not_enough_in_stock', FALSE, array( 'sprintf' => array( $data['stock'] - $inCart ) ) );
|
||||
return (string) $form;
|
||||
}
|
||||
|
||||
/* Work out renewal term */
|
||||
$renewalTerm = NULL;
|
||||
if ( count( $renewOptions ) )
|
||||
{
|
||||
if ( count( $renewOptions ) === 1 )
|
||||
{
|
||||
$chosenRenewOption = array_pop( $renewOptions );
|
||||
}
|
||||
else
|
||||
{
|
||||
$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 );
|
||||
}
|
||||
|
||||
/* Associations */
|
||||
$parent = NULL;
|
||||
if ( isset( $values['associate_with'] ) and $values['associate_with'] )
|
||||
{
|
||||
$exploded = explode( '.', $values['associate_with'] );
|
||||
if ( $exploded[0] )
|
||||
{
|
||||
$parent = \IPS\nexus\Purchase::load( $exploded[1] );
|
||||
}
|
||||
else
|
||||
{
|
||||
$parent = (int) $exploded[1];
|
||||
}
|
||||
}
|
||||
|
||||
/* Blah */
|
||||
$package->addItemsToCartData( $details, $quantity, $renewalTerm, $parent, $values );
|
||||
|
||||
/* Redirect or AJAX */
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
{
|
||||
/* Upselling? */
|
||||
$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' );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=nexus&module=store&controller=cart&added=' . $package->id, 'front', 'store_cart' ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return (string) $form;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Browse Store
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage Nexus
|
||||
* @since 29 Apr 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\modules\front\store;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Browse Store
|
||||
*/
|
||||
class _store extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* @brief Products per page
|
||||
*/
|
||||
protected static $productsPerPage = 50;
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'store.css', 'nexus' ) );
|
||||
|
||||
if ( \IPS\Theme::i()->settings['responsive'] )
|
||||
{
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'store_responsive.css', 'nexus', 'front' ) );
|
||||
}
|
||||
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Browse Store
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
/* Work out currenty */
|
||||
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 )
|
||||
{
|
||||
$_SESSION['currency'] = \IPS\Request::i()->currency;
|
||||
}
|
||||
$currency = \IPS\Request::i()->currency;
|
||||
}
|
||||
else
|
||||
{
|
||||
$currency = \IPS\nexus\Customer::loggedIn()->defaultCurrency();
|
||||
}
|
||||
|
||||
/* If we have a category, display it */
|
||||
if ( isset( \IPS\Request::i()->cat ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
$category = \IPS\nexus\Package\Group::loadAndCheckPerms( \IPS\Request::i()->cat );
|
||||
|
||||
if ( \IPS\Request::i()->view )
|
||||
{
|
||||
\IPS\Request::i()->setCookie( 'storeView', ( \IPS\Request::i()->view == 'list' ) ? 'list' : 'grid', \IPS\DateTime::ts( time() )->add( new \DateInterval( 'P1Y' ) ) );
|
||||
\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' );
|
||||
|
||||
$joins = array();
|
||||
switch ( \IPS\Request::i()->sortby )
|
||||
{
|
||||
case 'name':
|
||||
$joins['core_sys_lang_words'] = array( "word_app='nexus' AND word_key=CONCAT( 'nexus_package_', p_id ) AND lang_id=?", \IPS\Member::loggedIn()->language()->id );
|
||||
$sortBy = 'word_custom';
|
||||
break;
|
||||
|
||||
case 'price_low':
|
||||
case 'price_high':
|
||||
$joins['nexus_package_base_prices'] = array( 'id=p_id' );
|
||||
$sortBy = \IPS\Request::i()->sortby == 'price_low' ? $currency : ( $currency . ' DESC' );
|
||||
break;
|
||||
|
||||
case 'rating':
|
||||
$sortBy = 'p_rating DESC';
|
||||
break;
|
||||
|
||||
default:
|
||||
$sortBy = 'p_position';
|
||||
break;
|
||||
}
|
||||
|
||||
$currentPage = isset( \IPS\Request::i()->page ) ? intval( \IPS\Request::i()->page ) : 1;
|
||||
|
||||
if( $currentPage < 1 )
|
||||
{
|
||||
$currentPage = 1;
|
||||
}
|
||||
|
||||
$select = \IPS\Db::i()->select( '*', '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 ) . ' )' )
|
||||
), $sortBy, array( ( $currentPage - 1 ) * static::$productsPerPage, static::$productsPerPage ), NULL, NULL, \IPS\Db::SELECT_SQL_CALC_FOUND_ROWS );
|
||||
foreach ( $joins as $table => $clause )
|
||||
{
|
||||
$select->join( $table, $clause );
|
||||
}
|
||||
|
||||
$packages = new \IPS\Patterns\ActiveRecordIterator( $select, 'IPS\nexus\Package' );
|
||||
|
||||
$totalPages = ceil( $packages->count( TRUE ) / static::$productsPerPage );
|
||||
if ( $totalPages and $currentPage > $totalPages )
|
||||
{
|
||||
\IPS\Output::i()->redirect( $category->url()->setQueryString( 'page', $totalPages ), NULL, 303 );
|
||||
}
|
||||
$pagination = \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->pagination( $category->url(), $totalPages, $currentPage, static::$productsPerPage );
|
||||
|
||||
$packagesWithCustomFields = array();
|
||||
foreach ( iterator_to_array( \IPS\Db::i()->select( 'cf_packages', 'nexus_package_fields', 'cf_purchase=1' ) ) as $ids )
|
||||
{
|
||||
$packagesWithCustomFields = array_merge( $packagesWithCustomFields, array_filter( explode( ',', $ids ) ) );
|
||||
}
|
||||
|
||||
\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 );
|
||||
|
||||
foreach ( $category->parents() as $parent )
|
||||
{
|
||||
\IPS\Output::i()->breadcrumb[] = array( $parent->url(), $parent->_title );
|
||||
}
|
||||
\IPS\Output::i()->breadcrumb[] = array( NULL, $category->_title );
|
||||
\IPS\Output::i()->title = $category->_title;
|
||||
return;
|
||||
}
|
||||
catch ( \OutofRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '1X241/1', 404, '' );
|
||||
}
|
||||
}
|
||||
|
||||
/* Otherwise, display the index */
|
||||
else
|
||||
{
|
||||
/* New Products */
|
||||
$newProducts = array();
|
||||
$nexus_store_new = explode( ',', \IPS\Settings::i()->nexus_store_new );
|
||||
if ( $nexus_store_new[0] )
|
||||
{
|
||||
$newProducts = \IPS\nexus\Package\Item::getItemsWithPermission( array( array( 'p_date_added>?', \IPS\DateTime::create()->sub( new \DateInterval( 'P' . $nexus_store_new[1] . 'D' ) )->getTimestamp() ) ), 'p_date_added DESC', $nexus_store_new[0] );
|
||||
}
|
||||
|
||||
/* Popular Products */
|
||||
$popularProducts = array();
|
||||
$nexus_store_popular = explode( ',', \IPS\Settings::i()->nexus_store_popular );
|
||||
if ( $nexus_store_popular[0] )
|
||||
{
|
||||
$where = array();
|
||||
$where[] = array( 'ps_app=? AND ps_type=? AND ps_start>?', 'nexus', 'package', \IPS\DateTime::create()->sub( new \DateInterval( 'P' . $nexus_store_popular[1] . 'D' ) )->getTimestamp() );
|
||||
$where[] = "( p_member_groups='*' OR " . \IPS\Db::i()->findInSet( 'p_member_groups', \IPS\Member::loggedIn()->groups ) . ' )';
|
||||
$where[] = array( 'p_store=?', 1 );
|
||||
|
||||
$popularProducts = new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( 'nexus_packages.*', 'nexus_purchases', $where, 'COUNT(*) DESC', $nexus_store_popular[0], 'ps_item_id' )->join( 'nexus_packages', 'ps_item_id=p_id' ), 'IPS\nexus\Package' );
|
||||
}
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->sidebar['contextual'] = \IPS\Theme::i()->getTemplate('store')->categorySidebar( );
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('store')->index( \IPS\nexus\Customer::loggedIn()->cm_credits[ $currency ], $newProducts, $popularProducts );
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('module__nexus_store');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registration Packages
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
\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()->title = \IPS\Member::loggedIn()->language()->addToStack('sign_up');
|
||||
}
|
||||
|
||||
/**
|
||||
* View Cart
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function cart()
|
||||
{
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('store')->cart();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user