Version 4.5.0
This commit is contained in:
1 parent
1a0c7fd3c2
commit
f79dcf067a
3791 files changed
+248032
-76372
No files matched your search
@@ -12,7 +12,7 @@
|
||||
namespace IPS\nexus\modules\front\store;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
@@ -43,6 +43,8 @@ class _product extends \IPS\Content\Controller
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'store_responsive.css', 'nexus', 'front' ) );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->pageCaching = FALSE;
|
||||
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
@@ -58,7 +60,7 @@ class _product extends \IPS\Content\Controller
|
||||
{
|
||||
$_SESSION['cart'] = array();
|
||||
}
|
||||
$memberCurrency = ( ( isset( $_SESSION['currency'] ) and in_array( $_SESSION['currency'], \IPS\nexus\Money::currencies() ) ) ? $_SESSION['currency'] : \IPS\nexus\Customer::loggedIn()->defaultCurrency() );
|
||||
$memberCurrency = ( ( isset( \IPS\Request::i()->cookie['currency'] ) and \in_array( \IPS\Request::i()->cookie['currency'], \IPS\nexus\Money::currencies() ) ) ? \IPS\Request::i()->cookie['currency'] : \IPS\nexus\Customer::loggedIn()->defaultCurrency() );
|
||||
|
||||
/* Load Package */
|
||||
$item = parent::manage();
|
||||
@@ -115,14 +117,10 @@ class _product extends \IPS\Content\Controller
|
||||
{
|
||||
/* Where are we shipping to? */
|
||||
$shipAddress = NULL;
|
||||
if ( \IPS\Member::loggedIn()->member_id )
|
||||
if ( \IPS\Member::loggedIn()->member_id and $primaryBillingAddress = \IPS\nexus\Customer::loggedIn()->primaryBillingAddress() )
|
||||
{
|
||||
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 ) { }
|
||||
$shipAddress = $primaryBillingAddress;
|
||||
$locationType = 'address';
|
||||
}
|
||||
if ( !$shipAddress )
|
||||
{
|
||||
@@ -149,7 +147,7 @@ class _product extends \IPS\Content\Controller
|
||||
}
|
||||
|
||||
/* Easypost */
|
||||
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 ) ) ) )
|
||||
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
|
||||
{
|
||||
@@ -179,14 +177,31 @@ class _product extends \IPS\Content\Controller
|
||||
/* Do we have renewal terms? */
|
||||
$renewalTerm = NULL;
|
||||
$renewOptions = $package->renew_options ? json_decode( $package->renew_options, TRUE ) : array();
|
||||
if ( count( $renewOptions ) )
|
||||
$initialTerm = NULL;
|
||||
if ( \count( $renewOptions ) )
|
||||
{
|
||||
$renewalTerm = TRUE;
|
||||
if ( count( $renewOptions ) === 1 )
|
||||
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'] ) ), $package->tax ? \IPS\nexus\Tax::load( $package->tax ) : NULL, $renewalTerm['add'] );
|
||||
}
|
||||
if ( $package->initial_term )
|
||||
{
|
||||
$term = mb_substr( $package->initial_term, 0, -1 );
|
||||
switch( mb_substr( $package->initial_term, -1 ) )
|
||||
{
|
||||
case 'D':
|
||||
$initialTerm = \IPS\Member::loggedIn()->language()->pluralize( \IPS\Member::loggedIn()->language()->get('renew_days'), array( $term ) );
|
||||
break;
|
||||
case 'M':
|
||||
$initialTerm = \IPS\Member::loggedIn()->language()->pluralize( \IPS\Member::loggedIn()->language()->get('renew_months'), array( $term ) );
|
||||
break;
|
||||
case 'Y':
|
||||
$initialTerm = \IPS\Member::loggedIn()->language()->pluralize( \IPS\Member::loggedIn()->language()->get('renew_years'), array( $term ) );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Display */
|
||||
@@ -197,7 +212,7 @@ class _product extends \IPS\Content\Controller
|
||||
}
|
||||
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 );
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('store')->package( $package, $item, $this->_getForm( $package, $inCart, TRUE ), array_sum( $inCart ), $shippingMethods, $itemDataForShipping, $locationType, $renewalTerm, $initialTerm );
|
||||
}
|
||||
|
||||
try
|
||||
@@ -222,7 +237,7 @@ class _product extends \IPS\Content\Controller
|
||||
'@context' => "http://schema.org",
|
||||
'@type' => "Product",
|
||||
'name' => $package->_title,
|
||||
'description' => strip_tags( $item->truncated() ),
|
||||
'description' => $item->truncated( TRUE, NULL ),
|
||||
'category' => $item->container()->_title,
|
||||
'url' => (string) $package->url(),
|
||||
'sku' => $package->id,
|
||||
@@ -268,12 +283,24 @@ class _product extends \IPS\Content\Controller
|
||||
*
|
||||
* @param \IPS\nexus\Package $package The package
|
||||
* @param array $inCart The number in the cart already for each of the field combinations
|
||||
* @param bool $verticalForm Whether to output a vertical form (true) or not
|
||||
* @return string
|
||||
*/
|
||||
protected function _getForm( \IPS\nexus\Package $package, $inCart, $verticalForm = FALSE )
|
||||
{
|
||||
/* Is this a subscription package that we've already bought? */
|
||||
if ( $package->subscription )
|
||||
{
|
||||
try
|
||||
{
|
||||
$purchase = \IPS\nexus\Purchase::constructFromData( \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', $package->id, \IPS\Member::loggedIn()->member_id ) )->first() );
|
||||
return \IPS\Theme::i()->getTemplate( 'store', 'nexus' )->subscriptionPurchase( $purchase );
|
||||
}
|
||||
catch ( \UnderflowException $e ) {}
|
||||
}
|
||||
|
||||
/* Get member's currency */
|
||||
$memberCurrency = ( ( isset( $_SESSION['currency'] ) and in_array( $_SESSION['currency'], \IPS\nexus\Money::currencies() ) ) ? $_SESSION['currency'] : \IPS\nexus\Customer::loggedIn()->defaultCurrency() );
|
||||
$memberCurrency = ( ( isset( \IPS\Request::i()->cookie['currency'] ) and \in_array( \IPS\Request::i()->cookie['currency'], \IPS\nexus\Money::currencies() ) ) ? \IPS\Request::i()->cookie['currency'] : \IPS\nexus\Customer::loggedIn()->defaultCurrency() );
|
||||
|
||||
/* Init form */
|
||||
$form = new \IPS\Helpers\Form( "package_{$package->id}", 'add_to_cart' );
|
||||
@@ -308,18 +335,18 @@ class _product extends \IPS\Content\Controller
|
||||
}
|
||||
|
||||
/* Associate */
|
||||
if ( count( $package->associablePackages() ) )
|
||||
if ( \count( $package->associablePackages() ) )
|
||||
{
|
||||
$associableIds = array_keys( $package->associablePackages() );
|
||||
$associableOptions = array();
|
||||
foreach ( $_SESSION['cart'] as $k => $item )
|
||||
{
|
||||
if ( in_array( $item->id, $associableIds ) )
|
||||
if ( \in_array( $item->id, $associableIds ) )
|
||||
{
|
||||
for ( $i = 0; $i < $item->quantity; $i++ )
|
||||
{
|
||||
$name = $item->name;
|
||||
if ( count( $item->details ) )
|
||||
if ( \count( $item->details ) )
|
||||
{
|
||||
$customFields = \IPS\nexus\Package\CustomField::roots();
|
||||
$stickyFields = array();
|
||||
@@ -330,7 +357,7 @@ class _product extends \IPS\Content\Controller
|
||||
$stickyFields[] = $v;
|
||||
}
|
||||
}
|
||||
if ( count( $stickyFields ) )
|
||||
if ( \count( $stickyFields ) )
|
||||
{
|
||||
$name .= ' (' . implode( ' · ', $stickyFields ) . ')';
|
||||
}
|
||||
@@ -360,7 +387,7 @@ class _product extends \IPS\Content\Controller
|
||||
|
||||
/* Renewal options */
|
||||
$renewOptions = $package->renew_options ? json_decode( $package->renew_options, TRUE ) : array();
|
||||
if ( count( $renewOptions ) > 1 )
|
||||
if ( \count( $renewOptions ) > 1 )
|
||||
{
|
||||
$sortedRenewOptions = array();
|
||||
foreach ( $renewOptions as $k => $option )
|
||||
@@ -444,7 +471,14 @@ class _product extends \IPS\Content\Controller
|
||||
if ( isset( $values[ 'nexus_pfield_' . $field->id ] ) )
|
||||
{
|
||||
$class = $field->buildHelper();
|
||||
$details[ $field->id ] = $class::stringValue( $values[ 'nexus_pfield_' . $field->id ] );
|
||||
if ( $class instanceof \IPS\Helpers\Form\Upload )
|
||||
{
|
||||
$details[ $field->id ] = (string) $values[ 'nexus_pfield_' . $field->id ];
|
||||
}
|
||||
else
|
||||
{
|
||||
$details[ $field->id ] = $class::stringValue( $values[ 'nexus_pfield_' . $field->id ] );
|
||||
}
|
||||
|
||||
if ( !isset( \IPS\Request::i()->stockCheck ) and $field->type === 'Editor' )
|
||||
{
|
||||
@@ -505,16 +539,14 @@ class _product extends \IPS\Content\Controller
|
||||
$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(
|
||||
( 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']
|
||||
) )->toDisplay()
|
||||
) ) );
|
||||
$return['renewal'] = ( 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']
|
||||
) )->toDisplay();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -537,11 +569,11 @@ class _product extends \IPS\Content\Controller
|
||||
/* Format and return */
|
||||
if ( $data['price']->amount->compare( $normalPrice->amount ) !== 0 )
|
||||
{
|
||||
$return['price'] = \IPS\Theme::i()->getTemplate( 'store', 'nexus' )->priceDiscounted( $normalPrice, $data['price'], FALSE );
|
||||
$return['price'] = \IPS\Theme::i()->getTemplate( 'store', 'nexus' )->priceDiscounted( $normalPrice, $data['price'], FALSE, FALSE, NULL );
|
||||
}
|
||||
else
|
||||
{
|
||||
$return['price'] = \IPS\Theme::i()->getTemplate( 'store', 'nexus' )->price( $data['price'], FALSE, FALSE );
|
||||
$return['price'] = \IPS\Theme::i()->getTemplate( 'store', 'nexus' )->price( $data['price'], FALSE, FALSE, NULL );
|
||||
}
|
||||
\IPS\Output::i()->json( $return );
|
||||
}
|
||||
@@ -565,9 +597,9 @@ class _product extends \IPS\Content\Controller
|
||||
|
||||
/* Work out renewal term */
|
||||
$renewalTerm = NULL;
|
||||
if ( count( $renewOptions ) )
|
||||
if ( \count( $renewOptions ) )
|
||||
{
|
||||
if ( count( $renewOptions ) === 1 )
|
||||
if ( \count( $renewOptions ) === 1 )
|
||||
{
|
||||
$chosenRenewOption = array_pop( $renewOptions );
|
||||
}
|
||||
@@ -605,7 +637,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()->json( array( 'dialog' => \IPS\Theme::i()->getTemplate('store')->cartReview( $package, $quantity, $upsell ), 'cart' => \IPS\Theme::i()->getTemplate('store')->cartHeader() ) );
|
||||
\IPS\Output::i()->json( array( 'dialog' => \IPS\Theme::i()->getTemplate('store')->cartReview( $package, $quantity, $upsell ), 'cart' => \IPS\Theme::i()->getTemplate('store')->cartHeader(), 'css' => \IPS\Output::i()->cssFiles ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user