Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -12,59 +12,87 @@
|
||||
namespace IPS\nexus\modules\front\store;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use DateInterval;
|
||||
use IPS\Content\Filter;
|
||||
use IPS\DateTime;
|
||||
use IPS\Db;
|
||||
use IPS\Dispatcher\Controller;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\Number;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Login;
|
||||
use IPS\Member;
|
||||
use IPS\nexus\Customer;
|
||||
use IPS\nexus\Money;
|
||||
use IPS\nexus\Package;
|
||||
use IPS\nexus\Package\Group;
|
||||
use IPS\nexus\Package\Item;
|
||||
use IPS\Output;
|
||||
use IPS\Patterns\ActiveRecordIterator;
|
||||
use IPS\Request;
|
||||
use IPS\Session;
|
||||
use IPS\Settings;
|
||||
use IPS\Theme;
|
||||
use OutOfBoundsException;
|
||||
use OutofRangeException;
|
||||
use function count;
|
||||
use function defined;
|
||||
use function floatval;
|
||||
use function in_array;
|
||||
use function intval;
|
||||
use function is_array;
|
||||
use function is_numeric;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Browse Store
|
||||
*/
|
||||
class _store extends \IPS\Dispatcher\Controller
|
||||
class store extends Controller
|
||||
{
|
||||
/**
|
||||
* @brief Products per page
|
||||
*/
|
||||
protected static $productsPerPage = 50;
|
||||
protected static int $productsPerPage = 50;
|
||||
|
||||
/**
|
||||
* @brief Currency
|
||||
*/
|
||||
protected $currency;
|
||||
protected mixed $currency = NULL;
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
public function execute() : void
|
||||
{
|
||||
/* Set CSS */
|
||||
\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' ) );
|
||||
}
|
||||
Output::i()->cssFiles = array_merge( Output::i()->cssFiles, Theme::i()->css( 'store.css', 'nexus' ) );
|
||||
|
||||
/* Work out currency */
|
||||
if ( isset( \IPS\Request::i()->currency ) and \in_array( \IPS\Request::i()->currency, \IPS\nexus\Money::currencies() ) )
|
||||
if ( isset( Request::i()->currency ) and in_array( Request::i()->currency, Money::currencies() ) )
|
||||
{
|
||||
if ( isset( \IPS\Request::i()->csrfKey ) and \IPS\Login::compareHashes( (string) \IPS\Session::i()->csrfKey, (string) \IPS\Request::i()->csrfKey ) )
|
||||
if ( isset( Request::i()->csrfKey ) and Login::compareHashes( (string) Session::i()->csrfKey, (string) Request::i()->csrfKey ) )
|
||||
{
|
||||
$_SESSION['cart'] = array();
|
||||
\IPS\Request::i()->setCookie( 'currency', \IPS\Request::i()->currency );
|
||||
Request::i()->setCookie( 'currency', Request::i()->currency );
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=nexus&module=store&controller=store', 'front', 'store' ) );
|
||||
Output::i()->redirect( Url::internal( 'app=nexus&module=store&controller=store', 'front', 'store' ) );
|
||||
}
|
||||
$this->currency = \IPS\Request::i()->currency;
|
||||
$this->currency = Request::i()->currency;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->currency = \IPS\nexus\Customer::loggedIn()->defaultCurrency();
|
||||
$this->currency = Customer::loggedIn()->defaultCurrency();
|
||||
}
|
||||
|
||||
\IPS\Output::setCacheTime( false );
|
||||
|
||||
Output::i()->pageCaching = FALSE;
|
||||
|
||||
/* Pass up */
|
||||
parent::execute();
|
||||
@@ -75,12 +103,12 @@ class _store extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
protected function manage() : void
|
||||
{
|
||||
/* If we have a category, display it */
|
||||
if ( isset( \IPS\Request::i()->cat ) )
|
||||
if ( isset( Request::i()->cat ) )
|
||||
{
|
||||
return $this->_categoryView();
|
||||
$this->_categoryView();
|
||||
}
|
||||
|
||||
/* Otherwise, display the index */
|
||||
@@ -95,21 +123,21 @@ class _store extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _categoryView()
|
||||
protected function _categoryView() : void
|
||||
{
|
||||
/* Load category */
|
||||
try
|
||||
{
|
||||
$category = \IPS\nexus\Package\Group::loadAndCheckPerms( \IPS\Request::i()->cat );
|
||||
$category = Group::loadAndCheckPerms( Request::i()->cat );
|
||||
}
|
||||
catch ( \OutofRangeException $e )
|
||||
catch ( OutofRangeException )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '1X241/1', 404, '' );
|
||||
Output::i()->error( 'node_error', '1X241/1', 404, '' );
|
||||
}
|
||||
$url = $category->url();
|
||||
|
||||
/* Set initial stuff for fetching packages */
|
||||
$currentPage = isset( \IPS\Request::i()->page ) ? \intval( \IPS\Request::i()->page ) : 1;
|
||||
$currentPage = isset( Request::i()->page ) ? intval( Request::i()->page ) : 1;
|
||||
if( $currentPage < 1 )
|
||||
{
|
||||
$currentPage = 1;
|
||||
@@ -117,55 +145,55 @@ class _store extends \IPS\Dispatcher\Controller
|
||||
$where = 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 ) . ' )' )
|
||||
array( "( p_member_groups='*' OR " . Db::i()->findInSet( 'p_member_groups', Member::loggedIn()->groups ) . ' )' )
|
||||
);
|
||||
$havePackagesWhichAcceptReviews = (bool) \IPS\Db::i()->select( 'COUNT(*)', 'nexus_packages', array_merge( $where, array( array( 'p_reviewable=1' ) ) ) )->first();
|
||||
$havePackagesWhichUseStockLevels = (bool) \IPS\Db::i()->select( 'COUNT(*)', 'nexus_packages', array_merge( $where, array( array( 'p_stock<>-1' ) ) ) )->first();
|
||||
$havePackagesWhichAcceptReviews = (bool) Db::i()->select( 'COUNT(*)', 'nexus_packages', array_merge( $where, array( array( 'p_reviewable=1' ) ) ) )->first();
|
||||
$havePackagesWhichUseStockLevels = (bool) Db::i()->select( 'COUNT(*)', 'nexus_packages', array_merge( $where, array( array( 'p_stock<>-1' ) ) ) )->first();
|
||||
$joins = array();
|
||||
|
||||
/* Apply Filters */
|
||||
if ( isset( \IPS\Request::i()->filter ) and \is_array( \IPS\Request::i()->filter ) )
|
||||
if ( isset( Request::i()->filter ) and is_array( Request::i()->filter ) )
|
||||
{
|
||||
$url = $url->setQueryString( 'filter', \IPS\Request::i()->filter );
|
||||
foreach ( \IPS\Request::i()->filter as $filterId => $allowedValues )
|
||||
$url = $url->setQueryString( 'filter', Request::i()->filter );
|
||||
foreach ( Request::i()->filter as $filterId => $allowedValues )
|
||||
{
|
||||
$filterId = (int) $filterId;
|
||||
$where[] = array( \IPS\Db::i()->findInSet( "filter{$filterId}.pfm_values", array_map( 'intval', explode( ',', $allowedValues ) ) ) );
|
||||
$where[] = array( Db::i()->findInSet( "filter{$filterId}.pfm_values", array_map( 'intval', explode( ',', $allowedValues ) ) ) );
|
||||
$joins[] = array( 'table' => array( 'nexus_package_filters_map', "filter{$filterId}" ), 'on' => array( "filter{$filterId}.pfm_package=p_id AND filter{$filterId}.pfm_filter=?", $filterId ) );
|
||||
}
|
||||
}
|
||||
foreach ( array( 'minPrice' => '>', 'maxPrice' => '<' ) as $k => $op )
|
||||
{
|
||||
if ( isset( \IPS\Request::i()->$k ) and \is_numeric( \IPS\Request::i()->$k ) and \floatval( \IPS\Request::i()->$k ) > 0 )
|
||||
if ( isset( Request::i()->$k ) and is_numeric( Request::i()->$k ) and floatval( Request::i()->$k ) > 0 )
|
||||
{
|
||||
$url = $url->setQueryString( $k, \IPS\Request::i()->$k );
|
||||
$url = $url->setQueryString( $k, Request::i()->$k );
|
||||
$joins['nexus_package_base_prices'] = array( 'table' => 'nexus_package_base_prices', 'on' => array( 'id=p_id' ) );
|
||||
$where[] = array( $this->currency . $op . '=?', \floatval( \IPS\Request::i()->$k ) );
|
||||
$where[] = array( $this->currency . $op . '=?', floatval( Request::i()->$k ) );
|
||||
}
|
||||
}
|
||||
if ( isset( \IPS\Request::i()->minRating ) and \is_numeric( \IPS\Request::i()->minRating ) and \floatval( \IPS\Request::i()->minRating ) > 0 )
|
||||
if ( isset( Request::i()->minRating ) and is_numeric( Request::i()->minRating ) and floatval( Request::i()->minRating ) > 0 )
|
||||
{
|
||||
$url = $url->setQueryString( 'minRating', \IPS\Request::i()->minRating );
|
||||
$where[] = array( 'p_rating>=?', \intval( \IPS\Request::i()->minRating ) );
|
||||
$url = $url->setQueryString( 'minRating', Request::i()->minRating );
|
||||
$where[] = array( 'p_rating>=?', intval( Request::i()->minRating ) );
|
||||
}
|
||||
if ( isset( \IPS\Request::i()->inStock ) )
|
||||
if ( isset( Request::i()->inStock ) )
|
||||
{
|
||||
$url = $url->setQueryString( 'inStock', \IPS\Request::i()->inStock );
|
||||
$where[] = array( '( p_stock>0 OR ( p_stock=-2 AND (?)>0 ) )', \IPS\Db::i()->select( 'MAX(opt_stock)', 'nexus_product_options', 'opt_package=p_id' ) );
|
||||
$url = $url->setQueryString( 'inStock', Request::i()->inStock );
|
||||
$where[] = array( '( p_stock>0 OR ( p_stock=-2 AND (?)>0 ) )', Db::i()->select( 'MAX(opt_stock)', 'nexus_product_options', 'opt_package=p_id' ) );
|
||||
}
|
||||
|
||||
/* Figure out the sorting */
|
||||
switch ( \IPS\Request::i()->sortby )
|
||||
switch ( Request::i()->sortby )
|
||||
{
|
||||
case 'name':
|
||||
$joins['core_sys_lang_words'] = array( 'table' => 'core_sys_lang_words', 'on' => array( "word_app='nexus' AND word_key=CONCAT( 'nexus_package_', p_id ) AND lang_id=?", \IPS\Member::loggedIn()->language()->id ) );
|
||||
$joins['core_sys_lang_words'] = array( 'table' => 'core_sys_lang_words', 'on' => array( "word_app='nexus' AND word_key=CONCAT( 'nexus_package_', p_id ) AND lang_id=?", Member::loggedIn()->language()->id ) );
|
||||
$sortBy = 'word_custom';
|
||||
break;
|
||||
|
||||
case 'price_low':
|
||||
case 'price_high':
|
||||
$joins['nexus_package_base_prices'] = array( 'table' => 'nexus_package_base_prices', 'on' => array( 'id=p_id' ) );
|
||||
$sortBy = \IPS\Request::i()->sortby == 'price_low' ? $this->currency : ( $this->currency . ' DESC' );
|
||||
$sortBy = Request::i()->sortby == 'price_low' ? $this->currency : ( $this->currency . ' DESC' );
|
||||
break;
|
||||
|
||||
case 'rating':
|
||||
@@ -178,15 +206,15 @@ class _store extends \IPS\Dispatcher\Controller
|
||||
}
|
||||
|
||||
/* Fetch the packages */
|
||||
$select = \IPS\Db::i()->select( '*', 'nexus_packages', $where, $sortBy, array( ( $currentPage - 1 ) * static::$productsPerPage, static::$productsPerPage ) );
|
||||
$select = Db::i()->select( '*', 'nexus_packages', $where, $sortBy, array( ( $currentPage - 1 ) * static::$productsPerPage, static::$productsPerPage ) );
|
||||
foreach ( $joins as $join )
|
||||
{
|
||||
$select->join( $join['table'], $join['on'] );
|
||||
}
|
||||
$packages = new \IPS\Patterns\ActiveRecordIterator( $select, 'IPS\nexus\Package' );
|
||||
$packages = new ActiveRecordIterator( $select, 'IPS\nexus\Package' );
|
||||
|
||||
/* Get packages count */
|
||||
$select = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_packages', $where );
|
||||
$select = Db::i()->select( 'COUNT(*)', 'nexus_packages', $where );
|
||||
foreach ( $joins as $join )
|
||||
{
|
||||
$select->join( $join['table'], $join['on'] );
|
||||
@@ -197,50 +225,41 @@ class _store extends \IPS\Dispatcher\Controller
|
||||
$totalPages = ceil( $totalCount / static::$productsPerPage );
|
||||
if ( $totalPages and $currentPage > $totalPages )
|
||||
{
|
||||
\IPS\Output::i()->redirect( $category->url()->setPage( 'page', $totalPages ), NULL, 303 );
|
||||
Output::i()->redirect( $category->url()->setPage( 'page', $totalPages ), NULL, 303 );
|
||||
}
|
||||
$pagination = \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->pagination( $category->url(), $totalPages, $currentPage, static::$productsPerPage );
|
||||
$pagination = Theme::i()->getTemplate( 'global', 'core', 'global' )->pagination( $category->url(), $totalPages, $currentPage, static::$productsPerPage );
|
||||
|
||||
/* Other stuff we need for the view */
|
||||
$subcategories = new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_package_groups', array( 'pg_parent=?', $category->id ), 'pg_position ASC' ), 'IPS\nexus\Package\Group' );
|
||||
$subcategories = new ActiveRecordIterator( Db::i()->select( '*', 'nexus_package_groups', array( 'pg_parent=?', $category->id ), 'pg_position ASC' ), 'IPS\nexus\Package\Group' );
|
||||
$packagesWithCustomFields = array();
|
||||
foreach ( iterator_to_array( \IPS\Db::i()->select( 'cf_packages', 'nexus_package_fields', 'cf_purchase=1' ) ) as $ids )
|
||||
foreach ( iterator_to_array( Db::i()->select( 'cf_packages', 'nexus_package_fields', 'cf_purchase=1' ) ) as $ids )
|
||||
{
|
||||
$packagesWithCustomFields = array_merge( $packagesWithCustomFields, array_filter( explode( ',', $ids ) ) );
|
||||
}
|
||||
|
||||
/* List or grid? */
|
||||
if ( \IPS\Request::i()->view )
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
\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';
|
||||
}
|
||||
|
||||
/* Output */
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
if ( Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->json( array(
|
||||
'contents' => \IPS\Theme::i()->getTemplate('store')->categoryContents( $category, $subcategories, $packages, $pagination, $packagesWithCustomFields, $totalCount ),
|
||||
'sidebar' => \IPS\Theme::i()->getTemplate('store')->categorySidebar( $category, $subcategories, $url, \count( $packages ), $this->currency, $havePackagesWhichAcceptReviews, $havePackagesWhichUseStockLevels )
|
||||
Output::i()->json( array(
|
||||
'contents' => Theme::i()->getTemplate('store')->categoryContents( $category, $subcategories, $packages, $pagination, $packagesWithCustomFields, $totalCount ),
|
||||
'sidebar' => Theme::i()->getTemplate('store')->categorySidebar( $category, $subcategories, $url, count( $packages ), $this->currency, $havePackagesWhichAcceptReviews, $havePackagesWhichUseStockLevels )
|
||||
)) ;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach ( $category->parents() as $parent )
|
||||
{
|
||||
\IPS\Output::i()->breadcrumb[] = array( $parent->url(), $parent->_title );
|
||||
Output::i()->breadcrumb[] = array( $parent->url(), $parent->_title );
|
||||
}
|
||||
\IPS\Output::i()->breadcrumb[] = array( $category->url(), $category->_title );
|
||||
\IPS\Output::i()->title = $category->_title;
|
||||
\IPS\Output::i()->sidebar['contextual'] = \IPS\Theme::i()->getTemplate('store')->categorySidebar( $category, $subcategories, $url, \count( $packages ), $this->currency, $havePackagesWhichAcceptReviews, $havePackagesWhichUseStockLevels );
|
||||
Output::i()->breadcrumb[] = array( $category->url(), $category->_title );
|
||||
Output::i()->title = $category->_title;
|
||||
Output::i()->sidebar['contextual'] = Theme::i()->getTemplate('store')->categorySidebar( $category, $subcategories, $url, count( $packages ), $this->currency, $havePackagesWhichAcceptReviews, $havePackagesWhichUseStockLevels );
|
||||
|
||||
/* Set default search */
|
||||
\IPS\Output::i()->defaultSearchOption = array( 'nexus_package_item', "nexus_package_item_el" );
|
||||
Output::i()->defaultSearchOption = array( 'nexus_package_item', "nexus_package_item_el" );
|
||||
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('store')->category( $category, $subcategories, $packages, $pagination, $packagesWithCustomFields, $totalCount );
|
||||
\IPS\Output::i()->globalControllers[] = 'nexus.front.store.category';
|
||||
Output::i()->output = Theme::i()->getTemplate('store')->category( $category, $subcategories, $packages, $pagination, $packagesWithCustomFields, $totalCount );
|
||||
Output::i()->globalControllers[] = 'nexus.front.store.category';
|
||||
}
|
||||
|
||||
/* JSON-LD
|
||||
@@ -248,13 +267,14 @@ class _store extends \IPS\Dispatcher\Controller
|
||||
@link https://developers.google.com/search/docs/guides/intro-structured-data#multiple-entities-on-the-same-page */
|
||||
foreach( $packages as $package )
|
||||
{
|
||||
$item = \IPS\nexus\Package\Item::load( $package->id );
|
||||
/* @var Package $package */
|
||||
$item = Item::load( $package->id );
|
||||
|
||||
try
|
||||
{
|
||||
$price = $package->price();
|
||||
}
|
||||
catch( \OutOfBoundsException $e )
|
||||
catch( OutOfBoundsException )
|
||||
{
|
||||
$price = NULL;
|
||||
}
|
||||
@@ -262,8 +282,8 @@ class _store extends \IPS\Dispatcher\Controller
|
||||
/* A product MUST have an offer, so if there's no price (i.e. due to currency configuration) don't even output */
|
||||
if( $price !== NULL )
|
||||
{
|
||||
\IPS\Output::i()->jsonLd['package' . $package->id ] = array(
|
||||
'@context' => "http://schema.org",
|
||||
Output::i()->jsonLd['package' . $package->id ] = array(
|
||||
'@context' => "https://schema.org",
|
||||
'@type' => "Product",
|
||||
'name' => $package->_title,
|
||||
'description' => $item->truncated( TRUE, NULL ),
|
||||
@@ -276,32 +296,29 @@ class _store extends \IPS\Dispatcher\Controller
|
||||
'priceCurrency' => $price->currency,
|
||||
'seller' => array(
|
||||
'@type' => 'Organization',
|
||||
'name' => \IPS\Settings::i()->board_name
|
||||
'name' => Settings::i()->board_name
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
/* Stock levels */
|
||||
if( $package->physical )
|
||||
if( $package->stockLevel() === 0 )
|
||||
{
|
||||
if( $package->stockLevel() === 0 )
|
||||
{
|
||||
\IPS\Output::i()->jsonLd['package' . $package->id ]['offers']['availability'] = 'http://schema.org/OutOfStock';
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->jsonLd['package' . $package->id ]['offers']['availability'] = 'http://schema.org/InStock';
|
||||
}
|
||||
Output::i()->jsonLd['package' . $package->id ]['offers']['availability'] = 'https://schema.org/OutOfStock';
|
||||
}
|
||||
else
|
||||
{
|
||||
Output::i()->jsonLd['package' . $package->id ]['offers']['availability'] = 'https://schema.org/InStock';
|
||||
}
|
||||
|
||||
if( $package->image )
|
||||
{
|
||||
\IPS\Output::i()->jsonLd['package' . $package->id ]['image'] = (string) $package->image;
|
||||
Output::i()->jsonLd['package' . $package->id ]['image'] = (string) $package->image;
|
||||
}
|
||||
|
||||
if( $package->reviewable and $item->averageReviewRating() )
|
||||
{
|
||||
\IPS\Output::i()->jsonLd['package' . $package->id ]['aggregateRating'] = array(
|
||||
Output::i()->jsonLd['package' . $package->id ]['aggregateRating'] = array(
|
||||
'@type' => 'AggregateRating',
|
||||
'ratingValue' => $item->averageReviewRating(),
|
||||
'ratingCount' => $item->reviews
|
||||
@@ -316,21 +333,21 @@ class _store extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function priceFilter()
|
||||
protected function priceFilter() : void
|
||||
{
|
||||
if ( !isset( \IPS\Request::i()->maxPrice ) )
|
||||
if ( !isset( Request::i()->maxPrice ) )
|
||||
{
|
||||
\IPS\Request::i()->maxPrice = 0;
|
||||
Request::i()->maxPrice = 0;
|
||||
}
|
||||
|
||||
$form = new \IPS\Helpers\Form( 'price_filter', 'filter' );
|
||||
$form->class = 'ipsForm_vertical';
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'minPrice', FALSE, 0, array( 'decimals' => \IPS\nexus\Money::numberOfDecimalsForCurrency( $this->currency ) ), NULL, NULL, $this->currency ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'maxPrice', FALSE, 0, array( 'decimals' => \IPS\nexus\Money::numberOfDecimalsForCurrency( $this->currency ), 'unlimited' => 0 ), NULL, NULL, $this->currency ) );
|
||||
$form = new Form( 'price_filter', 'filter' );
|
||||
$form->class = 'ipsForm--vertical ipsForm--price-filter';
|
||||
$form->add( new Number( 'minPrice', FALSE, 0, array( 'decimals' => Money::numberOfDecimalsForCurrency( $this->currency ) ), NULL, NULL, $this->currency ) );
|
||||
$form->add( new Number( 'maxPrice', FALSE, 0, array( 'decimals' => Money::numberOfDecimalsForCurrency( $this->currency ), 'unlimited' => 0 ), NULL, NULL, $this->currency ) );
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
$url = \IPS\Request::i()->url()->setQueryString( 'do', NULL );
|
||||
$url = Request::i()->url()->setQueryString( 'do', NULL );
|
||||
if ( $values['minPrice'] )
|
||||
{
|
||||
$url = $url->setQueryString( 'minPrice', $values['minPrice'] );
|
||||
@@ -347,11 +364,11 @@ class _store extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
$url = $url->setQueryString( 'maxPrice', NULL );
|
||||
}
|
||||
\IPS\Output::i()->redirect( $url );
|
||||
Output::i()->redirect( $url );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('price_filter');
|
||||
\IPS\Output::i()->output = $form->customTemplate( array( \IPS\Theme::i()->getTemplate( 'forms', 'core' ), 'popupTemplate' ) );
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack('price_filter');
|
||||
Output::i()->output = $form->customTemplate( array( Theme::i()->getTemplate( 'forms', 'core' ), 'popupTemplate' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -359,38 +376,38 @@ class _store extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _indexView()
|
||||
protected function _indexView() : void
|
||||
{
|
||||
/* New Products */
|
||||
$newProducts = array();
|
||||
$nexus_store_new = explode( ',', \IPS\Settings::i()->nexus_store_new );
|
||||
$nexus_store_new = explode( ',', 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] );
|
||||
$newProducts = Item::getItemsWithPermission( array( array( 'p_date_added>?', 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 );
|
||||
$nexus_store_popular = explode( ',', 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( 'ps_app=? AND ps_type=? AND ps_start>?', 'nexus', 'package', DateTime::create()->sub( new DateInterval( 'P' . $nexus_store_popular[1] . 'D' ) )->getTimestamp() );
|
||||
$where[] = "( p_member_groups='*' OR " . Db::i()->findInSet( 'p_member_groups', Member::loggedIn()->groups ) . ' )';
|
||||
$where[] = array( 'p_store=?', 1 );
|
||||
|
||||
$popularIds = \IPS\Db::i()->select( 'nexus_purchases.ps_item_id', 'nexus_purchases', $where, 'COUNT(ps_item_id) DESC', $nexus_store_popular[0], 'ps_item_id' )->join( 'nexus_packages', 'ps_item_id=p_id' );
|
||||
if( \count( $popularIds ) )
|
||||
$popularIds = Db::i()->select( 'nexus_purchases.ps_item_id', 'nexus_purchases', $where, 'COUNT(ps_item_id) DESC', $nexus_store_popular[0], 'ps_item_id' )->join( 'nexus_packages', 'ps_item_id=p_id' );
|
||||
if( count( $popularIds ) )
|
||||
{
|
||||
$popularProducts = new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( 'nexus_packages.*', 'nexus_packages', array( \IPS\Db::i()->in( 'p_id', iterator_to_array( $popularIds ) ) ), 'FIELD(p_id, ' . implode( ',', iterator_to_array($popularIds) ) . ')' ), 'IPS\nexus\Package' );
|
||||
$popularProducts = new ActiveRecordIterator( Db::i()->select( 'nexus_packages.*', 'nexus_packages', array( Db::i()->in( 'p_id', iterator_to_array( $popularIds ) ) ), 'FIELD(p_id, ' . implode( ',', iterator_to_array($popularIds) ) . ')' ), 'IPS\nexus\Package' );
|
||||
}
|
||||
}
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->sidebar['contextual'] = \IPS\Theme::i()->getTemplate('store')->categorySidebar( );
|
||||
\IPS\Output::i()->linkTags['canonical'] = (string) \IPS\Http\Url::internal( 'app=nexus&module=store&controller=store', 'front', 'store' );
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('store')->index( \IPS\nexus\Customer::loggedIn()->cm_credits[ $this->currency ], $newProducts, $popularProducts );
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('module__nexus_store');
|
||||
Output::i()->sidebar['contextual'] = Theme::i()->getTemplate('store')->categorySidebar( );
|
||||
Output::i()->linkTags['canonical'] = (string) Url::internal( 'app=nexus&module=store&controller=store', 'front', 'store' );
|
||||
Output::i()->output = Theme::i()->getTemplate('store')->index( Customer::loggedIn()->cm_credits[ $this->currency ], $newProducts, $popularProducts );
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack('module__nexus_store');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -398,12 +415,12 @@ class _store extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
public function register() : void
|
||||
{
|
||||
\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' ) ), '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');
|
||||
Output::i()->bodyClasses[] = 'ipsLayout_minimal';
|
||||
Output::i()->sidebar['enabled'] = FALSE;
|
||||
Output::i()->output = Theme::i()->getTemplate('store')->register( Item::getItemsWithPermission( array( array( 'p_reg=1' ) ), 'pg_position, p_position', 10, 'read', Filter::FILTER_AUTOMATIC, 0, NULL, TRUE ) );
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack('sign_up');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -411,8 +428,8 @@ class _store extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function cart()
|
||||
protected function cart() : void
|
||||
{
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('store')->cart();
|
||||
Output::i()->output = Theme::i()->getTemplate('store')->cart();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user