If CategoryId is present in the query string, it means the visitor is browsing a category, so
GetProductsInCategory() is called to retrieve the products in that category. If only DepartmentId is
present, GetProductsOnDepartment() is called to retrieve the department??™s featured products.
CHAPTER 5 ?– CREATING THE PRODUCT CATALOG: PART 2 162
public function init()
{
/* If browsing a category, get the list of products by calling
the GetProductsInCategory() business tier method */
if (isset ($this->_mCategoryId))
$this->mProducts = Catalog::GetProductsInCategory(
$this->_mCategoryId, $this->mPage, $this->mrTotalPages);
/* If browsing a department, get the list of products by calling
the GetProductsOnDepartment() business tier method */
elseif (isset ($this->_mDepartmentId))
$this->mProducts = Catalog::GetProductsOnDepartment(
$this->_mDepartmentId, $this->mPage, $this->mrTotalPages);
The next part of the function takes care of paging. If the business tier call tells you there is more than one page of
products (so there are more products than what you specified in the PRODUCTS_PER_PAGE constant), you need to
show the visitor the current subpage of products being visited, the total number of subpages, and the Previous and
Next page links. The comments in code should make the functionality fairly clear, so we won??™t reiterate the code here.
Pages:
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264