/** * Returns the number of products per page according to where it is set. * Highest priority has the customer's configuration setting if available. * Next comes the shop owners setting for this page; if that's not * configured we use the global setting from SilvercartConfig. * * @return int */ public function getProductsPerPageSetting() { $productsPerPage = 0; $member = SilvercartCustomer::currentUser(); if ($member && $member->getSilvercartCustomerConfig() && $member->getSilvercartCustomerConfig()->productsPerPage !== null) { $productsPerPage = $member->getSilvercartCustomerConfig()->productsPerPage; if ($productsPerPage == 0) { $productsPerPage = SilvercartConfig::getProductsPerPageUnlimitedNumber(); } } else { if ($this->productsPerPage) { $productsPerPage = $this->productsPerPage; } else { $productsPerPage = SilvercartConfig::ProductsPerPage(); } } return $productsPerPage; }
/** * Getter similar to DataObject::get(); returns a SS_List of products filtered by the requirements in self::getRequiredAttributes(); * If an product is free of charge, it can have no price. This is for giveaways and gifts. * * Expected format of $joins: * <pre> * array( * array( * 'table' => 'JoinTableName_1', * 'on' => 'JoinTableOnClause_1', * 'alias' => 'JoinTableAlias_1', * ), * array( * 'table' => 'JoinTableName_2', * 'on' => 'JoinTableOnClause_2', * 'alias' => 'JoinTableAlias_2', * ), * ... * ) * </pre> * * @param string $whereClause to be inserted into the sql where clause * @param string $sort string with sort clause * @param array $joins left join data as multi dimensional array * @param integer $limit DataObject limit * @param array $request Request data * @param integer $pageLength Count of items per page * * @return PaginatedList|ArrayList PaginatedList of products or empty ArrayList * * @author Sebastian Diel <*****@*****.**> * @since 20.10.2014 */ public static function getPaginatedProducts($whereClause = "", $sort = null, $joins = null, $limit = null, $request = null, $pageLength = null) { $paginatedProducts = null; if (is_null($request)) { $request = $_GET; } if (is_null($pageLength)) { $pageLength = SilvercartConfig::ProductsPerPage(); } $products = self::getProducts($whereClause, $sort, $joins, $limit); if ($products instanceof SS_List && $products->exists()) { if ($products instanceof PaginatedList) { $paginatedProducts = $products; } else { $paginatedProducts = new PaginatedList($products, $request); } $paginatedProducts->setPageLength($pageLength); } return $paginatedProducts; }
/** * Return the start value for the limit part of the sql query that * retrieves the product group list for the current product group page. * * @param int|bool $numberOfProductGroups The number of product groups to return * * @return int * * @author Sebastian Diel <*****@*****.**> * @since 04.07.2011 */ public function getSqlOffsetForProductGroups($numberOfProductGroups = false) { if ($this->productGroupsPerPage) { $productGroupsPerPage = $this->productGroupsPerPage; } else { $productGroupsPerPage = SilvercartConfig::ProductsPerPage(); } if ($numberOfProductGroups !== false) { $productGroupsPerPage = (int) $numberOfProductGroups; } if (!isset($_GET['groupStart']) || !is_numeric($_GET['groupStart']) || (int) $_GET['groupStart'] < 1) { if (isset($_GET['groupOffset'])) { // -------------------------------------------------------- // Use offset for getting the current item rage // -------------------------------------------------------- $offset = (int) $_GET['groupOffset']; if ($offset > 0) { $offset -= 1; } // Prevent too high values if ($offset > 999999) { $offset = 0; } $SQL_start = $offset * $productGroupsPerPage; } else { // -------------------------------------------------------- // Use item number for getting the current item range // -------------------------------------------------------- $SQL_start = 0; } } else { $SQL_start = (int) $_GET['groupStart']; } return $SQL_start; }