<?php
require_once 'config.php';
/*********************************************************
* PRODUCT FUNCTIONS
**********************************************************/
/*
Get detail information of a product
*/
function getProductList($catId)
{
global $offset;
global $range;
$children = array_merge(array($catId), getChildCategories(NULL, $catId));
$children = ' (' . implode(', ', $children) . ')';
$sql = "SELECT pd_id, pd_name, pd_price,pd_wholesale_price, pd_thumbnail, pd_qty, c.cat_id, pd_phase_out
FROM tbl_product pd, tbl_category c
WHERE pd_for_sale='true' AND pd.cat_id = c.cat_id AND pd.cat_id IN $children
ORDER BY pd_name LIMIT $offset,$range";
$result =& dbQuery($sql);
$products = array();
while ($row =&dbFetchAssoc2($result)) {
extract($row);
if ($pd_thumbnail) {
$pd_thumbnail = WEB_ROOT . 'images/product/' . $pd_thumbnail;
} else {
$pd_thumbnail = WEB_ROOT . 'images/no-image-small.png';
}
$products[] = array('url' => $_SERVER['PHP_SELF'] . "?c=$catId&p=$pd_id",
'image' => $pd_thumbnail,
'name' => $pd_name,
'price' => $pd_price,
'wprice' => $pd_wholesale_price,
'qty' => $pd_qty,
'phase_out' => $pd_phase_out);
} // end while
return $products;
}
function getProductDetail($pdId, $catId)
{
$_SESSION['shoppingReturnUrl'] = $_SERVER['REQUEST_URI'];
// get the product information from database
$sql = "SELECT pd_name, pd_description, pd_price, pd_image, pd_qty
FROM tbl_product
WHERE pd_id = $pdId";
$result = dbQuery($sql);
$row = dbFetchAssoc($result);
extract($row);
$row['pd_description'] = nl2br($row['pd_description']);
if ($row['pd_image']) {
$row['pd_image'] = WEB_ROOT . 'images/product/' . $row['pd_image'];
} else {
$row['pd_image'] = WEB_ROOT . 'images/no-image-large.png';
}
$row['cart_url'] = "cart.php?action=add&p=$pdId";
return $row;
}
?>